This is an automated email from the ASF dual-hosted git repository. stoty pushed a commit to branch 5.1 in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/5.1 by this push: new 499e34a PHOENIX-6616 Alter table command can be used to set normalization_enabled=true on salted tables 499e34a is described below commit 499e34a5c5565ab650d0e3d317625cf33b20cde9 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 | 97 ++++++++++++++++++++++ .../phoenix/query/ConnectionQueryServicesImpl.java | 12 ++- 2 files changed, 108 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 dc62472..60fa923 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 @@ -52,6 +52,7 @@ import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.ColumnFamilyDescriptor; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.client.TableDescriptor; +import org.apache.hadoop.hbase.client.TableDescriptorBuilder; import org.apache.hadoop.hbase.util.Bytes; import org.apache.phoenix.exception.SQLExceptionCode; import org.apache.phoenix.jdbc.PhoenixConnection; @@ -1576,4 +1577,100 @@ 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 " + TableDescriptorBuilder.NORMALIZATION_ENABLED + + "=true"; + + String conflictIndexDdl = + "ALTER TABLE " + indexName + " SET " + TableDescriptorBuilder.NORMALIZATION_ENABLED + + "=true"; + + String conflictMtDdl = + "ALTER TABLE " + mtTableName + " SET " + + TableDescriptorBuilder.NORMALIZATION_ENABLED + "=true"; + + String conflictMtViewDdl = + "ALTER TABLE " + indexName + " SET " + TableDescriptorBuilder.NORMALIZATION_ENABLED + + "=true"; + + String conflictMtIndexDdl = + "ALTER TABLE " + mtIndexName + " SET " + + TableDescriptorBuilder.NORMALIZATION_ENABLED + "=true"; + + String okDdl = + "ALTER TABLE " + tableName + " SET " + TableDescriptorBuilder.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); + } + } + } \ No newline at end of file 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 4c4b07b..202bad9 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 @@ -2337,8 +2337,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); @@ -2607,6 +2607,16 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement .build() .buildException(); } + if (propName.equals(TableDescriptorBuilder.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)) {