You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by st...@apache.org on 2022/03/25 13:31:15 UTC
[phoenix] branch 4.16 updated: PHOENIX-6616 Alter table command can be used to set normalization_enabled=true on salted tables
This is an automated email from the ASF dual-hosted git repository.
stoty pushed a commit to branch 4.16
in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.16 by this push:
new 27816e4 PHOENIX-6616 Alter table command can be used to set normalization_enabled=true on salted tables
27816e4 is described below
commit 27816e421022f0747d3219dbc01826482cf3ecec
Author: Istvan Toth <st...@apache.org>
AuthorDate: Thu Mar 24 09:50:26 2022 +0100
PHOENIX-6616 Alter table command can be used to set normalization_enabled=true on salted tables
---
.../org/apache/phoenix/end2end/AlterTableIT.java | 95 ++++++++++++++++++++++
.../phoenix/query/ConnectionQueryServicesImpl.java | 12 ++-
2 files changed, 106 insertions(+), 1 deletion(-)
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
index 83bf222..1c7c77a 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterTableIT.java
@@ -1578,4 +1578,99 @@ public class AlterTableIT extends ParallelStatsDisabledIT {
}
}
+ @Test
+ public void testNormalizerCannotBeEnabledForSalted() throws Exception {
+ String tableName = generateUniqueName();
+ String indexName = generateUniqueName();
+
+ String mtTableName = generateUniqueName();
+ String mtViewName = generateUniqueName();
+ String mtIndexName = generateUniqueName();
+
+ String ddl =
+ "create table " + tableName + " ( id integer PRIMARY KEY," + " col1 integer,"
+ + " col2 bigint" + " ) SALT_BUCKETS=4";
+ String indexDdl =
+ "create index IF NOT EXISTS " + indexName + " on " + tableName + " (col2)";
+ String mtDdl =
+ "CREATE TABLE " + mtTableName + " (TenantId UNSIGNED_INT NOT NULL ,"
+ + " Id UNSIGNED_INT NOT NULL ," + " val VARCHAR, "
+ + " CONSTRAINT pk PRIMARY KEY(TenantId, Id) "
+ + " ) MULTI_TENANT=true, SALT_BUCKETS=4";
+ String mtViewDdl =
+ "CREATE VIEW " + mtViewName + "(view_column CHAR(15)) AS " + " SELECT * FROM "
+ + mtTableName + " WHERE val='L' ";
+ String mtIndexDdl = "CREATE INDEX " + mtIndexName + " on " + mtViewName + " (view_column) ";
+
+ String conflictDdl =
+ "ALTER TABLE " + tableName + " SET " + HTableDescriptor.NORMALIZATION_ENABLED
+ + "=true";
+
+ String conflictIndexDdl =
+ "ALTER TABLE " + indexName + " SET " + HTableDescriptor.NORMALIZATION_ENABLED
+ + "=true";
+
+ String conflictMtDdl =
+ "ALTER TABLE " + mtTableName + " SET "
+ + HTableDescriptor.NORMALIZATION_ENABLED + "=true";
+
+ String conflictMtViewDdl =
+ "ALTER TABLE " + indexName + " SET " + HTableDescriptor.NORMALIZATION_ENABLED
+ + "=true";
+
+ String conflictMtIndexDdl =
+ "ALTER TABLE " + mtIndexName + " SET "
+ + HTableDescriptor.NORMALIZATION_ENABLED + "=true";
+
+ String okDdl =
+ "ALTER TABLE " + tableName + " SET " + HTableDescriptor.NORMALIZATION_ENABLED
+ + "=false";
+
+ Properties props = new Properties();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props);
+ Statement stmt = conn.createStatement()) {
+ stmt.execute(ddl);
+ stmt.execute(indexDdl);
+ stmt.execute(mtDdl);
+ stmt.execute(mtViewDdl);
+ stmt.execute(mtIndexDdl);
+
+ try {
+ stmt.execute(conflictDdl);
+ fail("Should have thrown an exception");
+ } catch (SQLException e) {
+ assertEquals(1147, e.getErrorCode());
+ }
+
+ try {
+ stmt.execute(conflictIndexDdl);
+ fail("Should have thrown an exception");
+ } catch (SQLException e) {
+ assertEquals(1147, e.getErrorCode());
+ }
+
+ try {
+ stmt.execute(conflictMtDdl);
+ fail("Should have thrown an exception");
+ } catch (SQLException e) {
+ assertEquals(1147, e.getErrorCode());
+ }
+
+ try {
+ stmt.execute(conflictMtViewDdl);
+ fail("Should have thrown an exception");
+ } catch (SQLException e) {
+ assertEquals(1147, e.getErrorCode());
+ }
+
+ try {
+ stmt.execute(conflictMtIndexDdl);
+ fail("Should have thrown an exception");
+ } catch (SQLException e) {
+ assertEquals(1147, e.getErrorCode());
+ }
+
+ stmt.execute(okDdl);
+ }
+ }
}
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
index 1a79a7d..0030a80 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/query/ConnectionQueryServicesImpl.java
@@ -2308,8 +2308,8 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
// Special case for call during drop table to ensure that the empty column family exists.
// In this, case we only include the table header row, as until we add schemaBytes and tableBytes
// as args to this function, we have no way of getting them in this case.
+ // Also used to update table descriptor property values on ALTER TABLE t SET prop=xxx
// TODO: change to if (tableMetaData.isEmpty()) once we pass through schemaBytes and tableBytes
- // Also, could be used to update property values on ALTER TABLE t SET prop=xxx
if ((tableMetaData.isEmpty()) || (tableMetaData.size() == 1 && tableMetaData.get(0).isEmpty())) {
if (modifyHTable) {
sendHBaseMetaData(tableDescriptors, pollingNeeded);
@@ -2575,6 +2575,16 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement
.build()
.buildException();
}
+ if (propName.equals(HTableDescriptor.NORMALIZATION_ENABLED)
+ && (Boolean)propValue == true
+ && table.getPropertyValues().containsKey(PhoenixDatabaseMetaData.SALT_BUCKETS)
+ && Integer.parseInt(table.getPropertyValues().get(PhoenixDatabaseMetaData.SALT_BUCKETS)) > 0) {
+ throw new SQLExceptionInfo.Builder(SQLExceptionCode.NO_NORMALIZER_ON_SALTED_TABLE)
+ .setSchemaName(table.getSchemaName().getString())
+ .setTableName(table.getTableName().getString())
+ .build()
+ .buildException();
+ }
tableProps.put(propName, propValue);
} else {
if (TableProperty.isPhoenixTableProperty(propName)) {