Search in sources :

Example 6 with PTableKey

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();
    }
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) PTableKey(org.apache.phoenix.schema.PTableKey)

Example 7 with PTableKey

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();
    }
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Properties(java.util.Properties) PTableKey(org.apache.phoenix.schema.PTableKey) PTable(org.apache.phoenix.schema.PTable) ColumnReference(org.apache.phoenix.hbase.index.covered.update.ColumnReference) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 8 with PTableKey

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));
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) PTableKey(org.apache.phoenix.schema.PTableKey)

Example 9 with PTableKey

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());
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) PTableKey(org.apache.phoenix.schema.PTableKey) PTable(org.apache.phoenix.schema.PTable) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 10 with PTableKey

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());
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) PTableKey(org.apache.phoenix.schema.PTableKey) PTable(org.apache.phoenix.schema.PTable) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Aggregations

PTableKey (org.apache.phoenix.schema.PTableKey)89 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)77 PTable (org.apache.phoenix.schema.PTable)55 Connection (java.sql.Connection)48 Test (org.junit.Test)40 Properties (java.util.Properties)23 ResultSet (java.sql.ResultSet)14 PColumn (org.apache.phoenix.schema.PColumn)14 PreparedStatement (java.sql.PreparedStatement)13 HTableInterface (org.apache.hadoop.hbase.client.HTableInterface)12 SQLException (java.sql.SQLException)11 TableNotFoundException (org.apache.phoenix.schema.TableNotFoundException)11 PMetaData (org.apache.phoenix.schema.PMetaData)10 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)9 PName (org.apache.phoenix.schema.PName)9 BaseTest (org.apache.phoenix.query.BaseTest)8 Result (org.apache.hadoop.hbase.client.Result)7 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)7 Scan (org.apache.hadoop.hbase.client.Scan)7 MetaDataMutationResult (org.apache.phoenix.coprocessor.MetaDataProtocol.MetaDataMutationResult)6