[
https://issues.apache.org/jira/browse/PHOENIX-6227?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17438369#comment-17438369
]
ASF GitHub Bot commented on PHOENIX-6227:
-----------------------------------------
gjacoby126 commented on a change in pull request #1341:
URL: https://github.com/apache/phoenix/pull/1341#discussion_r742156376
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
##########
@@ -42,14 +42,11 @@
import org.apache.phoenix.jdbc.PhoenixConnection;
import org.apache.phoenix.jdbc.PhoenixDatabaseMetaData;
import org.apache.phoenix.jdbc.PhoenixStatement;
-import org.apache.phoenix.schema.ColumnNotFoundException;
-import org.apache.phoenix.schema.PColumn;
-import org.apache.phoenix.schema.PTable;
-import org.apache.phoenix.schema.PTableKey;
-import org.apache.phoenix.schema.PTableType;
+import org.apache.phoenix.schema.*;
Review comment:
Fixed
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/AlterMultiTenantTableWithViewsIT.java
##########
@@ -82,7 +79,66 @@ private static void verifyNewColumns(ResultSet rs, String
... values) throws SQL
assertFalse(rs.next());
assertEquals(values.length, i - 1);
}
-
+
+ @Test
+ public void testCreateAndAlterViewsWithChangeDetectionEnabled() throws
Exception {
+ String tenantId = "TE_" + generateUniqueName();
+ String schemaName = "S_" + generateUniqueName();
+ String tableName = "T_" + generateUniqueName();
+ String globalViewName = "GV_" + generateUniqueName();
+ String tenantViewName = "TV_" + generateUniqueName();
+ String fullTableName = SchemaUtil.getTableName(schemaName, tableName);
+ String fullGlobalViewName = SchemaUtil.getTableName(schemaName,
globalViewName);
+ String fullTenantViewName = SchemaUtil.getTableName(schemaName,
tenantViewName);
+
+ PTable globalView = null;
+ PTable alteredGlobalView = null;
+ try (Connection conn = DriverManager.getConnection(getUrl())) {
+ String ddl = "CREATE TABLE " + fullTableName +
+ " (id char(1) NOT NULL," + " col1 integer NOT NULL," + " col2
bigint NOT NULL," +
+ " CONSTRAINT NAME_PK PRIMARY KEY (id, col1, col2)) " +
+ "MULTI_TENANT=true, CHANGE_DETECTION_ENABLED=true";
+ conn.createStatement().execute(ddl);
+ PTable table = PhoenixRuntime.getTableNoCache(conn, fullTableName);
+ assertTrue(table.isChangeDetectionEnabled());
+ AlterTableIT.verifySchemaExport(table,
getUtility().getConfiguration());
+
+ String globalViewDdl = "CREATE VIEW " + fullGlobalViewName +
+ " (id2 CHAR(12) NOT NULL PRIMARY KEY, col3 BIGINT NULL) " +
+ " AS SELECT * FROM " + fullTableName + "
CHANGE_DETECTION_ENABLED=true";
+
+ conn.createStatement().execute(globalViewDdl);
+ globalView = PhoenixRuntime.getTableNoCache(conn,
fullGlobalViewName);
+ assertTrue(globalView.isChangeDetectionEnabled());
+ // base column count doesn't get set properly
+ PTableImpl.Builder builder =
PTableImpl.builderFromExisting(globalView);
+ builder.setBaseColumnCount(table.getColumns().size());
+ globalView = builder.setColumns(globalView.getColumns()).build();
+ AlterTableIT.verifySchemaExport(globalView,
getUtility().getConfiguration());
+
+ String alterViewDdl = "ALTER VIEW " + fullGlobalViewName + " ADD
id3 VARCHAR(12) NULL "
Review comment:
Added tests
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -1148,115 +1235,203 @@ private PTable getTable(RegionScanner scanner, long
clientTimeStamp, long tableT
transactionProviderKv.getValueOffset(),
SortOrder.getDefault()));
}
+ builder.setTransactionProvider(transactionProviderKv != null ||
transactionalKv != null
+ ? transactionProvider : oldTable != null ?
oldTable.getTransactionProvider() : null);
+
Cell viewTypeKv = tableKeyValues[VIEW_TYPE_INDEX];
ViewType viewType = viewTypeKv == null ? null :
ViewType.fromSerializedValue(viewTypeKv.getValueArray()[viewTypeKv.getValueOffset()]);
- PDataType viewIndexIdType = getViewIndexIdType(tableKeyValues);
+ builder.setViewType(viewType != null ? viewType : oldTable != null ?
oldTable.getViewType() : null);
+
+ PDataType viewIndexIdType = oldTable != null ?
oldTable.getviewIndexIdType() :
+ getViewIndexIdType(tableKeyValues);
+ builder.setViewIndexIdType(viewIndexIdType);
+
Long viewIndexId = getViewIndexId(tableKeyValues, viewIndexIdType);
+ builder.setViewIndexId(viewIndexId != null ? viewIndexId : oldTable !=
null ? oldTable.getViewIndexId() : null);
+
Cell indexTypeKv = tableKeyValues[INDEX_TYPE_INDEX];
IndexType indexType = indexTypeKv == null ? null :
IndexType.fromSerializedValue(indexTypeKv.getValueArray()[indexTypeKv.getValueOffset()]);
+ builder.setIndexType(indexType != null ? indexType : oldTable != null
? oldTable.getIndexType() : null);
+
Cell baseColumnCountKv = tableKeyValues[BASE_COLUMN_COUNT_INDEX];
int baseColumnCount = baseColumnCountKv == null ? 0 :
PInteger.INSTANCE.getCodec().decodeInt(baseColumnCountKv.getValueArray(),
baseColumnCountKv.getValueOffset(), SortOrder.getDefault());
+ builder.setBaseColumnCount(baseColumnCountKv != null ? baseColumnCount
: oldTable != null ? oldTable.getBaseColumnCount() : 0);
+
Cell rowKeyOrderOptimizableKv =
tableKeyValues[ROW_KEY_ORDER_OPTIMIZABLE_INDEX];
- boolean rowKeyOrderOptimizable = rowKeyOrderOptimizableKv == null ?
false :
Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(rowKeyOrderOptimizableKv.getValueArray(),
rowKeyOrderOptimizableKv.getValueOffset(),
rowKeyOrderOptimizableKv.getValueLength()));
+ boolean rowKeyOrderOptimizable = rowKeyOrderOptimizableKv != null &&
Boolean.TRUE.equals(
+
PBoolean.INSTANCE.toObject(rowKeyOrderOptimizableKv.getValueArray(),
+ rowKeyOrderOptimizableKv.getValueOffset(),
+ rowKeyOrderOptimizableKv.getValueLength()));
+ builder.setRowKeyOrderOptimizable(rowKeyOrderOptimizableKv != null ?
rowKeyOrderOptimizable :
+ oldTable != null && oldTable.rowKeyOrderOptimizable());
+
Cell updateCacheFrequencyKv =
tableKeyValues[UPDATE_CACHE_FREQUENCY_INDEX];
long updateCacheFrequency = updateCacheFrequencyKv == null ? 0 :
PLong.INSTANCE.getCodec().decodeLong(updateCacheFrequencyKv.getValueArray(),
updateCacheFrequencyKv.getValueOffset(),
SortOrder.getDefault());
+ builder.setUpdateCacheFrequency(updateCacheFrequencyKv != null ?
updateCacheFrequency : oldTable != null ? oldTable.getUpdateCacheFrequency() :
0);
// Check the cell tag to see whether the view has modified this
property
final byte[] tagUpdateCacheFreq = (updateCacheFrequencyKv == null) ?
HConstants.EMPTY_BYTE_ARRAY :
CellUtil.getTagArray(updateCacheFrequencyKv);
boolean viewModifiedUpdateCacheFrequency =
(PTableType.VIEW.equals(tableType)) &&
Bytes.contains(tagUpdateCacheFreq,
VIEW_MODIFIED_PROPERTY_BYTES);
+
builder.setViewModifiedUpdateCacheFrequency(!Bytes.equals(tagUpdateCacheFreq,
+ HConstants.EMPTY_BYTE_ARRAY) ? viewModifiedUpdateCacheFrequency :
+ oldTable != null &&
oldTable.hasViewModifiedUpdateCacheFrequency());
+
Cell indexDisableTimestampKv = tableKeyValues[INDEX_DISABLE_TIMESTAMP];
long indexDisableTimestamp = indexDisableTimestampKv == null ? 0L :
PLong.INSTANCE.getCodec().decodeLong(indexDisableTimestampKv.getValueArray(),
indexDisableTimestampKv.getValueOffset(),
SortOrder.getDefault());
+ builder.setIndexDisableTimestamp(indexDisableTimestampKv != null ?
+ indexDisableTimestamp : oldTable != null ?
oldTable.getIndexDisableTimestamp() : 0L);
+
Cell isNamespaceMappedKv = tableKeyValues[IS_NAMESPACE_MAPPED_INDEX];
- boolean isNamespaceMapped = isNamespaceMappedKv == null ? false
- :
Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(isNamespaceMappedKv.getValueArray(),
+ boolean isNamespaceMapped = isNamespaceMappedKv != null &&
Boolean.TRUE.equals(
+ PBoolean.INSTANCE.toObject(isNamespaceMappedKv.getValueArray(),
isNamespaceMappedKv.getValueOffset(),
isNamespaceMappedKv.getValueLength()));
+ builder.setNamespaceMapped(isNamespaceMappedKv != null ?
isNamespaceMapped :
+ oldTable != null && oldTable.isNamespaceMapped());
+
Cell autoPartitionSeqKv = tableKeyValues[AUTO_PARTITION_SEQ_INDEX];
String autoPartitionSeq = autoPartitionSeqKv != null ? (String)
PVarchar.INSTANCE.toObject(autoPartitionSeqKv.getValueArray(),
autoPartitionSeqKv.getValueOffset(),
autoPartitionSeqKv.getValueLength()) : null;
+ builder.setAutoPartitionSeqName(autoPartitionSeq != null
+ ? autoPartitionSeq : oldTable != null ?
oldTable.getAutoPartitionSeqName() : null);
+
Cell isAppendOnlySchemaKv = tableKeyValues[APPEND_ONLY_SCHEMA_INDEX];
- boolean isAppendOnlySchema = isAppendOnlySchemaKv == null ? false
- :
Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(isAppendOnlySchemaKv.getValueArray(),
+ boolean isAppendOnlySchema = isAppendOnlySchemaKv != null &&
Boolean.TRUE.equals(
+ PBoolean.INSTANCE.toObject(isAppendOnlySchemaKv.getValueArray(),
isAppendOnlySchemaKv.getValueOffset(),
isAppendOnlySchemaKv.getValueLength()));
+ builder.setAppendOnlySchema(isAppendOnlySchemaKv != null ?
isAppendOnlySchema :
+ oldTable != null && oldTable.isAppendOnlySchema());
+
Cell storageSchemeKv = tableKeyValues[STORAGE_SCHEME_INDEX];
//TODO: change this once we start having other values for storage
schemes
ImmutableStorageScheme storageScheme = storageSchemeKv == null ?
ImmutableStorageScheme.ONE_CELL_PER_COLUMN : ImmutableStorageScheme
.fromSerializedValue((byte)
PTinyint.INSTANCE.toObject(storageSchemeKv.getValueArray(),
storageSchemeKv.getValueOffset(),
storageSchemeKv.getValueLength()));
+ builder.setImmutableStorageScheme(storageSchemeKv != null ?
storageScheme :
+ oldTable != null ? oldTable.getImmutableStorageScheme() :
ImmutableStorageScheme.ONE_CELL_PER_COLUMN);
+
Cell encodingSchemeKv =
tableKeyValues[QUALIFIER_ENCODING_SCHEME_INDEX];
QualifierEncodingScheme encodingScheme = encodingSchemeKv == null ?
QualifierEncodingScheme.NON_ENCODED_QUALIFIERS : QualifierEncodingScheme
.fromSerializedValue((byte)
PTinyint.INSTANCE.toObject(encodingSchemeKv.getValueArray(),
encodingSchemeKv.getValueOffset(),
encodingSchemeKv.getValueLength()));
+ builder.setQualifierEncodingScheme(encodingSchemeKv != null ?
encodingScheme :
+ oldTable != null ? oldTable.getEncodingScheme() :
QualifierEncodingScheme.NON_ENCODED_QUALIFIERS);
+
Cell useStatsForParallelizationKv =
tableKeyValues[USE_STATS_FOR_PARALLELIZATION_INDEX];
- Boolean useStatsForParallelization = useStatsForParallelizationKv ==
null ? null :
Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(useStatsForParallelizationKv.getValueArray(),
useStatsForParallelizationKv.getValueOffset(),
useStatsForParallelizationKv.getValueLength()));
+ Boolean useStatsForParallelization = useStatsForParallelizationKv ==
null ? null :
+
Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(useStatsForParallelizationKv.getValueArray(),
useStatsForParallelizationKv.getValueOffset(),
useStatsForParallelizationKv.getValueLength()));
+ builder.setUseStatsForParallelization(useStatsForParallelization !=
null ?
+ useStatsForParallelization : oldTable != null ?
oldTable.useStatsForParallelization() : null);
Cell phoenixTTLKv = tableKeyValues[PHOENIX_TTL_INDEX];
long phoenixTTL = phoenixTTLKv == null ? PHOENIX_TTL_NOT_DEFINED :
PLong.INSTANCE.getCodec().decodeLong(phoenixTTLKv.getValueArray(),
phoenixTTLKv.getValueOffset(), SortOrder.getDefault());
+ builder.setPhoenixTTL(phoenixTTLKv != null ? phoenixTTL :
+ oldTable != null ? oldTable.getPhoenixTTL() :
PHOENIX_TTL_NOT_DEFINED);
Cell phoenixTTLHWMKv = tableKeyValues[PHOENIX_TTL_HWM_INDEX];
long phoenixTTLHWM = phoenixTTLHWMKv == null ? MIN_PHOENIX_TTL_HWM :
PLong.INSTANCE.getCodec().decodeLong(phoenixTTLHWMKv.getValueArray(),
phoenixTTLHWMKv.getValueOffset(),
SortOrder.getDefault());
+ builder.setPhoenixTTLHighWaterMark(phoenixTTLHWMKv != null ?
phoenixTTLHWM :
+ oldTable != null ? oldTable.getPhoenixTTLHighWaterMark() :
MIN_PHOENIX_TTL_HWM);
// Check the cell tag to see whether the view has modified this
property
final byte[] tagPhoenixTTL = (phoenixTTLKv == null) ?
HConstants.EMPTY_BYTE_ARRAY :
CellUtil.getTagArray(phoenixTTLKv);
boolean viewModifiedPhoenixTTL = (PTableType.VIEW.equals(tableType)) &&
Bytes.contains(tagPhoenixTTL, VIEW_MODIFIED_PROPERTY_BYTES);
+ builder.setViewModifiedPhoenixTTL(oldTable != null ?
+ oldTable.hasViewModifiedPhoenixTTL() || viewModifiedPhoenixTTL :
viewModifiedPhoenixTTL);
Cell lastDDLTimestampKv = tableKeyValues[LAST_DDL_TIMESTAMP_INDEX];
Long lastDDLTimestamp = lastDDLTimestampKv == null ?
null :
PLong.INSTANCE.getCodec().decodeLong(lastDDLTimestampKv.getValueArray(),
lastDDLTimestampKv.getValueOffset(), SortOrder.getDefault());
+ builder.setLastDDLTimestamp(lastDDLTimestampKv != null ?
lastDDLTimestamp :
+ oldTable != null ? oldTable.getLastDDLTimestamp() : null);
Cell changeDetectionEnabledKv =
tableKeyValues[CHANGE_DETECTION_ENABLED_INDEX];
boolean isChangeDetectionEnabled = changeDetectionEnabledKv != null
&&
Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(changeDetectionEnabledKv.getValueArray(),
changeDetectionEnabledKv.getValueOffset(),
changeDetectionEnabledKv.getValueLength()));
+ builder.setIsChangeDetectionEnabled(changeDetectionEnabledKv != null ?
+ isChangeDetectionEnabled : oldTable != null &&
oldTable.isChangeDetectionEnabled());
Cell schemaVersionKv = tableKeyValues[SCHEMA_VERSION_INDEX];
String schemaVersion = schemaVersionKv != null ? (String)
PVarchar.INSTANCE.toObject(
schemaVersionKv.getValueArray(),
schemaVersionKv.getValueOffset(), schemaVersionKv.getValueLength())
: null;
+ builder.setSchemaVersion(schemaVersion != null ?
+ schemaVersion : oldTable != null ? oldTable.getSchemaVersion() :
null);
+
+ Cell externalSchemaIdKv = tableKeyValues[EXTERNAL_SCHEMA_ID_INDEX];
+ String externalSchemaId = externalSchemaIdKv != null ?
+ (String)
PVarchar.INSTANCE.toObject(externalSchemaIdKv.getValueArray(),
+ externalSchemaIdKv.getValueOffset(),
externalSchemaIdKv.getValueLength())
+ : null;
+ builder.setExternalSchemaId(externalSchemaId != null ?
externalSchemaId :
+ oldTable != null ? oldTable.getExternalSchemaId() : null);
// Check the cell tag to see whether the view has modified this
property
final byte[] tagUseStatsForParallelization =
(useStatsForParallelizationKv == null) ?
HConstants.EMPTY_BYTE_ARRAY :
CellUtil.getTagArray(useStatsForParallelizationKv);
boolean viewModifiedUseStatsForParallelization =
(PTableType.VIEW.equals(tableType)) &&
Bytes.contains(tagUseStatsForParallelization,
VIEW_MODIFIED_PROPERTY_BYTES);
+
builder.setViewModifiedUseStatsForParallelization(viewModifiedUseStatsForParallelization
||
+ (oldTable != null &&
oldTable.hasViewModifiedUseStatsForParallelization()));
+ boolean setPhysicalName = false;
Review comment:
Added a test to LogicalTableNameIT
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -1148,115 +1235,203 @@ private PTable getTable(RegionScanner scanner, long
clientTimeStamp, long tableT
transactionProviderKv.getValueOffset(),
SortOrder.getDefault()));
}
+ builder.setTransactionProvider(transactionProviderKv != null ||
transactionalKv != null
+ ? transactionProvider : oldTable != null ?
oldTable.getTransactionProvider() : null);
+
Cell viewTypeKv = tableKeyValues[VIEW_TYPE_INDEX];
ViewType viewType = viewTypeKv == null ? null :
ViewType.fromSerializedValue(viewTypeKv.getValueArray()[viewTypeKv.getValueOffset()]);
- PDataType viewIndexIdType = getViewIndexIdType(tableKeyValues);
+ builder.setViewType(viewType != null ? viewType : oldTable != null ?
oldTable.getViewType() : null);
+
+ PDataType viewIndexIdType = oldTable != null ?
oldTable.getviewIndexIdType() :
+ getViewIndexIdType(tableKeyValues);
+ builder.setViewIndexIdType(viewIndexIdType);
+
Long viewIndexId = getViewIndexId(tableKeyValues, viewIndexIdType);
+ builder.setViewIndexId(viewIndexId != null ? viewIndexId : oldTable !=
null ? oldTable.getViewIndexId() : null);
+
Cell indexTypeKv = tableKeyValues[INDEX_TYPE_INDEX];
IndexType indexType = indexTypeKv == null ? null :
IndexType.fromSerializedValue(indexTypeKv.getValueArray()[indexTypeKv.getValueOffset()]);
+ builder.setIndexType(indexType != null ? indexType : oldTable != null
? oldTable.getIndexType() : null);
+
Cell baseColumnCountKv = tableKeyValues[BASE_COLUMN_COUNT_INDEX];
int baseColumnCount = baseColumnCountKv == null ? 0 :
PInteger.INSTANCE.getCodec().decodeInt(baseColumnCountKv.getValueArray(),
baseColumnCountKv.getValueOffset(), SortOrder.getDefault());
+ builder.setBaseColumnCount(baseColumnCountKv != null ? baseColumnCount
: oldTable != null ? oldTable.getBaseColumnCount() : 0);
+
Cell rowKeyOrderOptimizableKv =
tableKeyValues[ROW_KEY_ORDER_OPTIMIZABLE_INDEX];
- boolean rowKeyOrderOptimizable = rowKeyOrderOptimizableKv == null ?
false :
Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(rowKeyOrderOptimizableKv.getValueArray(),
rowKeyOrderOptimizableKv.getValueOffset(),
rowKeyOrderOptimizableKv.getValueLength()));
+ boolean rowKeyOrderOptimizable = rowKeyOrderOptimizableKv != null &&
Boolean.TRUE.equals(
+
PBoolean.INSTANCE.toObject(rowKeyOrderOptimizableKv.getValueArray(),
+ rowKeyOrderOptimizableKv.getValueOffset(),
+ rowKeyOrderOptimizableKv.getValueLength()));
+ builder.setRowKeyOrderOptimizable(rowKeyOrderOptimizableKv != null ?
rowKeyOrderOptimizable :
+ oldTable != null && oldTable.rowKeyOrderOptimizable());
+
Cell updateCacheFrequencyKv =
tableKeyValues[UPDATE_CACHE_FREQUENCY_INDEX];
long updateCacheFrequency = updateCacheFrequencyKv == null ? 0 :
PLong.INSTANCE.getCodec().decodeLong(updateCacheFrequencyKv.getValueArray(),
updateCacheFrequencyKv.getValueOffset(),
SortOrder.getDefault());
+ builder.setUpdateCacheFrequency(updateCacheFrequencyKv != null ?
updateCacheFrequency : oldTable != null ? oldTable.getUpdateCacheFrequency() :
0);
// Check the cell tag to see whether the view has modified this
property
final byte[] tagUpdateCacheFreq = (updateCacheFrequencyKv == null) ?
HConstants.EMPTY_BYTE_ARRAY :
CellUtil.getTagArray(updateCacheFrequencyKv);
boolean viewModifiedUpdateCacheFrequency =
(PTableType.VIEW.equals(tableType)) &&
Bytes.contains(tagUpdateCacheFreq,
VIEW_MODIFIED_PROPERTY_BYTES);
+
builder.setViewModifiedUpdateCacheFrequency(!Bytes.equals(tagUpdateCacheFreq,
+ HConstants.EMPTY_BYTE_ARRAY) ? viewModifiedUpdateCacheFrequency :
+ oldTable != null &&
oldTable.hasViewModifiedUpdateCacheFrequency());
+
Cell indexDisableTimestampKv = tableKeyValues[INDEX_DISABLE_TIMESTAMP];
long indexDisableTimestamp = indexDisableTimestampKv == null ? 0L :
PLong.INSTANCE.getCodec().decodeLong(indexDisableTimestampKv.getValueArray(),
indexDisableTimestampKv.getValueOffset(),
SortOrder.getDefault());
+ builder.setIndexDisableTimestamp(indexDisableTimestampKv != null ?
+ indexDisableTimestamp : oldTable != null ?
oldTable.getIndexDisableTimestamp() : 0L);
+
Cell isNamespaceMappedKv = tableKeyValues[IS_NAMESPACE_MAPPED_INDEX];
- boolean isNamespaceMapped = isNamespaceMappedKv == null ? false
- :
Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(isNamespaceMappedKv.getValueArray(),
+ boolean isNamespaceMapped = isNamespaceMappedKv != null &&
Boolean.TRUE.equals(
+ PBoolean.INSTANCE.toObject(isNamespaceMappedKv.getValueArray(),
isNamespaceMappedKv.getValueOffset(),
isNamespaceMappedKv.getValueLength()));
+ builder.setNamespaceMapped(isNamespaceMappedKv != null ?
isNamespaceMapped :
+ oldTable != null && oldTable.isNamespaceMapped());
+
Cell autoPartitionSeqKv = tableKeyValues[AUTO_PARTITION_SEQ_INDEX];
String autoPartitionSeq = autoPartitionSeqKv != null ? (String)
PVarchar.INSTANCE.toObject(autoPartitionSeqKv.getValueArray(),
autoPartitionSeqKv.getValueOffset(),
autoPartitionSeqKv.getValueLength()) : null;
+ builder.setAutoPartitionSeqName(autoPartitionSeq != null
+ ? autoPartitionSeq : oldTable != null ?
oldTable.getAutoPartitionSeqName() : null);
+
Cell isAppendOnlySchemaKv = tableKeyValues[APPEND_ONLY_SCHEMA_INDEX];
- boolean isAppendOnlySchema = isAppendOnlySchemaKv == null ? false
- :
Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(isAppendOnlySchemaKv.getValueArray(),
+ boolean isAppendOnlySchema = isAppendOnlySchemaKv != null &&
Boolean.TRUE.equals(
+ PBoolean.INSTANCE.toObject(isAppendOnlySchemaKv.getValueArray(),
isAppendOnlySchemaKv.getValueOffset(),
isAppendOnlySchemaKv.getValueLength()));
+ builder.setAppendOnlySchema(isAppendOnlySchemaKv != null ?
isAppendOnlySchema :
+ oldTable != null && oldTable.isAppendOnlySchema());
+
Cell storageSchemeKv = tableKeyValues[STORAGE_SCHEME_INDEX];
//TODO: change this once we start having other values for storage
schemes
ImmutableStorageScheme storageScheme = storageSchemeKv == null ?
ImmutableStorageScheme.ONE_CELL_PER_COLUMN : ImmutableStorageScheme
.fromSerializedValue((byte)
PTinyint.INSTANCE.toObject(storageSchemeKv.getValueArray(),
storageSchemeKv.getValueOffset(),
storageSchemeKv.getValueLength()));
+ builder.setImmutableStorageScheme(storageSchemeKv != null ?
storageScheme :
+ oldTable != null ? oldTable.getImmutableStorageScheme() :
ImmutableStorageScheme.ONE_CELL_PER_COLUMN);
+
Cell encodingSchemeKv =
tableKeyValues[QUALIFIER_ENCODING_SCHEME_INDEX];
QualifierEncodingScheme encodingScheme = encodingSchemeKv == null ?
QualifierEncodingScheme.NON_ENCODED_QUALIFIERS : QualifierEncodingScheme
.fromSerializedValue((byte)
PTinyint.INSTANCE.toObject(encodingSchemeKv.getValueArray(),
encodingSchemeKv.getValueOffset(),
encodingSchemeKv.getValueLength()));
+ builder.setQualifierEncodingScheme(encodingSchemeKv != null ?
encodingScheme :
+ oldTable != null ? oldTable.getEncodingScheme() :
QualifierEncodingScheme.NON_ENCODED_QUALIFIERS);
+
Cell useStatsForParallelizationKv =
tableKeyValues[USE_STATS_FOR_PARALLELIZATION_INDEX];
- Boolean useStatsForParallelization = useStatsForParallelizationKv ==
null ? null :
Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(useStatsForParallelizationKv.getValueArray(),
useStatsForParallelizationKv.getValueOffset(),
useStatsForParallelizationKv.getValueLength()));
+ Boolean useStatsForParallelization = useStatsForParallelizationKv ==
null ? null :
+
Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(useStatsForParallelizationKv.getValueArray(),
useStatsForParallelizationKv.getValueOffset(),
useStatsForParallelizationKv.getValueLength()));
+ builder.setUseStatsForParallelization(useStatsForParallelization !=
null ?
+ useStatsForParallelization : oldTable != null ?
oldTable.useStatsForParallelization() : null);
Cell phoenixTTLKv = tableKeyValues[PHOENIX_TTL_INDEX];
long phoenixTTL = phoenixTTLKv == null ? PHOENIX_TTL_NOT_DEFINED :
PLong.INSTANCE.getCodec().decodeLong(phoenixTTLKv.getValueArray(),
phoenixTTLKv.getValueOffset(), SortOrder.getDefault());
+ builder.setPhoenixTTL(phoenixTTLKv != null ? phoenixTTL :
+ oldTable != null ? oldTable.getPhoenixTTL() :
PHOENIX_TTL_NOT_DEFINED);
Cell phoenixTTLHWMKv = tableKeyValues[PHOENIX_TTL_HWM_INDEX];
long phoenixTTLHWM = phoenixTTLHWMKv == null ? MIN_PHOENIX_TTL_HWM :
PLong.INSTANCE.getCodec().decodeLong(phoenixTTLHWMKv.getValueArray(),
phoenixTTLHWMKv.getValueOffset(),
SortOrder.getDefault());
+ builder.setPhoenixTTLHighWaterMark(phoenixTTLHWMKv != null ?
phoenixTTLHWM :
+ oldTable != null ? oldTable.getPhoenixTTLHighWaterMark() :
MIN_PHOENIX_TTL_HWM);
// Check the cell tag to see whether the view has modified this
property
final byte[] tagPhoenixTTL = (phoenixTTLKv == null) ?
HConstants.EMPTY_BYTE_ARRAY :
CellUtil.getTagArray(phoenixTTLKv);
boolean viewModifiedPhoenixTTL = (PTableType.VIEW.equals(tableType)) &&
Bytes.contains(tagPhoenixTTL, VIEW_MODIFIED_PROPERTY_BYTES);
+ builder.setViewModifiedPhoenixTTL(oldTable != null ?
+ oldTable.hasViewModifiedPhoenixTTL() || viewModifiedPhoenixTTL :
viewModifiedPhoenixTTL);
Cell lastDDLTimestampKv = tableKeyValues[LAST_DDL_TIMESTAMP_INDEX];
Long lastDDLTimestamp = lastDDLTimestampKv == null ?
null :
PLong.INSTANCE.getCodec().decodeLong(lastDDLTimestampKv.getValueArray(),
lastDDLTimestampKv.getValueOffset(), SortOrder.getDefault());
+ builder.setLastDDLTimestamp(lastDDLTimestampKv != null ?
lastDDLTimestamp :
+ oldTable != null ? oldTable.getLastDDLTimestamp() : null);
Cell changeDetectionEnabledKv =
tableKeyValues[CHANGE_DETECTION_ENABLED_INDEX];
boolean isChangeDetectionEnabled = changeDetectionEnabledKv != null
&&
Boolean.TRUE.equals(PBoolean.INSTANCE.toObject(changeDetectionEnabledKv.getValueArray(),
changeDetectionEnabledKv.getValueOffset(),
changeDetectionEnabledKv.getValueLength()));
+ builder.setIsChangeDetectionEnabled(changeDetectionEnabledKv != null ?
+ isChangeDetectionEnabled : oldTable != null &&
oldTable.isChangeDetectionEnabled());
Cell schemaVersionKv = tableKeyValues[SCHEMA_VERSION_INDEX];
String schemaVersion = schemaVersionKv != null ? (String)
PVarchar.INSTANCE.toObject(
schemaVersionKv.getValueArray(),
schemaVersionKv.getValueOffset(), schemaVersionKv.getValueLength())
: null;
+ builder.setSchemaVersion(schemaVersion != null ?
+ schemaVersion : oldTable != null ? oldTable.getSchemaVersion() :
null);
+
+ Cell externalSchemaIdKv = tableKeyValues[EXTERNAL_SCHEMA_ID_INDEX];
+ String externalSchemaId = externalSchemaIdKv != null ?
+ (String)
PVarchar.INSTANCE.toObject(externalSchemaIdKv.getValueArray(),
+ externalSchemaIdKv.getValueOffset(),
externalSchemaIdKv.getValueLength())
+ : null;
+ builder.setExternalSchemaId(externalSchemaId != null ?
externalSchemaId :
+ oldTable != null ? oldTable.getExternalSchemaId() : null);
// Check the cell tag to see whether the view has modified this
property
final byte[] tagUseStatsForParallelization =
(useStatsForParallelizationKv == null) ?
HConstants.EMPTY_BYTE_ARRAY :
CellUtil.getTagArray(useStatsForParallelizationKv);
boolean viewModifiedUseStatsForParallelization =
(PTableType.VIEW.equals(tableType)) &&
Bytes.contains(tagUseStatsForParallelization,
VIEW_MODIFIED_PROPERTY_BYTES);
+
builder.setViewModifiedUseStatsForParallelization(viewModifiedUseStatsForParallelization
||
+ (oldTable != null &&
oldTable.hasViewModifiedUseStatsForParallelization()));
+ boolean setPhysicalName = false;
List<PColumn> columns =
Lists.newArrayListWithExpectedSize(columnCount);
List<PTable> indexes = Lists.newArrayList();
List<PName> physicalTables = Lists.newArrayList();
PName parentTableName = tableType == INDEX ? dataTableName : null;
PName parentSchemaName = tableType == INDEX ? schemaName : null;
PName parentLogicalName = null;
- EncodedCQCounter cqCounter =
- (!EncodedColumnsUtil.usesEncodedColumnNames(encodingScheme) ||
tableType == PTableType.VIEW) ? PTable.EncodedCQCounter.NULL_COUNTER
- : new EncodedCQCounter();
+ EncodedCQCounter cqCounter = null;
+ if (oldTable != null) {
+ cqCounter = oldTable.getEncodedCQCounter();
+ } else {
+ cqCounter =
(!EncodedColumnsUtil.usesEncodedColumnNames(encodingScheme) || tableType ==
PTableType.VIEW) ?
+ PTable.EncodedCQCounter.NULL_COUNTER :
+ new EncodedCQCounter();
+ }
+
+ if (timeStamp == HConstants.LATEST_TIMESTAMP) {
+ timeStamp = lastDDLTimestamp != null ? lastDDLTimestamp :
clientTimeStamp;
+ }
+ builder.setTimeStamp(timeStamp);
+
+
boolean isRegularView = (tableType == PTableType.VIEW && viewType !=
ViewType.MAPPED);
- while (true) {
- results.clear();
- scanner.next(results);
- if (results.isEmpty()) {
- break;
- }
- Cell colKv = results.get(LINK_TYPE_INDEX);
+ for (List<Cell> columnCellList : allColumnCellList) {
+
+ Cell colKv = columnCellList.get(LINK_TYPE_INDEX);
int colKeyLength = colKv.getRowLength();
+
PName colName = newPName(colKv.getRowArray(), colKv.getRowOffset()
+ offset, colKeyLength - offset);
+ if (colName == null && !schemaName.getString().equals("SYSTEM")) {
+ int foo = 1;
Review comment:
Removed
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -2251,6 +2428,64 @@ public void createTable(RpcController controller,
CreateTableRequest request,
}
}
+ private void exportSchema(List<Mutation> tableMetadata, byte[] tableKey,
long clientTimestamp,
+ int clientVersion, PTable oldTable) throws
SQLException, IOException {
+ List<Cell> tableCellList =
MetaDataUtil.getTableCellsFromMutations(tableMetadata);
+
+ List<List<Cell>> allColumnsCellList =
MetaDataUtil.getColumnAndLinkCellsFromMutations(tableMetadata);
+ //getTableFromCells assumes the Cells are sorted as they would be when
reading from HBase
+ Collections.sort(tableCellList, KeyValue.COMPARATOR);
+ for (List<Cell> columnCellList : allColumnsCellList) {
+ Collections.sort(columnCellList, KeyValue.COMPARATOR);
+ }
+
+ PTable newTable = getTableFromCells(tableCellList, allColumnsCellList,
clientTimestamp,
+ clientVersion, oldTable);
+ PTable parentTable = null;
+ //if this is a view, we need to get the columns from its parent table
/ view
+ if (newTable != null && newTable.getType().equals(PTableType.VIEW)) {
+ /*
Review comment:
Removed the comment
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/schema/export/DefaultSchemaRegistryRepository.java
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.schema.export;
+
+import org.apache.hadoop.conf.Configuration;
+import org.apache.phoenix.schema.PTable;
+import org.apache.phoenix.util.EnvironmentEdgeManager;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Default in-memory implementation of SchemaRegistryRepository. Not intended
for production use
+ */
+public class DefaultSchemaRegistryRepository implements
SchemaRegistryRepository {
+ public static final String DEFAULT_SCHEMA_NAME = "default_schema";
+ public static final String DEFAULT_TENANT_ID = "global";
+
+ Map<String, String> schemaMap = new HashMap<String, String>();
+
+ @Override
+ public void init(Configuration conf) throws IOException {
+
+ }
+
+ @Override
+ public String exportSchema(SchemaWriter writer, PTable table) throws
IOException {
+ String schemaId = getSchemaId(table);
+ schemaMap.put(schemaId, writer.exportSchema(table));
+ return schemaId;
+ }
+
+ @Override
+ public String getSchemaById(String schemaId) {
+ return schemaMap.get(schemaId);
+ }
+
+ @Override
+ public String getSchemaByTable(PTable table) {
+ return schemaMap.get(getSchemaId(table));
+ }
+
+ @Override
+ public void close() throws IOException {
+ schemaMap.clear();
+ }
+
+ public static String getSchemaId(PTable table) {
+ String schemaMetadataName = getSchemaMetadataName(table);
+ String version = table.getSchemaVersion() != null ?
table.getSchemaVersion() :
+ table.getLastDDLTimestamp() != null ?
table.getLastDDLTimestamp().toString() :
+ Long.toString(EnvironmentEdgeManager.currentTimeMillis());
+
+ //tenant*schema*table*version-id
+ return String.format("%s*%s", schemaMetadataName,
+ version);
+ }
+
+ private static String getSchemaMetadataName(PTable table) {
+ String schemaGroup = getSchemaGroup(table);
+ return schemaGroup + "*" + table.getTableName().getString();
+ }
+
+ private static String getSchemaGroup(PTable table) {
+ String tenantId = (table.getTenantId() != null) ?
table.getTenantId().getString() :
+ DEFAULT_TENANT_ID;
+ String schemaName = table.getSchemaName().getString();
+ if (schemaName == null) {
+ schemaName = DEFAULT_SCHEMA_NAME;
+ }
+ return tenantId + "*" + schemaName;
Review comment:
Made * a constant
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/schema/export/SchemaRegistryRepositoryFactory.java
##########
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.phoenix.schema.export;
+
+import org.apache.hadoop.conf.Configuration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+public final class SchemaRegistryRepositoryFactory {
+ private static final Logger LOGGER =
LoggerFactory.getLogger(SchemaRegistryRepository.class);
+ private static SchemaRegistryRepository exporter;
+
+ public synchronized static SchemaRegistryRepository
getSchemaRegistryRepository(Configuration conf)
+ throws IOException {
+ if (exporter != null) {
+ return exporter;
+ }
+ try {
+ String className =
conf.get(SchemaRegistryRepository.SCHEMA_REGISTRY_IMPL_KEY);
+ if (className == null) {
+ exporter = new DefaultSchemaRegistryRepository();
Review comment:
Added the factory close method as I described
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
> Option for DDL changes to export to external schema repository
> --------------------------------------------------------------
>
> Key: PHOENIX-6227
> URL: https://issues.apache.org/jira/browse/PHOENIX-6227
> Project: Phoenix
> Issue Type: Sub-task
> Reporter: Geoffrey Jacoby
> Assignee: Geoffrey Jacoby
> Priority: Major
> Fix For: 4.17.0, 5.2.0
>
>
> When a user creates or drops a table or view, or adds/removes a column from
> one, there should be the option for Phoenix to notify an external schema
> repository. This should be a configurable plugin so that core Phoenix is not
> coupled to any particular repository implementation.
> This will also store a schema id generated by the external schema registry in
> a new field in System.Catalog so that a future JIRA can switch to using the
> schema id in change detection WAL annotations. Because of this this JIRA will
> not be able to be backported to 5.1.x or 4.16.x
--
This message was sent by Atlassian Jira
(v8.3.4#803005)