ChinmaySKulkarni commented on a change in pull request #541: PHOENIX-4893 Move
parent column combining logic of view and view inde…
URL: https://github.com/apache/phoenix/pull/541#discussion_r305165444
##########
File path:
phoenix-core/src/main/java/org/apache/phoenix/coprocessor/MetaDataEndpointImpl.java
##########
@@ -3777,195 +2812,74 @@ public int compare(byte[] o1, byte[] o2) {
iterator.remove();
}
}
- if(functionsAvailable.size() == numFunctions) return
functionsAvailable;
+ if (functionsAvailable.size() == numFunctions) return
functionsAvailable;
// Query for the latest table first, since it's not cached
List<PFunction> buildFunctions =
buildFunctions(keys, region, clientTimeStamp, false,
- Collections.<Mutation> emptyList());
- if(buildFunctions == null || buildFunctions.isEmpty()) {
+ Collections.<Mutation>emptyList());
+ if (buildFunctions == null || buildFunctions.isEmpty()) {
return null;
}
functionsAvailable.addAll(buildFunctions);
- if(functionsAvailable.size() == numFunctions) return
functionsAvailable;
+ if (functionsAvailable.size() == numFunctions) return
functionsAvailable;
return null;
} finally {
- releaseRowLocks(region,rowLocks);
+ releaseRowLocks(region, rowLocks);
}
}
-
- private PColumn getColumn(int pkCount, byte[][] rowKeyMetaData, PTable
table) throws ColumnFamilyNotFoundException, ColumnNotFoundException {
- PColumn col = null;
- if (pkCount > FAMILY_NAME_INDEX
- &&
rowKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX].length > 0) {
- PColumnFamily family =
-
table.getColumnFamily(rowKeyMetaData[PhoenixDatabaseMetaData.FAMILY_NAME_INDEX]);
- col =
-
family.getPColumnForColumnNameBytes(rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX]);
- } else if (pkCount > COLUMN_NAME_INDEX
- &&
rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX].length > 0) {
- col = table.getPKColumn(new
String(rowKeyMetaData[PhoenixDatabaseMetaData.COLUMN_NAME_INDEX]));
- }
- return col;
- }
@Override
public void dropColumn(RpcController controller, final DropColumnRequest
request,
- RpcCallback<MetaDataResponse> done) {
+ RpcCallback<MetaDataResponse> done) {
List<Mutation> tableMetaData = null;
final List<byte[]> tableNamesToDelete = Lists.newArrayList();
final List<SharedTableState> sharedTablesToDelete =
Lists.newArrayList();
try {
tableMetaData = ProtobufUtil.getMutations(request);
- MetaDataMutationResult result =
mutateColumn(MutatateColumnType.DROP_COLUMN, tableMetaData, new ColumnMutator()
{
- @Override
- public MetaDataMutationResult updateMutation(PTable table,
byte[][] rowKeyMetaData,
- List<Mutation> tableMetaData, Region region,
- List<ImmutableBytesPtr> invalidateList, List<RowLock>
locks, long clientTimeStamp)
- throws IOException, SQLException {
-
- byte[] tenantId = rowKeyMetaData[TENANT_ID_INDEX];
- byte[] schemaName = rowKeyMetaData[SCHEMA_NAME_INDEX];
- byte[] tableName = rowKeyMetaData[TABLE_NAME_INDEX];
- boolean isView = table.getType() == PTableType.VIEW;
- boolean deletePKColumn = false;
-
getCoprocessorHost().preAlterTable(Bytes.toString(tenantId),
- SchemaUtil.getTableName(schemaName, tableName),
-
TableName.valueOf(table.getPhysicalName().getBytes()),
- getParentPhysicalTableName(table),table.getType());
-
- List<Mutation> additionalTableMetaData =
Lists.newArrayList();
- PTableType type = table.getType();
- if (type == PTableType.TABLE) {
- TableViewFinderResult childViewsResult = new
TableViewFinderResult();
- findAllChildViews(tenantId,
table.getSchemaName().getBytes(), table.getTableName().getBytes(),
childViewsResult);
- if (childViewsResult.hasLinks()) {
- MetaDataMutationResult mutationResult =
- dropViewIndexes(region, table,
- locks, tableMetaData,
additionalTableMetaData,
- schemaName, tableName, invalidateList,
- clientTimeStamp, childViewsResult,
tableNamesToDelete, sharedTablesToDelete, request.getClientVersion());
- // return if we were not able to drop view indexes
that need this column successfully
- if (mutationResult != null) return mutationResult;
- }
- }
- ListIterator<Mutation> iterator =
tableMetaData.listIterator();
- while (iterator.hasNext()) {
- Mutation mutation = iterator.next();
- byte[] key = mutation.getRow();
- int pkCount = getVarChars(key, rowKeyMetaData);
- if (isView && mutation instanceof Put) {
- PColumn column = getColumn(pkCount,
rowKeyMetaData, table);
- if (column == null)
- continue;
- // ignore any puts that modify the ordinal
positions of columns
- iterator.remove();
- }
- else if (mutation instanceof Delete) {
- if (pkCount > COLUMN_NAME_INDEX
- && Bytes.compareTo(schemaName,
rowKeyMetaData[SCHEMA_NAME_INDEX]) == 0
- && Bytes.compareTo(tableName,
rowKeyMetaData[TABLE_NAME_INDEX]) == 0) {
- PColumn columnToDelete = null;
- try {
- columnToDelete = getColumn(pkCount,
rowKeyMetaData, table);
- if (columnToDelete == null)
- continue;
- deletePKColumn =
columnToDelete.getFamilyName() == null;
- if (isView) {
- // if we are dropping a derived column
add it to the excluded column list
- if (columnToDelete.isDerived()) {
- mutation = MetaDataUtil
-
.cloneDeleteToPutAndAddColumn((Delete) mutation, TABLE_FAMILY_BYTES,
LINK_TYPE_BYTES, LinkType.EXCLUDED_COLUMN.getSerializedValueAsByteArray());
- iterator.set(mutation);
- }
-
- if (table.getBaseColumnCount() !=
DIVERGED_VIEW_BASE_COLUMN_COUNT
- && columnToDelete.isDerived()) {
- /*
- * If the column being dropped is
inherited from the base table, then the
- * view is about to diverge itself
from the base table. The consequence of
- * this divergence is that that
any further meta-data changes made to the
- * base table will not be
propagated to the hierarchy of views where this
- * view is the root.
- */
- byte[] viewKey =
SchemaUtil.getTableKey(tenantId, schemaName, tableName);
- Put updateBaseColumnCountPut = new
Put(viewKey);
- byte[] baseColumnCountPtr = new
byte[PInteger.INSTANCE.getByteSize()];
-
PInteger.INSTANCE.getCodec().encodeInt(DIVERGED_VIEW_BASE_COLUMN_COUNT,
- baseColumnCountPtr, 0);
-
updateBaseColumnCountPut.addColumn(PhoenixDatabaseMetaData.TABLE_FAMILY_BYTES,
-
PhoenixDatabaseMetaData.BASE_COLUMN_COUNT_BYTES, clientTimeStamp,
- baseColumnCountPtr);
-
additionalTableMetaData.add(updateBaseColumnCountPut);
- }
- }
- if (columnToDelete.isViewReferenced()) {
// Disallow deletion of column referenced in WHERE clause of view
- return new
MetaDataMutationResult(MutationCode.UNALLOWED_TABLE_MUTATION,
EnvironmentEdgeManager.currentTimeMillis(), table, columnToDelete);
- }
- // drop any indexes that need the column
that is going to be dropped
- MetaDataMutationResult result =
dropIndexes(table, region, invalidateList, locks,
- clientTimeStamp, schemaName, tableName,
- additionalTableMetaData,
columnToDelete,
- tableNamesToDelete,
sharedTablesToDelete, request.getClientVersion(), null);
- if (result != null) {
- return result;
- }
- } catch (ColumnFamilyNotFoundException e) {
- return new MetaDataMutationResult(
- MutationCode.COLUMN_NOT_FOUND,
EnvironmentEdgeManager
- .currentTimeMillis(), table,
columnToDelete);
- } catch (ColumnNotFoundException e) {
- return new MetaDataMutationResult(
- MutationCode.COLUMN_NOT_FOUND,
EnvironmentEdgeManager
- .currentTimeMillis(), table,
columnToDelete);
- }
- }
- }
-
- }
- if (deletePKColumn) {
- if (table.getPKColumns().size() == 1) {
- return new
MetaDataMutationResult(MutationCode.NO_PK_COLUMNS,
-
EnvironmentEdgeManager.currentTimeMillis(), null);
- }
- }
- tableMetaData.addAll(additionalTableMetaData);
- long currentTime =
MetaDataUtil.getClientTimeStamp(tableMetaData);
- return new
MetaDataMutationResult(MutationCode.TABLE_ALREADY_EXISTS, currentTime, null,
tableNamesToDelete, sharedTablesToDelete);
- }
- }, request.getClientVersion());
+ PTable parentTable = request.hasParentTable() ?
PTableImpl.createFromProto(request.getParentTable()) : null;
+ MetaDataMutationResult result = mutateColumn(tableMetaData, new
DropColumnMutator(env.getConfiguration()),
+ request.getClientVersion(), parentTable);
if (result != null) {
done.run(MetaDataMutationResult.toProto(result));
}
} catch (Throwable e) {
LOGGER.error("Drop column failed: ", e);
ProtobufUtil.setControllerException(controller,
- ServerUtil.createIOException("Error when dropping column: ",
e));
+ ServerUtil.createIOException("Error when dropping column:
", e));
}
}
- private MetaDataMutationResult dropIndexes(PTable table, Region region,
List<ImmutableBytesPtr> invalidateList,
- List<RowLock> locks, long clientTimeStamp, byte[] schemaName,
- byte[] tableName, List<Mutation> additionalTableMetaData, PColumn
columnToDelete,
- List<byte[]> tableNamesToDelete, List<SharedTableState>
sharedTablesToDelete, int clientVersion, PTable basePhysicalTable)
+ private MetaDataMutationResult dropIndexes(RegionCoprocessorEnvironment
env, PTable table,
+ List<ImmutableBytesPtr>
invalidateList, List<RowLock> locks,
+ long clientTimeStamp,
List<Mutation> tableMetaData,
+ PColumn columnToDelete,
List<byte[]> tableNamesToDelete,
+ List<SharedTableState>
sharedTablesToDelete, int clientVersion)
throws IOException, SQLException {
// Look for columnToDelete in any indexes. If found as PK column, get
lock and drop the
// index and then invalidate it
// Covered columns are deleted from the index by the client
+ Region region = env.getRegion();
PhoenixConnection connection = null;
try {
connection = table.getIndexes().isEmpty() ? null :
QueryUtil.getConnectionOnServer(
- env.getConfiguration()).unwrap(PhoenixConnection.class);
+ env.getConfiguration()).unwrap(PhoenixConnection.class);
} catch (ClassNotFoundException e) {
}
for (PTable index : table.getIndexes()) {
+ // ignore any indexes dervied from ancestors
Review comment:
nit: typo "dervied"
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services