PhoenixRuntime { public static Expression getTenantIdExpression(Connection conn, String fullTableName) throws SQLException { PTable table = getTable(conn, fullTableName); if (!SchemaUtil.isMetaTable(table) && !SchemaUtil.isSequenceTable(table) && !table.isMultiTenant()) { return null; } if (table.getIndexType() == IndexType.LOCAL) { throw new SQLFeatureNotSupportedException(); } int pkPosition = table.getBucketNum() == null ? 0 : 1; List<PColumn> pkColumns = table.getPKColumns(); return new RowKeyColumnExpression(pkColumns.get(pkPosition), new RowKeyValueAccessor(pkColumns, pkPosition)); } private  PhoenixRuntime(); static void main(String [] args); static int executeStatements(Connection conn, Reader reader, List<Object> binds); @Deprecated static List<KeyValue> getUncommittedData(Connection conn); static Iterator<Pair<byte[],List<KeyValue>>> getUncommittedDataIterator(Connection conn); static Iterator<Pair<byte[],List<KeyValue>>> getUncommittedDataIterator(Connection conn, boolean includeMutableIndexes); static PTable getTable(Connection conn, String name); static List<ColumnInfo> generateColumnInfo(Connection conn,
            String tableName, List<String> columns); static ColumnInfo getColumnInfo(PTable table, String columnName); static ColumnInfo getColumnInfo(PColumn pColumn); @Deprecated static byte[] encodePK(Connection conn, String fullTableName, Object[] values); @Deprecated static Object[] decodePK(Connection conn, String name, byte[] value); static QueryPlan getOptimizedQueryPlan(PreparedStatement stmt); static boolean hasOrderBy(QueryPlan plan); static int getLimit(QueryPlan plan); static void getPkColsForSql(List<Pair<String, String>> columns, QueryPlan plan, Connection conn, boolean forDataTable); static void getPkColsDataTypesForSql(List<Pair<String, String>> columns, List<String> dataTypes, QueryPlan plan, Connection conn, boolean forDataTable); static String getSqlTypeName(PColumn pCol); static String getArraySqlTypeName(@Nullable Integer maxLength, @Nullable Integer scale, PDataType arrayType); static byte[] encodeValues(Connection conn, String fullTableName, Object[] values, List<Pair<String, String>> columns); static Object[] decodeValues(Connection conn, String fullTableName, byte[] value, List<Pair<String, String>> columns); static Expression getTenantIdExpression(Connection conn, String fullTableName); static final String CURRENT_SCN_ATTRIB; final static String JDBC_PROTOCOL; final static char JDBC_PROTOCOL_TERMINATOR; final static char JDBC_PROTOCOL_SEPARATOR; @Deprecated
    final static String EMBEDDED_JDBC_PROTOCOL; final static String UPSERT_BATCH_SIZE_ATTRIB; static final String TENANT_ID_ATTRIB; static final String ANNOTATION_ATTRIB_PREFIX; static final String AUTO_COMMIT_ATTRIB; final static String CONNECTIONLESS; static final String PHOENIX_TEST_DRIVER_URL_PARAM; }
@Test public void testGetTenantIdExpression() throws Exception { Connection conn = DriverManager.getConnection(getUrl()); Expression e1 = PhoenixRuntime.getTenantIdExpression(conn, PhoenixDatabaseMetaData.SYSTEM_STATS_NAME); assertNull(e1); Expression e2 = PhoenixRuntime.getTenantIdExpression(conn, PhoenixDatabaseMetaData.SYSTEM_CATALOG_NAME); assertNotNull(e2); Expression e3 = PhoenixRuntime.getTenantIdExpression(conn, PhoenixDatabaseMetaData.SEQUENCE_FULLNAME); assertNotNull(e3); conn.createStatement().execute("CREATE TABLE FOO (k VARCHAR PRIMARY KEY)"); Expression e4 = PhoenixRuntime.getTenantIdExpression(conn, "FOO"); assertNull(e4); conn.createStatement().execute("CREATE TABLE A.BAR (k1 VARCHAR NOT NULL, k2 VARCHAR, CONSTRAINT PK PRIMARY KEY(K1,K2)) MULTI_TENANT=true"); Expression e5 = PhoenixRuntime.getTenantIdExpression(conn, "A.BAR"); assertNotNull(e5); conn.createStatement().execute("CREATE INDEX I1 ON A.BAR (K2)"); Expression e5A = PhoenixRuntime.getTenantIdExpression(conn, "A.I1"); assertNotNull(e5A); conn.createStatement().execute("CREATE TABLE BAS (k1 VARCHAR NOT NULL, k2 VARCHAR, CONSTRAINT PK PRIMARY KEY(K1,K2)) MULTI_TENANT=true, SALT_BUCKETS=3"); Expression e6 = PhoenixRuntime.getTenantIdExpression(conn, "BAS"); assertNotNull(e6); conn.createStatement().execute("CREATE INDEX I2 ON BAS (K2)"); Expression e6A = PhoenixRuntime.getTenantIdExpression(conn, "I2"); assertNotNull(e6A); try { PhoenixRuntime.getTenantIdExpression(conn, "NOT.ATABLE"); fail(); } catch (TableNotFoundException e) { } Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); props.setProperty(PhoenixRuntime.TENANT_ID_ATTRIB, "t1"); Connection tsconn = DriverManager.getConnection(getUrl(), props); tsconn.createStatement().execute("CREATE VIEW V(V1 VARCHAR) AS SELECT * FROM BAS"); Expression e7 = PhoenixRuntime.getTenantIdExpression(tsconn, "V"); assertNotNull(e7); tsconn.createStatement().execute("CREATE LOCAL INDEX I3 ON V (V1)"); try { PhoenixRuntime.getTenantIdExpression(tsconn, "I3"); fail(); } catch (SQLFeatureNotSupportedException e) { } }