use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class SaltedIndexIT method makeImmutableAndDeleteData.
private static void makeImmutableAndDeleteData(String tableName, String fullTableName) throws Exception {
Connection conn = getConnection();
try {
conn.setAutoCommit(true);
conn.createStatement().execute("DELETE FROM " + fullTableName);
conn.createStatement().execute("ALTER TABLE " + fullTableName + " SET IMMUTABLE_ROWS=true");
conn.createStatement().executeQuery("SELECT COUNT(*) FROM " + fullTableName).next();
PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
assertTrue(pconn.getTable(new PTableKey(pconn.getTenantId(), fullTableName)).isImmutableRows());
} finally {
conn.close();
}
}
use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class IndexMaintainerTest method tesIndexedExpressionSerialization.
@Test
public void tesIndexedExpressionSerialization() throws Exception {
Properties props = PropertiesUtil.deepCopy(TestUtil.TEST_PROPERTIES);
Connection conn = DriverManager.getConnection(getUrl(), props);
try {
conn.setAutoCommit(true);
conn.createStatement().execute("CREATE TABLE IF NOT EXISTS FHA (ORGANIZATION_ID CHAR(15) NOT NULL, PARENT_ID CHAR(15) NOT NULL, CREATED_DATE DATE NOT NULL, ENTITY_HISTORY_ID CHAR(15) NOT NULL, FIELD_HISTORY_ARCHIVE_ID CHAR(15), CREATED_BY_ID VARCHAR, FIELD VARCHAR, DATA_TYPE VARCHAR, OLDVAL_STRING VARCHAR, NEWVAL_STRING VARCHAR, OLDVAL_FIRST_NAME VARCHAR, NEWVAL_FIRST_NAME VARCHAR, OLDVAL_LAST_NAME VARCHAR, NEWVAL_LAST_NAME VARCHAR, OLDVAL_NUMBER DECIMAL, NEWVAL_NUMBER DECIMAL, OLDVAL_DATE DATE, NEWVAL_DATE DATE, ARCHIVE_PARENT_TYPE VARCHAR, ARCHIVE_FIELD_NAME VARCHAR, ARCHIVE_TIMESTAMP DATE, ARCHIVE_PARENT_NAME VARCHAR, DIVISION INTEGER, CONNECTION_ID VARCHAR CONSTRAINT PK PRIMARY KEY (ORGANIZATION_ID, PARENT_ID, CREATED_DATE DESC, ENTITY_HISTORY_ID )) VERSIONS=1,MULTI_TENANT=true");
conn.createStatement().execute("CREATE INDEX IDX ON FHA (FIELD_HISTORY_ARCHIVE_ID, UPPER(OLDVAL_STRING) || UPPER(NEWVAL_STRING), NEWVAL_DATE - NEWVAL_DATE)");
PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
PTable table = pconn.getTable(new PTableKey(pconn.getTenantId(), "FHA"));
ImmutableBytesWritable ptr = new ImmutableBytesWritable();
table.getIndexMaintainers(ptr, pconn);
List<IndexMaintainer> indexMaintainerList = IndexMaintainer.deserialize(ptr, GenericKeyValueBuilder.INSTANCE, true);
assertEquals(1, indexMaintainerList.size());
IndexMaintainer indexMaintainer = indexMaintainerList.get(0);
Set<ColumnReference> indexedColumns = indexMaintainer.getIndexedColumns();
assertEquals("Unexpected Number of indexed columns ", indexedColumns.size(), 4);
} finally {
conn.close();
}
}
use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class ExplainPlanWithStatsEnabledIT method assertUseStatsForQueryFlag.
private static void assertUseStatsForQueryFlag(String tableName, PhoenixConnection conn, boolean flag) throws TableNotFoundException, SQLException {
assertEquals(flag, 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();
assertEquals(flag, rs.getBoolean(1));
}
use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class QueryCompilerTest method testNullAlterTableDefaultRemoved.
@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());
}
use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class QueryCompilerTest method testNullDefaultRemoved.
@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());
}
Aggregations