use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class AlterTableIT method testClientCacheUpdatedOnChangingPhoenixTableProperties.
@Test
public void testClientCacheUpdatedOnChangingPhoenixTableProperties() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
try {
String ddl = "create table " + dataTableFullName + " (" + " id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2 bigint NOT NULL," + " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)" + " ) " + tableDDLOptions;
conn.createStatement().execute(ddl);
asssertIsWALDisabled(conn, dataTableFullName, false);
ddl = "ALTER TABLE " + dataTableFullName + " SET DISABLE_WAL = true";
conn.createStatement().execute(ddl);
// check metadata cache is updated with DISABLE_WAL = true
asssertIsWALDisabled(conn, dataTableFullName, true);
ddl = "ALTER TABLE " + dataTableFullName + " SET DISABLE_WAL = false";
conn.createStatement().execute(ddl);
// check metadata cache is updated with DISABLE_WAL = false
asssertIsWALDisabled(conn, dataTableFullName, false);
ddl = "ALTER TABLE " + dataTableFullName + " SET MULTI_TENANT = true";
conn.createStatement().execute(ddl);
// check metadata cache is updated with MULTI_TENANT = true
PTable t = conn.unwrap(PhoenixConnection.class).getTable(new PTableKey(null, dataTableFullName));
assertTrue(t.isMultiTenant());
// check table metadata updated server side
ResultSet rs = conn.createStatement().executeQuery("SELECT DISABLE_WAL, MULTI_TENANT FROM \"SYSTEM\".\"CATALOG\"" + "WHERE table_name = '" + dataTableFullName + "' AND DISABLE_WAL IS NOT NULL AND MULTI_TENANT IS NOT NULL");
assertTrue(rs.next());
assertFalse(rs.getBoolean(1));
assertTrue(rs.getBoolean(2));
assertFalse(rs.next());
rs.close();
} finally {
conn.close();
}
}
use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class AlterTableWithViewsIT method testAlterAppendOnlySchema.
@Test
public void testAlterAppendOnlySchema() throws Exception {
try (Connection conn = DriverManager.getConnection(getUrl());
Connection viewConn = isMultiTenant ? DriverManager.getConnection(TENANT_SPECIFIC_URL1) : conn) {
String baseTableName = "NONTXNTBL_" + generateUniqueName() + (isMultiTenant ? "0" : "1");
String viewOfTable = baseTableName + "_VIEW";
String ddl = "CREATE TABLE " + baseTableName + " (\n" + "%s ID VARCHAR(15) NOT NULL,\n" + " COL1 integer NOT NULL," + "CREATED_DATE DATE,\n" + "CONSTRAINT PK PRIMARY KEY (%s ID, COL1)) %s";
conn.createStatement().execute(generateDDL(ddl));
ddl = "CREATE VIEW " + viewOfTable + " AS SELECT * FROM " + baseTableName;
viewConn.createStatement().execute(ddl);
PhoenixConnection phoenixConn = conn.unwrap(PhoenixConnection.class);
PTable table = phoenixConn.getTable(new PTableKey(null, baseTableName));
PName tenantId = isMultiTenant ? PNameFactory.newName("tenant1") : null;
assertFalse(table.isAppendOnlySchema());
PTable viewTable = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable));
assertFalse(viewTable.isAppendOnlySchema());
try {
viewConn.createStatement().execute("ALTER VIEW " + viewOfTable + " SET APPEND_ONLY_SCHEMA = true");
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.CANNOT_ALTER_TABLE_PROPERTY_ON_VIEW.getErrorCode(), e.getErrorCode());
}
conn.createStatement().execute("ALTER TABLE " + baseTableName + " SET APPEND_ONLY_SCHEMA = true");
viewConn.createStatement().execute("SELECT * FROM " + viewOfTable);
phoenixConn = conn.unwrap(PhoenixConnection.class);
table = phoenixConn.getTable(new PTableKey(null, baseTableName));
assertTrue(table.isAppendOnlySchema());
viewTable = viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable));
assertTrue(viewTable.isAppendOnlySchema());
}
}
use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class AlterTableWithViewsIT method testAlterTablePropertyOnView.
@Test
public void testAlterTablePropertyOnView() throws Exception {
try (Connection conn = DriverManager.getConnection(getUrl());
Connection viewConn = isMultiTenant ? DriverManager.getConnection(TENANT_SPECIFIC_URL1) : conn) {
String baseTableName = "NONTXNTBL_" + generateUniqueName() + (isMultiTenant ? "0" : "1");
String viewOfTable = baseTableName + "_VIEW";
String ddl = "CREATE TABLE " + baseTableName + " (\n" + "%s ID VARCHAR(15) NOT NULL,\n" + " COL1 integer NOT NULL," + "CREATED_DATE DATE,\n" + "CONSTRAINT PK PRIMARY KEY (%s ID, COL1)) %s";
conn.createStatement().execute(generateDDL(ddl));
ddl = "CREATE VIEW " + viewOfTable + " AS SELECT * FROM " + baseTableName;
viewConn.createStatement().execute(ddl);
try {
viewConn.createStatement().execute("ALTER VIEW " + viewOfTable + " SET IMMUTABLE_ROWS = true");
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.CANNOT_ALTER_TABLE_PROPERTY_ON_VIEW.getErrorCode(), e.getErrorCode());
}
viewConn.createStatement().execute("ALTER VIEW " + viewOfTable + " SET UPDATE_CACHE_FREQUENCY = 100");
viewConn.createStatement().execute("SELECT * FROM " + viewOfTable);
PName tenantId = isMultiTenant ? PNameFactory.newName("tenant1") : null;
assertEquals(100, viewConn.unwrap(PhoenixConnection.class).getTable(new PTableKey(tenantId, viewOfTable)).getUpdateCacheFrequency());
try {
viewConn.createStatement().execute("ALTER VIEW " + viewOfTable + " SET APPEND_ONLY_SCHEMA = true");
fail();
} catch (SQLException e) {
assertEquals(SQLExceptionCode.CANNOT_ALTER_TABLE_PROPERTY_ON_VIEW.getErrorCode(), e.getErrorCode());
}
}
}
use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class ColumnEncodedBytesPropIT method testValidateProperty.
@Test
public void testValidateProperty() throws SQLException {
Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
String dataTableFullName1 = SchemaUtil.getTableName("", generateUniqueName());
String dataTableFullName2 = SchemaUtil.getTableName("", generateUniqueName());
try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
Statement stmt = conn.createStatement();
String ddl = "CREATE TABLE " + dataTableFullName1 + " (id varchar not null, val varchar " + " CONSTRAINT pk PRIMARY KEY (id)) COLUMN_ENCODED_BYTES=4";
stmt.execute(ddl);
ddl = "CREATE TABLE " + dataTableFullName2 + " (id varchar not null, val varchar " + " CONSTRAINT pk PRIMARY KEY (id)) COLUMN_ENCODED_BYTES=NONE";
stmt.execute(ddl);
PhoenixConnection phxConn = conn.unwrap(PhoenixConnection.class);
PTable dataTable1 = phxConn.getTable(new PTableKey(null, dataTableFullName1));
assertEquals("Encoding scheme set incorrectly", QualifierEncodingScheme.FOUR_BYTE_QUALIFIERS, dataTable1.getEncodingScheme());
PTable dataTable2 = phxConn.getTable(new PTableKey(null, dataTableFullName2));
assertEquals("Encoding scheme set incorrectly", QualifierEncodingScheme.NON_ENCODED_QUALIFIERS, dataTable2.getEncodingScheme());
}
}
use of org.apache.phoenix.schema.PTableKey in project phoenix by apache.
the class AlterMultiTenantTableWithViewsIT method checkColumnPartOfPk.
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;
}
Aggregations