@Override public void removeFunction(PName tenantId, String function, long functionTimeStamp) throws SQLException { this.metaData.functions.remove(new PTableKey(tenantId, function)); }
@Override public MetaDataMutationResult getSchema(String schemaName, long clientTimestamp) throws SQLException { try { PSchema schema = metaData.getSchema(new PTableKey(null, schemaName)); new MetaDataMutationResult(MutationCode.SCHEMA_ALREADY_EXISTS, schema, 0); } catch (SchemaNotFoundException e) {} return new MetaDataMutationResult(MutationCode.SCHEMA_NOT_FOUND, 0, null); }
private static void addToTable(PMetaData metaData, String name, int size, TestTimeKeeper timeKeeper) throws SQLException { PTable table = new PSizedTable(new PTableKey(null,name), size); metaData.addTable(table, System.currentTimeMillis()); timeKeeper.incrementTime(); }
public PSchema(String schemaName, long timeStamp) { this.schemaName = PNameFactory.newName(SchemaUtil.normalizeIdentifier(schemaName)); this.schemaKey = new PTableKey(null, this.schemaName.getString()); this.timeStamp = timeStamp; this.estimatedSize = SizedUtil.INT_SIZE + SizedUtil.LONG_SIZE + PNameFactory.getEstimatedSize(this.schemaName); }
private HashSet<String> existingColumnFamiliesForBaseTable(PName baseTableName) throws TableNotFoundException { throwConnectionClosedIfNullMetaData(); PTable table = latestMetaData.getTableRef(new PTableKey(null, baseTableName.getString())).getTable(); return existingColumnFamilies(table); }
@Override public MetaDataMutationResult getTable(PName tenantId, byte[] schemaBytes, byte[] tableBytes, long tableTimestamp, long clientTimestamp, boolean skipAddingIndexes, boolean skipCombiningColumns, PTable ancestorTable) throws SQLException { // Return result that will cause client to use it's own metadata instead of needing // to get anything from the server (since we don't have a connection) try { String fullTableName = SchemaUtil.getTableName(schemaBytes, tableBytes); PTable table = metaData.getTableRef(new PTableKey(tenantId, fullTableName)).getTable(); return new MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS, 0, table, true); } catch (TableNotFoundException e) { return new MetaDataMutationResult(MutationCode.TABLE_NOT_FOUND, 0, null); } }
@Before public void setup() throws Exception { Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES); conn = DriverManager.getConnection(getUrl(), props); PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class); pDataTable = pconn.getTable(new PTableKey(pconn.getTenantId(), DATA_TABLE_FULL_NAME)); pIndexTable = pconn.getTable(new PTableKey(pconn.getTenantId(), INDEX_TABLE_FULL_NAME)); }
private void validatePropertyOnViewIndex(String viewName, String viewIndexName, boolean useStats, Connection conn, Connection tenantConn) throws SQLException, TableNotFoundException { // fetch the latest view ptable PhoenixRuntime.getTableNoCache(tenantConn, viewName); PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class); PTable viewIndex = phxConn.getTable(new PTableKey(phxConn.getTenantId(), viewIndexName)); assertEquals("USE_STATS_FOR_PARALLELIZATION property set incorrectly", useStats, PhoenixConfigurationUtil .getStatsForParallelizationProp(tenantConn.unwrap(PhoenixConnection.class), viewIndex)); }
private static void assertNoActiveIndex(Connection conn, String schemaName, String tableName) throws SQLException { ImmutableBytesWritable ptr = new ImmutableBytesWritable(); String fullTableName = SchemaUtil.getTableName(schemaName, tableName); conn.createStatement().executeQuery("SELECT count(*) FROM " + fullTableName).next(); // client side cache will update PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class); pconn.getTable(new PTableKey(pconn.getTenantId(), fullTableName)).getIndexMaintainers(ptr, pconn); assertTrue(ptr.getLength() == 0); }
private static void assertActiveIndex(Connection conn, String schemaName, String tableName) throws SQLException { ImmutableBytesWritable ptr = new ImmutableBytesWritable(); String fullTableName = SchemaUtil.getTableName(schemaName, tableName); conn.createStatement().executeQuery("SELECT count(*) FROM " + fullTableName).next(); // client side cache will update PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class); pconn.getTable(new PTableKey(pconn.getTenantId(), fullTableName)).getIndexMaintainers(ptr, pconn); assertTrue(ptr.getLength() > 0); }
private static PTable getFromTable(PMetaData metaData, String name, TestTimeKeeper timeKeeper) throws TableNotFoundException { PTable table = metaData.getTableRef(new PTableKey(null,name)).getTable(); timeKeeper.incrementTime(); return table; }
private static void asssertIsWALDisabled(Connection conn, String fullTableName, boolean expectedValue) throws SQLException { PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class); assertEquals(expectedValue, pconn.getTable(new PTableKey(pconn.getTenantId(), fullTableName)).isWALDisabled()); }
private void assertImmutableRows(Connection conn, String fullTableName, boolean expectedValue) throws SQLException { PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class); assertEquals(expectedValue, pconn.getTable(new PTableKey(pconn.getTenantId(), fullTableName)).isImmutableRows()); }
@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()); }
private void assertColumnEncodingMetadata(QualifierEncodingScheme expectedEncodingScheme, ImmutableStorageScheme expectedStorageScheme, String tableName, Connection conn) throws Exception { PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class); PTable table = phxConn.getTable(new PTableKey(null, tableName)); assertEquals(expectedEncodingScheme, table.getEncodingScheme()); assertEquals(expectedStorageScheme, table.getImmutableStorageScheme()); }
private static short getMaxKeySequenceNumber(PhoenixConnection conn, String tableName) throws SQLException { PTable table = conn.getTable(new PTableKey(conn.getTenantId(), SchemaUtil.normalizeIdentifier(tableName))); return SchemaUtil.getMaxKeySeq(table); }
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; }
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))); }
private boolean checkColumnPartOfPk(PhoenixConnection conn, String columnName, String tableName) throws SQLException { String normalizedTableName = SchemaUtil.normalizeIdentifier(tableName); PTable table = conn.getTable(new PTableKey(conn.getTenantId(), normalizedTableName)); List<PColumn> pkCols = table.getPKColumns(); String normalizedColumnName = SchemaUtil.normalizeIdentifier(columnName); for (PColumn pkCol : pkCols) { if (pkCol.getName().getString().equals(normalizedColumnName)) { return true; } } return false; }
@Test public void testCompile() throws Exception { try (Connection conn = DriverManager.getConnection(getUrl())) { setupTables(conn); PhoenixConnection pConn = conn.unwrap(PhoenixConnection.class); PTable pDataTable = pConn.getTable(new PTableKey(null, "T")); PostIndexDDLCompiler compiler = new PostIndexDDLCompiler(pConn, new TableRef(pDataTable)); MutationPlan plan = compiler.compile(pConn.getTable(new PTableKey(null, "IDX"))); assertEquals("T", plan.getQueryPlan().getTableRef().getTable().getTableName().getString()); } }