private void getFunctionFromCache(List<String> functionNames, List<PFunction> functionsFound, boolean getOnlyTemporyFunctions) { Iterator<String> iterator = functionNames.iterator(); while(iterator.hasNext()) { PFunction function = null; String functionName = iterator.next(); try { function = connection.getMetaDataCache().getFunction(new PTableKey(connection.getTenantId(), functionName)); } catch (FunctionNotFoundException e1) { if (connection.getTenantId() != null) { // Check with null tenantId next try { function = connection.getMetaDataCache().getFunction(new PTableKey(null, functionName)); } catch (FunctionNotFoundException e2) { } } } if (function != null) { if (getOnlyTemporyFunctions) { if (function.isTemporaryFunction()) { functionsFound.add(function); iterator.remove(); } } else { functionsFound.add(function); iterator.remove(); } } } }
public PhoenixConnection(PhoenixConnection connection, MutationState mutationState) throws SQLException { this(connection.getQueryServices(), connection.getURL(), connection .getClientInfo(), connection.getMetaDataCache(), mutationState, connection.isDescVarLengthRowKeyUpgrade(), connection .isRunningUpgrade(), connection.buildingIndex); }
String functionName = iterator.next(); function = connection.getMetaDataCache().getFunction( new PTableKey(tenantId, functionName)); if (function != null && !alwaysHitServer
public MetaDataMutationResult updateCache(String schemaName, boolean alwaysHitServer) throws SQLException { long clientTimeStamp = getClientTimeStamp(); PSchema schema = null; try { schema = connection.getMetaDataCache().getSchema(new PTableKey(null, schemaName)); if (schema != null && !alwaysHitServer) { return new MetaDataMutationResult(MutationCode.SCHEMA_ALREADY_EXISTS, schema, QueryConstants.UNSET_TIMESTAMP); } } catch (SchemaNotFoundException e) { } MetaDataMutationResult result; result = connection.getQueryServices().getSchema(schemaName, clientTimeStamp); return result; }
private static boolean mutateRandomly(Connection conn, String fullTableName, int nRows, boolean checkForInactive, String fullIndexName) throws SQLException, InterruptedException { PTableKey key = new PTableKey(null,fullTableName); PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache(); boolean hasInactiveIndex = false; int batchSize = 200;
@Test public void testNullAlterTableDefaultRemoved() throws Exception { String ddl = "CREATE TABLE table_with_default (" + "pk INTEGER PRIMARY KEY)"; String ddl2 = "ALTER TABLE table_with_default " + "ADD v CHAR(3) DEFAULT null"; Connection conn = DriverManager.getConnection(getUrl()); conn.createStatement().execute(ddl); conn.createStatement().execute(ddl2); PTable table = conn.unwrap(PhoenixConnection.class).getMetaDataCache() .getTableRef(new PTableKey(null,"TABLE_WITH_DEFAULT")).getTable(); assertNull(table.getColumnForColumnName("V").getExpressionStr()); }
@Test public void testNullDefaultRemoved() throws Exception { String ddl = "CREATE TABLE table_with_default (" + "pk INTEGER PRIMARY KEY, " + "v VARCHAR DEFAULT null)"; Connection conn = DriverManager.getConnection(getUrl()); conn.createStatement().execute(ddl); PTable table = conn.unwrap(PhoenixConnection.class).getMetaDataCache() .getTableRef(new PTableKey(null,"TABLE_WITH_DEFAULT")).getTable(); assertNull(table.getColumnForColumnName("V").getExpressionStr()); }
public KeyRangeClipTest(String tableDef, List<Object> startValues, List<Object> endValues, int clipTo, KeyRange expectedOutput) throws SQLException { PhoenixConnection pconn = DriverManager.getConnection(getUrl()).unwrap(PhoenixConnection.class); pconn.createStatement().execute("CREATE TABLE T(" + tableDef+ ")"); PTable table = pconn.getMetaDataCache().getTableRef(new PTableKey(null,"T")).getTable(); this.schema = table.getRowKeySchema(); byte[] lowerRange = getRange(pconn, startValues); byte[] upperRange = getRange(pconn, endValues); this.input = KeyRange.getKeyRange(lowerRange, upperRange); this.expectedOutput = expectedOutput; this.clipTo = clipTo; }
conn1.commit(); PTableKey key = new PTableKey(null,fullTableName); PMetaData metaCache = conn1.unwrap(PhoenixConnection.class).getMetaDataCache(); PTable table = metaCache.getTableRef(key).getTable(); for (PTable index : table.getIndexes()) {
private static void assertUseStatsForQueryFlag(String tableName, PhoenixConnection conn, Boolean expected) throws TableNotFoundException, SQLException { assertEquals(expected, conn.unwrap(PhoenixConnection.class).getMetaDataCache() .getTableRef(new PTableKey(null, tableName)).getTable() .useStatsForParallelization()); String query = "SELECT USE_STATS_FOR_PARALLELIZATION FROM SYSTEM.CATALOG WHERE TABLE_NAME = ? AND COLUMN_NAME IS NULL AND COLUMN_FAMILY IS NULL AND TENANT_ID IS NULL"; PreparedStatement stmt = conn.prepareStatement(query); stmt.setString(1, tableName); ResultSet rs = stmt.executeQuery(); rs.next(); boolean b = rs.getBoolean(1); if (expected == null) { assertTrue(rs.wasNull()); } else { assertEquals(expected, b); } }
try (PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class)) { pconn.createStatement().execute("CREATE TABLE " + tableName + " (k DECIMAL PRIMARY KEY)"); final PTable table = pconn.getMetaDataCache().getTableRef(new PTableKey(null, tableName)).getTable(); KeyPart baseKeyPart = new KeyPart() {
if (logger.isInfoEnabled()) logger.info("Checking for index updates as of " + getInitialWritePointer()); MetaDataClient client = new MetaDataClient(connection); PMetaData cache = connection.getMetaDataCache(); boolean addedAnyIndexes = false; boolean allImmutableTables = !txTableRefs.isEmpty();
EnvironmentEdgeManager.injectEdge(clock); try (Connection conn = DriverManager.getConnection(getUrl())) { PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache(); conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR, v3 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2) INCLUDE (v3)");
long clientTimeStamp = scn == null ? HConstants.LATEST_TIMESTAMP : scn; try { PFunction function = connection.getMetaDataCache().getFunction(new PTableKey(tenantId, functionName)); if (function.isTemporaryFunction()) { connection.removeFunction(tenantId, functionName, clientTimeStamp);
private static void invalidateStats(Connection conn, String tableName) throws SQLException { PTable ptable = conn.unwrap(PhoenixConnection.class) .getMetaDataCache().getTableRef(new PTableKey(null, tableName)) .getTable(); byte[] name = ptable.getPhysicalName().getBytes(); conn.unwrap(PhoenixConnection.class).getQueryServices().invalidateStats(new GuidePostsKey(name, SchemaUtil.getEmptyColumnFamily(ptable))); }
@Test public void testRegionsOnlineCheck() throws Throwable { String schemaName = generateUniqueName(); String tableName = generateUniqueName(); final String fullTableName = SchemaUtil.getTableName(schemaName, tableName); PTableKey key = new PTableKey(null,fullTableName); try (Connection conn = DriverManager.getConnection(getUrl())) { PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache(); conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY)"); conn.createStatement().execute("UPSERT INTO " + fullTableName + " VALUES('a')"); conn.commit(); Configuration conf = conn.unwrap(PhoenixConnection.class).getQueryServices().getConfiguration(); PTable table = metaCache.getTableRef(key).getTable(); assertTrue(MetaDataUtil.tableRegionsOnline(conf, table)); try (Admin admin = conn.unwrap(PhoenixConnection.class).getQueryServices().getAdmin()) { admin.disableTable(TableName.valueOf(fullTableName)); assertFalse(MetaDataUtil.tableRegionsOnline(conf, table)); admin.enableTable(TableName.valueOf(fullTableName)); } assertTrue(MetaDataUtil.tableRegionsOnline(conf, table)); } }
EnvironmentEdgeManager.injectEdge(clock); try (Connection conn = DriverManager.getConnection(getUrl())) { PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache(); conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2)");
conn.unwrap(PhoenixConnection.class).getMetaDataCache())) { try { phxConn.createStatement().execute(
EnvironmentEdgeManager.injectEdge(clock); try (Connection conn = DriverManager.getConnection(getUrl())) { PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache(); conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2)");
EnvironmentEdgeManager.injectEdge(clock); try (Connection conn = DriverManager.getConnection(getUrl())) { PMetaData metaCache = conn.unwrap(PhoenixConnection.class).getMetaDataCache(); conn.createStatement().execute("CREATE TABLE " + fullTableName + "(k VARCHAR PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) COLUMN_ENCODED_BYTES = 0, STORE_NULLS=true"); conn.createStatement().execute("CREATE INDEX " + indexName + " ON " + fullTableName + " (v1, v2)");