This is an automated email from the ASF dual-hosted git repository. stoty pushed a commit to branch 4.x in repository https://gitbox.apache.org/repos/asf/phoenix.git
The following commit(s) were added to refs/heads/4.x by this push: new 7265be4 PHOENIX-6586 Set NORMALIZATION_ENABLED to false on salted tables 7265be4 is described below commit 7265be48f3ccd23418697c6c6255146ab7740cdd Author: Istvan Toth <st...@apache.org> AuthorDate: Thu Nov 4 15:48:27 2021 +0100 PHOENIX-6586 Set NORMALIZATION_ENABLED to false on salted tables --- .../org/apache/phoenix/end2end/CreateTableIT.java | 57 ++++++++++++++++++++++ .../apache/phoenix/exception/SQLExceptionCode.java | 3 +- .../phoenix/query/ConnectionQueryServicesImpl.java | 10 ++++ .../org/apache/phoenix/schema/MetaDataClient.java | 6 +++ 4 files changed, 75 insertions(+), 1 deletion(-) diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java index e41b6ae..16b2928 100644 --- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java +++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/CreateTableIT.java @@ -1232,6 +1232,63 @@ public class CreateTableIT extends ParallelStatsDisabledIT { } } + @Test + public void testNormalizerIsDisbledForSalted() throws Exception { + String tableName = generateUniqueName(); + String indexName = generateUniqueName(); + + String mtTableName = generateUniqueName(); + String mtViewName = generateUniqueName(); + String mtIndexName = generateUniqueName(); + + String conflictTableName = 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 confictDdl = + "create table " + conflictTableName + " ( id integer PRIMARY KEY," + + " col1 integer," + " col2 bigint" + " ) SALT_BUCKETS=4, " + + HTableDescriptor.NORMALIZATION_ENABLED + "=true"; + + Properties props = new Properties(); + Connection conn = DriverManager.getConnection(getUrl(), props); + conn.createStatement().execute(ddl); + conn.createStatement().execute(indexDdl); + conn.createStatement().execute(mtDdl); + conn.createStatement().execute(mtViewDdl); + conn.createStatement().execute(mtIndexDdl); + + HBaseAdmin admin = driver.getConnectionQueryServices(getUrl(), props).getAdmin(); + assertEquals("false", admin.getTableDescriptor(Bytes.toBytes(tableName)) + .getValue(HTableDescriptor.NORMALIZATION_ENABLED)); + assertEquals("false", admin.getTableDescriptor(Bytes.toBytes(indexName)) + .getValue(HTableDescriptor.NORMALIZATION_ENABLED)); + assertEquals("false", admin.getTableDescriptor(Bytes.toBytes(mtTableName)) + .getValue(HTableDescriptor.NORMALIZATION_ENABLED)); + assertEquals("false", admin.getTableDescriptor(Bytes.toBytes("_IDX_" + mtTableName)) + .getValue(HTableDescriptor.NORMALIZATION_ENABLED)); + + try { + conn.createStatement().execute(confictDdl); + fail("Should have thrown an exception"); + } catch (Exception e) { + assertTrue(e instanceof SQLException); + } + } + public static long verifyLastDDLTimestamp(String dataTableFullName, long startTS, Connection conn) throws SQLException { long endTS = EnvironmentEdgeManager.currentTimeMillis(); //Now try the PTable API diff --git a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java index 2e0c55f..c129d9a 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/exception/SQLExceptionCode.java @@ -261,13 +261,14 @@ public enum SQLExceptionCode { INVALID_BUCKET_NUM(1021, "42Y80", "Salt bucket numbers should be with 1 and 256."), NO_SPLITS_ON_SALTED_TABLE(1022, "42Y81", "Should not specify split points on salted table with default row key order."), SALT_ONLY_ON_CREATE_TABLE(1024, "42Y82", "Salt bucket number may only be specified when creating a table."), + NO_NORMALIZER_ON_SALTED_TABLE(1147, "42Y86", "Should not enable normalizer on salted table."), SET_UNSUPPORTED_PROP_ON_ALTER_TABLE(1025, "42Y83", "Unsupported property set in ALTER TABLE command."), CANNOT_ADD_NOT_NULLABLE_COLUMN(1038, "42Y84", "Only nullable columns may be added for a pre-existing table."), NO_MUTABLE_INDEXES(1026, "42Y85", "Mutable secondary indexes are only supported for HBase version " + MetaDataUtil.decodeHBaseVersionAsString(MetaDataProtocol.MUTABLE_SI_VERSION_THRESHOLD) + " and above."), INVALID_INDEX_STATE_TRANSITION(1028, "42Y87", "Invalid index state transition."), INVALID_MUTABLE_INDEX_CONFIG(1029, "42Y88", "Mutable secondary indexes must have the " + IndexManagementUtil.WAL_EDIT_CODEC_CLASS_KEY + " property set to " - + IndexManagementUtil.INDEX_WAL_EDIT_CODEC_CLASS_NAME + " in the hbase-sites.xml of every region server."), + + IndexManagementUtil.INDEX_WAL_EDIT_CODEC_CLASS_NAME + " in the hbase-sites.xml of every region server."), CANNOT_CREATE_DEFAULT(1031, "42Y90", "Cannot create column with a stateful default value."), CANNOT_CREATE_DEFAULT_ROWTIMESTAMP(1032, "42Y90", "Cannot create ROW_TIMESTAMP column with a default value."), 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 820209a..f84db78 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 @@ -1427,6 +1427,16 @@ public class ConnectionQueryServicesImpl extends DelegateQueryServices implement PBoolean.INSTANCE.toObject(newDesc.getValue(MetaDataUtil.IS_LOCAL_INDEX_TABLE_PROP_BYTES)))) { newDesc.setValue(HTableDescriptor.SPLIT_POLICY, IndexRegionSplitPolicy.class.getName()); } + if (props.get(PhoenixDatabaseMetaData.SALT_BUCKETS) != null + && (Integer) (props.get(PhoenixDatabaseMetaData.SALT_BUCKETS)) > 0) { + if (props.get(HTableDescriptor.NORMALIZATION_ENABLED) != null + && (Boolean)(props.get(HTableDescriptor.NORMALIZATION_ENABLED))) { + throw new SQLExceptionInfo.Builder(SQLExceptionCode.NO_NORMALIZER_ON_SALTED_TABLE) + .setSchemaName(SchemaUtil.getSchemaNameFromFullName(physicalTableName)) + .setTableName(SchemaUtil.getTableNameFromFullName(physicalTableName)).build().buildException(); + } + newDesc.setNormalizationEnabled(false); + } try { if (splits == null) { admin.createTable(newDesc); diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java index 65e31f8..64c6da2 100644 --- a/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java +++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/MetaDataClient.java @@ -1767,6 +1767,12 @@ public class MetaDataClient { if (dataTable.getDefaultFamilyName() != null && dataTable.getType() != PTableType.VIEW && !allocateIndexId) { statement.getProps().put("", new Pair<String,Object>(DEFAULT_COLUMN_FAMILY_NAME,dataTable.getDefaultFamilyName().getString())); } + // While SALT_BUCKETS would get copied in SYSCAT automatically, we need to add this + // explicitly so that the normalizer disabler logic can trigger later + if (dataTable.getBucketNum() != null && dataTable.getBucketNum() > 0 + && TableProperty.SALT_BUCKETS.getValue(tableProps) == null) { + tableProps.put(SALT_BUCKETS, dataTable.getBucketNum()); + } PrimaryKeyConstraint pk = FACTORY.primaryKey(null, allPkColumns); tableProps.put(MetaDataUtil.DATA_TABLE_NAME_PROP_NAME, dataTable.getPhysicalName().getString());