Skip to content

Commit

Permalink
Revert "Add a builder for IcebergTableHandle"
Browse files Browse the repository at this point in the history
This reverts commit 34efd53.
  • Loading branch information
raunaqmorarka committed Dec 10, 2022
1 parent dd27aa7 commit a5770e5
Show file tree
Hide file tree
Showing 6 changed files with 288 additions and 324 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,24 @@ public IcebergTableHandle getTableHandle(

Map<String, String> tableProperties = table.properties();
String nameMappingJson = tableProperties.get(TableProperties.DEFAULT_NAME_MAPPING);
return IcebergTableHandle.builder()
.withSchemaName(tableName.getSchemaName())
.withTableName(name.getTableName())
.withTableType(name.getTableType())
.withSnapshotId(tableSnapshotId)
.withTableSchemaJson(SchemaParser.toJson(tableSchema))
.withPartitionSpecJson(partitionSpec.map(PartitionSpecParser::toJson))
.withFormatVersion(table.operations().current().formatVersion())
.withNameMappingJson(Optional.ofNullable(nameMappingJson))
.withTableLocation(table.location())
.withStorageProperties(table.properties())
.build();
return new IcebergTableHandle(
tableName.getSchemaName(),
name.getTableName(),
name.getTableType(),
tableSnapshotId,
SchemaParser.toJson(tableSchema),
partitionSpec.map(PartitionSpecParser::toJson),
table.operations().current().formatVersion(),
TupleDomain.all(),
TupleDomain.all(),
ImmutableSet.of(),
Optional.ofNullable(nameMappingJson),
table.location(),
table.properties(),
NO_RETRIES,
ImmutableList.of(),
false,
Optional.empty());
}

private static long getSnapshotIdFromVersion(Table table, ConnectorTableVersion version)
Expand Down Expand Up @@ -1076,10 +1082,7 @@ private BeginTableExecuteResult<ConnectorTableExecuteHandle, ConnectorTableHandl

return new BeginTableExecuteResult<>(
executeHandle,
IcebergTableHandle.buildFrom(table)
.withRecordScannedFiles(true)
.withMaxScannedFileSize(Optional.of(optimizeHandle.getMaxScannedFileSize()))
.build());
table.forOptimize(true, optimizeHandle.getMaxScannedFileSize()));
}

@Override
Expand Down Expand Up @@ -1690,9 +1693,7 @@ public ConnectorTableHandle beginDelete(ConnectorSession session, ConnectorTable
validateNotPartitionedByNestedField(icebergTable.schema(), icebergTable.spec());

beginTransaction(icebergTable);
return IcebergTableHandle.buildFrom(table)
.withRetryMode(retryMode)
.build();
return table.withRetryMode(retryMode);
}

@Override
Expand All @@ -1718,12 +1719,10 @@ public ConnectorTableHandle beginUpdate(ConnectorSession session, ConnectorTable
validateNotPartitionedByNestedField(icebergTable.schema(), icebergTable.spec());

beginTransaction(icebergTable);
return IcebergTableHandle.buildFrom(table)
.withRetryMode(retryMode)
return table.withRetryMode(retryMode)
.withUpdatedColumns(updatedColumns.stream()
.map(IcebergColumnHandle.class::cast)
.collect(toImmutableList()))
.build();
.collect(toImmutableList()));
}

@Override
Expand Down Expand Up @@ -1793,9 +1792,7 @@ public ConnectorMergeTableHandle beginMerge(ConnectorSession session, ConnectorT

beginTransaction(icebergTable);

IcebergTableHandle newTableHandle = IcebergTableHandle.buildFrom(table)
.withRetryMode(retryMode)
.build();
IcebergTableHandle newTableHandle = table.withRetryMode(retryMode);
IcebergWritableTableHandle insertHandle = newWritableTableHandle(table.getSchemaTableName(), icebergTable, retryMode);

return new IcebergMergeTableHandle(newTableHandle, insertHandle);
Expand Down Expand Up @@ -2117,11 +2114,26 @@ else if (isMetadataColumnId(columnHandle.getId())) {
&& newUnenforcedConstraint.equals(table.getUnenforcedPredicate())) {
return Optional.empty();
}

return Optional.of(new ConstraintApplicationResult<>(
IcebergTableHandle.buildFrom(table)
.withUnenforcedPredicate(newUnenforcedConstraint)
.withEnforcedPredicate(newEnforcedConstraint)
.build(),
new IcebergTableHandle(
table.getSchemaName(),
table.getTableName(),
table.getTableType(),
table.getSnapshotId(),
table.getTableSchemaJson(),
table.getPartitionSpecJson(),
table.getFormatVersion(),
newUnenforcedConstraint,
newEnforcedConstraint,
table.getProjectedColumns(),
table.getNameMappingJson(),
table.getTableLocation(),
table.getStorageProperties(),
table.getRetryMode(),
table.getUpdatedColumns(),
table.isRecordScannedFiles(),
table.getMaxScannedFileSize()),
remainingConstraint.transformKeys(ColumnHandle.class::cast),
extractionResult.remainingExpression(),
false));
Expand Down Expand Up @@ -2175,9 +2187,7 @@ public Optional<ProjectionApplicationResult<ConnectorTableHandle>> applyProjecti
.collect(toImmutableList());

return Optional.of(new ProjectionApplicationResult<>(
IcebergTableHandle.buildFrom(icebergTableHandle)
.withProjectedColumns(projectedColumns)
.build(),
icebergTableHandle.withProjectedColumns(projectedColumns),
projections,
assignmentsList,
false));
Expand Down Expand Up @@ -2211,9 +2221,7 @@ public Optional<ProjectionApplicationResult<ConnectorTableHandle>> applyProjecti

List<Assignment> outputAssignments = ImmutableList.copyOf(newAssignments.values());
return Optional.of(new ProjectionApplicationResult<>(
IcebergTableHandle.buildFrom(icebergTableHandle)
.withProjectedColumns(projectedColumnsBuilder.build())
.build(),
icebergTableHandle.withProjectedColumns(projectedColumnsBuilder.build()),
newProjections,
outputAssignments,
false));
Expand Down Expand Up @@ -2257,10 +2265,24 @@ public TableStatistics getTableStatistics(ConnectorSession session, ConnectorTab
checkArgument(originalHandle.getMaxScannedFileSize().isEmpty(), "Unexpected max scanned file size set");

return tableStatisticsCache.computeIfAbsent(
IcebergTableHandle.buildFrom(originalHandle)
.withProjectedColumns(ImmutableSet.of()) // projectedColumns don't affect stats
.withRetryMode(NO_RETRIES) // retry mode doesn't affect stats
.build(),
new IcebergTableHandle(
originalHandle.getSchemaName(),
originalHandle.getTableName(),
originalHandle.getTableType(),
originalHandle.getSnapshotId(),
originalHandle.getTableSchemaJson(),
originalHandle.getPartitionSpecJson(),
originalHandle.getFormatVersion(),
originalHandle.getUnenforcedPredicate(),
originalHandle.getEnforcedPredicate(),
ImmutableSet.of(), // projectedColumns don't affect stats
originalHandle.getNameMappingJson(),
originalHandle.getTableLocation(),
originalHandle.getStorageProperties(),
NO_RETRIES, // retry mode doesn't affect stats
originalHandle.getUpdatedColumns(),
originalHandle.isRecordScannedFiles(),
originalHandle.getMaxScannedFileSize()),
handle -> {
Table icebergTable = catalog.loadTable(session, handle.getSchemaTableName());
return TableStatisticsMaker.getTableStatistics(typeManager, session, handle, icebergTable);
Expand Down
Loading

0 comments on commit a5770e5

Please sign in to comment.