From 34efd535573f89928405e4868b6eb23457b8cd58 Mon Sep 17 00:00:00 2001 From: Assaf Bern Date: Wed, 30 Nov 2022 14:52:17 +0200 Subject: [PATCH] Add a builder for IcebergTableHandle --- .../trino/plugin/iceberg/IcebergMetadata.java | 102 +++--- .../plugin/iceberg/IcebergTableHandle.java | 306 ++++++++++++------ ...stIcebergNodeLocalDynamicSplitPruning.java | 30 +- .../TestIcebergProjectionPushdownPlans.java | 8 +- .../iceberg/TestIcebergSplitSource.java | 30 +- ...TestConnectorPushdownRulesWithIceberg.java | 136 ++++---- 6 files changed, 324 insertions(+), 288 deletions(-) diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java index e12f937af007..49b352865ce2 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergMetadata.java @@ -369,24 +369,18 @@ public IcebergTableHandle getTableHandle( Map tableProperties = table.properties(); String nameMappingJson = tableProperties.get(TableProperties.DEFAULT_NAME_MAPPING); - 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()); + 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(); } private static long getSnapshotIdFromVersion(Table table, ConnectorTableVersion version) @@ -1082,7 +1076,10 @@ private BeginTableExecuteResult( executeHandle, - table.forOptimize(true, optimizeHandle.getMaxScannedFileSize())); + IcebergTableHandle.buildFrom(table) + .withRecordScannedFiles(true) + .withMaxScannedFileSize(Optional.of(optimizeHandle.getMaxScannedFileSize())) + .build()); } @Override @@ -1693,7 +1690,9 @@ public ConnectorTableHandle beginDelete(ConnectorSession session, ConnectorTable validateNotPartitionedByNestedField(icebergTable.schema(), icebergTable.spec()); beginTransaction(icebergTable); - return table.withRetryMode(retryMode); + return IcebergTableHandle.buildFrom(table) + .withRetryMode(retryMode) + .build(); } @Override @@ -1719,10 +1718,12 @@ public ConnectorTableHandle beginUpdate(ConnectorSession session, ConnectorTable validateNotPartitionedByNestedField(icebergTable.schema(), icebergTable.spec()); beginTransaction(icebergTable); - return table.withRetryMode(retryMode) + return IcebergTableHandle.buildFrom(table) + .withRetryMode(retryMode) .withUpdatedColumns(updatedColumns.stream() .map(IcebergColumnHandle.class::cast) - .collect(toImmutableList())); + .collect(toImmutableList())) + .build(); } @Override @@ -1792,7 +1793,9 @@ public ConnectorMergeTableHandle beginMerge(ConnectorSession session, ConnectorT beginTransaction(icebergTable); - IcebergTableHandle newTableHandle = table.withRetryMode(retryMode); + IcebergTableHandle newTableHandle = IcebergTableHandle.buildFrom(table) + .withRetryMode(retryMode) + .build(); IcebergWritableTableHandle insertHandle = newWritableTableHandle(table.getSchemaTableName(), icebergTable, retryMode); return new IcebergMergeTableHandle(newTableHandle, insertHandle); @@ -2114,26 +2117,11 @@ else if (isMetadataColumnId(columnHandle.getId())) { && newUnenforcedConstraint.equals(table.getUnenforcedPredicate())) { return Optional.empty(); } - return Optional.of(new ConstraintApplicationResult<>( - 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()), + IcebergTableHandle.buildFrom(table) + .withUnenforcedPredicate(newUnenforcedConstraint) + .withEnforcedPredicate(newEnforcedConstraint) + .build(), remainingConstraint.transformKeys(ColumnHandle.class::cast), extractionResult.remainingExpression(), false)); @@ -2187,7 +2175,9 @@ public Optional> applyProjecti .collect(toImmutableList()); return Optional.of(new ProjectionApplicationResult<>( - icebergTableHandle.withProjectedColumns(projectedColumns), + IcebergTableHandle.buildFrom(icebergTableHandle) + .withProjectedColumns(projectedColumns) + .build(), projections, assignmentsList, false)); @@ -2221,7 +2211,9 @@ public Optional> applyProjecti List outputAssignments = ImmutableList.copyOf(newAssignments.values()); return Optional.of(new ProjectionApplicationResult<>( - icebergTableHandle.withProjectedColumns(projectedColumnsBuilder.build()), + IcebergTableHandle.buildFrom(icebergTableHandle) + .withProjectedColumns(projectedColumnsBuilder.build()) + .build(), newProjections, outputAssignments, false)); @@ -2265,24 +2257,10 @@ public TableStatistics getTableStatistics(ConnectorSession session, ConnectorTab checkArgument(originalHandle.getMaxScannedFileSize().isEmpty(), "Unexpected max scanned file size set"); return tableStatisticsCache.computeIfAbsent( - 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()), + IcebergTableHandle.buildFrom(originalHandle) + .withProjectedColumns(ImmutableSet.of()) // projectedColumns don't affect stats + .withRetryMode(NO_RETRIES) // retry mode doesn't affect stats + .build(), handle -> { Table icebergTable = catalog.loadTable(session, handle.getSchemaTableName()); return TableStatisticsMaker.getTableStatistics(typeManager, session, handle, icebergTable); diff --git a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergTableHandle.java b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergTableHandle.java index 8cd1d3f58299..fe89301c8b41 100644 --- a/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergTableHandle.java +++ b/plugin/trino-iceberg/src/main/java/io/trino/plugin/iceberg/IcebergTableHandle.java @@ -32,6 +32,7 @@ import java.util.Optional; import java.util.Set; +import static java.util.Collections.emptyMap; import static java.util.Objects.requireNonNull; import static java.util.stream.Collectors.joining; @@ -84,27 +85,26 @@ public static IcebergTableHandle fromJsonForDeserializationOnly( @JsonProperty("retryMode") RetryMode retryMode, @JsonProperty("updatedColumns") List updatedColumns) { - return new IcebergTableHandle( - schemaName, - tableName, - tableType, - snapshotId, - tableSchemaJson, - partitionSpecJson, - formatVersion, - unenforcedPredicate, - enforcedPredicate, - projectedColumns, - nameMappingJson, - tableLocation, - storageProperties, - retryMode, - updatedColumns, - false, - Optional.empty()); + return builder() + .withSchemaName(schemaName) + .withTableName(tableName) + .withTableType(tableType) + .withSnapshotId(snapshotId) + .withTableSchemaJson(tableSchemaJson) + .withPartitionSpecJson(partitionSpecJson) + .withFormatVersion(formatVersion) + .withUnenforcedPredicate(unenforcedPredicate) + .withEnforcedPredicate(enforcedPredicate) + .withProjectedColumns(projectedColumns) + .withNameMappingJson(nameMappingJson) + .withTableLocation(tableLocation) + .withStorageProperties(storageProperties) + .withRetryMode(retryMode) + .withUpdatedColumns(updatedColumns) + .build(); } - public IcebergTableHandle( + private IcebergTableHandle( String schemaName, String tableName, TableType tableType, @@ -254,94 +254,6 @@ public SchemaTableName getSchemaTableNameWithType() return new SchemaTableName(schemaName, tableName + "$" + tableType.name().toLowerCase(Locale.ROOT)); } - public IcebergTableHandle withProjectedColumns(Set projectedColumns) - { - return new IcebergTableHandle( - schemaName, - tableName, - tableType, - snapshotId, - tableSchemaJson, - partitionSpecJson, - formatVersion, - unenforcedPredicate, - enforcedPredicate, - projectedColumns, - nameMappingJson, - tableLocation, - storageProperties, - retryMode, - updatedColumns, - recordScannedFiles, - maxScannedFileSize); - } - - public IcebergTableHandle withRetryMode(RetryMode retryMode) - { - return new IcebergTableHandle( - schemaName, - tableName, - tableType, - snapshotId, - tableSchemaJson, - partitionSpecJson, - formatVersion, - unenforcedPredicate, - enforcedPredicate, - projectedColumns, - nameMappingJson, - tableLocation, - storageProperties, - retryMode, - updatedColumns, - recordScannedFiles, - maxScannedFileSize); - } - - public IcebergTableHandle withUpdatedColumns(List updatedColumns) - { - return new IcebergTableHandle( - schemaName, - tableName, - tableType, - snapshotId, - tableSchemaJson, - partitionSpecJson, - formatVersion, - unenforcedPredicate, - enforcedPredicate, - projectedColumns, - nameMappingJson, - tableLocation, - storageProperties, - retryMode, - updatedColumns, - recordScannedFiles, - maxScannedFileSize); - } - - public IcebergTableHandle forOptimize(boolean recordScannedFiles, DataSize maxScannedFileSize) - { - return new IcebergTableHandle( - schemaName, - tableName, - tableType, - snapshotId, - tableSchemaJson, - partitionSpecJson, - formatVersion, - unenforcedPredicate, - enforcedPredicate, - projectedColumns, - nameMappingJson, - tableLocation, - storageProperties, - retryMode, - updatedColumns, - recordScannedFiles, - Optional.of(maxScannedFileSize)); - } - @Override public boolean equals(Object o) { @@ -395,4 +307,184 @@ else if (!enforcedPredicate.isAll()) { } return builder.toString(); } + + public static Builder builder() + { + return new Builder(); + } + + public static Builder buildFrom(IcebergTableHandle table) + { + return new Builder(table); + } + + public static class Builder + { + private String schemaName; + private String tableName; + private TableType tableType; + private Optional snapshotId = Optional.empty(); + private String tableSchemaJson; + private Optional partitionSpecJson = Optional.empty(); + private int formatVersion; + private String tableLocation; + private Map storageProperties = emptyMap(); + private RetryMode retryMode = RetryMode.NO_RETRIES; + private List updatedColumns = ImmutableList.of(); + private TupleDomain unenforcedPredicate = TupleDomain.all(); + private TupleDomain enforcedPredicate = TupleDomain.all(); + private Set projectedColumns = ImmutableSet.of(); + private Optional nameMappingJson = Optional.empty(); + private boolean recordScannedFiles; + private Optional maxScannedFileSize = Optional.empty(); + + private Builder() + { + } + + private Builder(IcebergTableHandle table) + { + this.schemaName = table.schemaName; + this.tableName = table.tableName; + this.tableType = table.tableType; + this.snapshotId = table.snapshotId; + this.tableSchemaJson = table.tableSchemaJson; + this.partitionSpecJson = table.partitionSpecJson; + this.formatVersion = table.formatVersion; + this.tableLocation = table.tableLocation; + this.storageProperties = table.storageProperties; + this.retryMode = table.retryMode; + this.updatedColumns = table.updatedColumns; + this.unenforcedPredicate = table.unenforcedPredicate; + this.enforcedPredicate = table.enforcedPredicate; + this.projectedColumns = table.projectedColumns; + this.nameMappingJson = table.nameMappingJson; + this.recordScannedFiles = table.recordScannedFiles; + this.maxScannedFileSize = table.maxScannedFileSize; + } + + public Builder withSchemaName(String schemaName) + { + this.schemaName = schemaName; + return this; + } + + public Builder withTableName(String tableName) + { + this.tableName = tableName; + return this; + } + + public Builder withTableType(TableType tableType) + { + this.tableType = tableType; + return this; + } + + public Builder withSnapshotId(Optional snapshotId) + { + this.snapshotId = snapshotId; + return this; + } + + public Builder withTableSchemaJson(String tableSchemaJson) + { + this.tableSchemaJson = tableSchemaJson; + return this; + } + + public Builder withPartitionSpecJson(Optional partitionSpecJson) + { + this.partitionSpecJson = partitionSpecJson; + return this; + } + + public Builder withFormatVersion(int formatVersion) + { + this.formatVersion = formatVersion; + return this; + } + + public Builder withTableLocation(String tableLocation) + { + this.tableLocation = tableLocation; + return this; + } + + public Builder withStorageProperties(Map storageProperties) + { + this.storageProperties = storageProperties; + return this; + } + + public Builder withRetryMode(RetryMode retryMode) + { + this.retryMode = retryMode; + return this; + } + + public Builder withUpdatedColumns(List updatedColumns) + { + this.updatedColumns = updatedColumns; + return this; + } + + public Builder withUnenforcedPredicate(TupleDomain unenforcedPredicate) + { + this.unenforcedPredicate = unenforcedPredicate; + return this; + } + + public Builder withEnforcedPredicate(TupleDomain enforcedPredicate) + { + this.enforcedPredicate = enforcedPredicate; + return this; + } + + public Builder withProjectedColumns(Set projectedColumns) + { + this.projectedColumns = projectedColumns; + return this; + } + + public Builder withNameMappingJson(Optional nameMappingJson) + { + this.nameMappingJson = nameMappingJson; + return this; + } + + public Builder withRecordScannedFiles(boolean recordScannedFiles) + { + this.recordScannedFiles = recordScannedFiles; + return this; + } + + public Builder withMaxScannedFileSize(Optional maxScannedFileSize) + { + this.maxScannedFileSize = maxScannedFileSize; + return this; + } + + public IcebergTableHandle build() + { + return new IcebergTableHandle( + schemaName, + tableName, + tableType, + snapshotId, + tableSchemaJson, + partitionSpecJson, + formatVersion, + unenforcedPredicate, + enforcedPredicate, + projectedColumns, + nameMappingJson, + tableLocation, + storageProperties, + retryMode, + updatedColumns, + recordScannedFiles, + maxScannedFileSize); + } + } } diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergNodeLocalDynamicSplitPruning.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergNodeLocalDynamicSplitPruning.java index 7b45bd5dad50..e818e6cddcce 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergNodeLocalDynamicSplitPruning.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergNodeLocalDynamicSplitPruning.java @@ -42,7 +42,6 @@ import io.trino.spi.connector.ColumnHandle; import io.trino.spi.connector.ConnectorPageSource; import io.trino.spi.connector.DynamicFilter; -import io.trino.spi.connector.RetryMode; import io.trino.spi.predicate.Domain; import io.trino.spi.predicate.TupleDomain; import io.trino.spi.type.Type; @@ -179,24 +178,17 @@ private static ConnectorPageSource createTestingPageSource(HiveTransactionHandle String tablePath = filePath.substring(0, filePath.lastIndexOf("/")); TableHandle tableHandle = new TableHandle( TEST_CATALOG_HANDLE, - new IcebergTableHandle( - SCHEMA_NAME, - TABLE_NAME, - TableType.DATA, - Optional.empty(), - SchemaParser.toJson(TABLE_SCHEMA), - Optional.of(PartitionSpecParser.toJson(PartitionSpec.unpartitioned())), - 2, - TupleDomain.withColumnDomains(ImmutableMap.of(KEY_ICEBERG_COLUMN_HANDLE, Domain.singleValue(INTEGER, (long) KEY_COLUMN_VALUE))), - TupleDomain.all(), - ImmutableSet.of(KEY_ICEBERG_COLUMN_HANDLE), - Optional.empty(), - tablePath, - ImmutableMap.of(), - RetryMode.NO_RETRIES, - ImmutableList.of(), - false, - Optional.empty()), + IcebergTableHandle.builder() + .withSchemaName(SCHEMA_NAME) + .withTableName(TABLE_NAME) + .withTableType(TableType.DATA) + .withTableSchemaJson(SchemaParser.toJson(TABLE_SCHEMA)) + .withPartitionSpecJson(Optional.of(PartitionSpecParser.toJson(PartitionSpec.unpartitioned()))) + .withFormatVersion(2) + .withUnenforcedPredicate(TupleDomain.withColumnDomains(ImmutableMap.of(KEY_ICEBERG_COLUMN_HANDLE, Domain.singleValue(INTEGER, (long) KEY_COLUMN_VALUE)))) + .withProjectedColumns(ImmutableSet.of(KEY_ICEBERG_COLUMN_HANDLE)) + .withTableLocation(tablePath) + .build(), transaction); FileFormatDataSourceStats stats = new FileFormatDataSourceStats(); diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergProjectionPushdownPlans.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergProjectionPushdownPlans.java index 59eefbdb779b..0d86d5bc4c58 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergProjectionPushdownPlans.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergProjectionPushdownPlans.java @@ -166,7 +166,9 @@ public void testDereferencePushdown() assertPlan( "SELECT col0.x expr_x, col0.y expr_y FROM " + testTable, any(tableScan( - equalTo(((IcebergTableHandle) tableHandle.get().getConnectorHandle()).withProjectedColumns(Set.of(columnX, columnY))), + equalTo(IcebergTableHandle.buildFrom((IcebergTableHandle) tableHandle.get().getConnectorHandle()) + .withProjectedColumns(Set.of(columnX, columnY)) + .build()), TupleDomain.all(), ImmutableMap.of("col0#x", equalTo(columnX), "col0#y", equalTo(columnY))))); @@ -232,7 +234,9 @@ public void testDereferencePushdown() .right( anyTree( tableScan( - equalTo(((IcebergTableHandle) tableHandle.get().getConnectorHandle()).withProjectedColumns(Set.of(column1Handle))), + equalTo(IcebergTableHandle.buildFrom((IcebergTableHandle) tableHandle.get().getConnectorHandle()) + .withProjectedColumns(Set.of(column1Handle)) + .build()), TupleDomain.all(), ImmutableMap.of("s_expr_1", equalTo(column1Handle))))))))); } diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergSplitSource.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergSplitSource.java index 5c23ca01896c..ca8b9d1134b9 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergSplitSource.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/TestIcebergSplitSource.java @@ -60,8 +60,8 @@ import static io.trino.plugin.hive.HiveTestUtils.HDFS_ENVIRONMENT; import static io.trino.plugin.hive.metastore.cache.CachingHiveMetastore.memoizeMetastore; import static io.trino.plugin.hive.metastore.file.FileHiveMetastore.createTestingFileHiveMetastore; +import static io.trino.plugin.iceberg.TableType.DATA; import static io.trino.spi.connector.Constraint.alwaysTrue; -import static io.trino.spi.connector.RetryMode.NO_RETRIES; import static io.trino.spi.type.BigintType.BIGINT; import static io.trino.testing.TestingConnectorSession.SESSION; import static io.trino.tpch.TpchTable.NATION; @@ -115,24 +115,16 @@ public void testIncompleteDynamicFilterTimeout() long startMillis = System.currentTimeMillis(); SchemaTableName schemaTableName = new SchemaTableName("tpch", "nation"); Table nationTable = catalog.loadTable(SESSION, schemaTableName); - IcebergTableHandle tableHandle = new IcebergTableHandle( - schemaTableName.getSchemaName(), - schemaTableName.getTableName(), - TableType.DATA, - Optional.empty(), - SchemaParser.toJson(nationTable.schema()), - Optional.of(PartitionSpecParser.toJson(nationTable.spec())), - 1, - TupleDomain.all(), - TupleDomain.all(), - ImmutableSet.of(), - Optional.empty(), - nationTable.location(), - nationTable.properties(), - NO_RETRIES, - ImmutableList.of(), - false, - Optional.empty()); + IcebergTableHandle tableHandle = IcebergTableHandle.builder() + .withSchemaName(schemaTableName.getSchemaName()) + .withTableName(schemaTableName.getTableName()) + .withTableType(DATA) + .withTableSchemaJson(SchemaParser.toJson(nationTable.schema())) + .withPartitionSpecJson(Optional.of(PartitionSpecParser.toJson(nationTable.spec()))) + .withFormatVersion(1) + .withTableLocation(nationTable.location()) + .withStorageProperties(nationTable.properties()) + .build(); try (IcebergSplitSource splitSource = new IcebergSplitSource( HDFS_ENVIRONMENT, diff --git a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/optimizer/TestConnectorPushdownRulesWithIceberg.java b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/optimizer/TestConnectorPushdownRulesWithIceberg.java index b0202f59aa7a..295fb409cd41 100644 --- a/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/optimizer/TestConnectorPushdownRulesWithIceberg.java +++ b/plugin/trino-iceberg/src/test/java/io/trino/plugin/iceberg/optimizer/TestConnectorPushdownRulesWithIceberg.java @@ -72,7 +72,6 @@ import static io.trino.plugin.iceberg.ColumnIdentity.primitiveColumnIdentity; import static io.trino.plugin.iceberg.TableType.DATA; import static io.trino.plugin.iceberg.catalog.hms.IcebergHiveMetastoreCatalogModule.HIDE_DELTA_LAKE_TABLES_IN_ICEBERG; -import static io.trino.spi.connector.RetryMode.NO_RETRIES; import static io.trino.spi.type.BigintType.BIGINT; import static io.trino.spi.type.IntegerType.INTEGER; import static io.trino.spi.type.RowType.field; @@ -166,24 +165,16 @@ public void testProjectionPushdown() BIGINT, Optional.empty()); - IcebergTableHandle icebergTable = new IcebergTableHandle( - SCHEMA_NAME, - tableName, - DATA, - Optional.of(1L), - "", - Optional.of(""), - 1, - TupleDomain.all(), - TupleDomain.all(), - ImmutableSet.of(), - Optional.empty(), - "", - ImmutableMap.of(), - NO_RETRIES, - ImmutableList.of(), - false, - Optional.empty()); + IcebergTableHandle icebergTable = IcebergTableHandle.builder() + .withSchemaName(SCHEMA_NAME) + .withTableName(tableName) + .withTableType(DATA) + .withSnapshotId(Optional.of(1L)) + .withTableSchemaJson("") + .withPartitionSpecJson(Optional.of("")) + .withFormatVersion(1) + .withTableLocation("") + .build(); TableHandle table = new TableHandle(TEST_CATALOG_HANDLE, icebergTable, new HiveTransactionHandle(false)); IcebergColumnHandle fullColumn = partialColumn.getBaseColumn(); @@ -201,7 +192,9 @@ public void testProjectionPushdown() project( ImmutableMap.of("expr", expression("col")), tableScan( - icebergTable.withProjectedColumns(ImmutableSet.of(fullColumn))::equals, + IcebergTableHandle.buildFrom(icebergTable) + .withProjectedColumns(ImmutableSet.of(fullColumn)) + .build()::equals, TupleDomain.all(), ImmutableMap.of("col", fullColumn::equals)))); @@ -213,7 +206,9 @@ public void testProjectionPushdown() p.tableScan( new TableHandle( TEST_CATALOG_HANDLE, - icebergTable.withProjectedColumns(ImmutableSet.of(fullColumn)), + IcebergTableHandle.buildFrom(icebergTable) + .withProjectedColumns(ImmutableSet.of(fullColumn)) + .build(), new HiveTransactionHandle(false)), ImmutableList.of(p.symbol("struct_of_int", baseType)), ImmutableMap.of(p.symbol("struct_of_int", baseType), fullColumn)))) @@ -232,7 +227,9 @@ public void testProjectionPushdown() .matches(project( ImmutableMap.of("expr_deref", expression(new SymbolReference("struct_of_int#a"))), tableScan( - icebergTable.withProjectedColumns(ImmutableSet.of(partialColumn))::equals, + IcebergTableHandle.buildFrom(icebergTable) + .withProjectedColumns(ImmutableSet.of(partialColumn)) + .build()::equals, TupleDomain.all(), ImmutableMap.of("struct_of_int#a", partialColumn::equals)))); @@ -248,24 +245,16 @@ public void testPredicatePushdown() PushPredicateIntoTableScan pushPredicateIntoTableScan = new PushPredicateIntoTableScan(tester().getPlannerContext(), tester().getTypeAnalyzer()); - IcebergTableHandle icebergTable = new IcebergTableHandle( - SCHEMA_NAME, - tableName, - DATA, - Optional.of(snapshotId), - "", - Optional.of(""), - 1, - TupleDomain.all(), - TupleDomain.all(), - ImmutableSet.of(), - Optional.empty(), - "", - ImmutableMap.of(), - NO_RETRIES, - ImmutableList.of(), - false, - Optional.empty()); + IcebergTableHandle icebergTable = IcebergTableHandle.builder() + .withSchemaName(SCHEMA_NAME) + .withTableName(tableName) + .withTableType(DATA) + .withSnapshotId(Optional.of(snapshotId)) + .withTableSchemaJson("") + .withPartitionSpecJson(Optional.of("")) + .withFormatVersion(1) + .withTableLocation("") + .build(); TableHandle table = new TableHandle(TEST_CATALOG_HANDLE, icebergTable, new HiveTransactionHandle(false)); IcebergColumnHandle column = new IcebergColumnHandle(primitiveColumnIdentity(1, "a"), INTEGER, ImmutableList.of(), INTEGER, Optional.empty()); @@ -297,24 +286,15 @@ public void testColumnPruningProjectionPushdown() PruneTableScanColumns pruneTableScanColumns = new PruneTableScanColumns(tester().getMetadata()); - IcebergTableHandle icebergTable = new IcebergTableHandle( - SCHEMA_NAME, - tableName, - DATA, - Optional.empty(), - "", - Optional.of(""), - 1, - TupleDomain.all(), - TupleDomain.all(), - ImmutableSet.of(), - Optional.empty(), - "", - ImmutableMap.of(), - NO_RETRIES, - ImmutableList.of(), - false, - Optional.empty()); + IcebergTableHandle icebergTable = IcebergTableHandle.builder() + .withSchemaName(SCHEMA_NAME) + .withTableName(tableName) + .withTableType(DATA) + .withTableSchemaJson("") + .withPartitionSpecJson(Optional.of("")) + .withFormatVersion(1) + .withTableLocation("") + .build(); TableHandle table = new TableHandle(TEST_CATALOG_HANDLE, icebergTable, new HiveTransactionHandle(false)); IcebergColumnHandle columnA = new IcebergColumnHandle(primitiveColumnIdentity(0, "a"), INTEGER, ImmutableList.of(), INTEGER, Optional.empty()); @@ -337,7 +317,9 @@ public void testColumnPruningProjectionPushdown() strictProject( ImmutableMap.of("expr", expression("COLA")), tableScan( - icebergTable.withProjectedColumns(ImmutableSet.of(columnA))::equals, + IcebergTableHandle.buildFrom(icebergTable) + .withProjectedColumns(ImmutableSet.of(columnA)) + .build()::equals, TupleDomain.all(), ImmutableMap.of("COLA", columnA::equals)))); @@ -357,24 +339,16 @@ public void testPushdownWithDuplicateExpressions() tester().getTypeAnalyzer(), new ScalarStatsCalculator(tester().getPlannerContext(), tester().getTypeAnalyzer())); - IcebergTableHandle icebergTable = new IcebergTableHandle( - SCHEMA_NAME, - tableName, - DATA, - Optional.of(1L), - "", - Optional.of(""), - 1, - TupleDomain.all(), - TupleDomain.all(), - ImmutableSet.of(), - Optional.empty(), - "", - ImmutableMap.of(), - NO_RETRIES, - ImmutableList.of(), - false, - Optional.empty()); + IcebergTableHandle icebergTable = IcebergTableHandle.builder() + .withSchemaName(SCHEMA_NAME) + .withTableName(tableName) + .withTableType(DATA) + .withSnapshotId(Optional.of(1L)) + .withTableSchemaJson("") + .withPartitionSpecJson(Optional.of("")) + .withFormatVersion(1) + .withTableLocation("") + .build(); TableHandle table = new TableHandle(TEST_CATALOG_HANDLE, icebergTable, new HiveTransactionHandle(false)); IcebergColumnHandle bigintColumn = new IcebergColumnHandle(primitiveColumnIdentity(1, "just_bigint"), BIGINT, ImmutableList.of(), BIGINT, Optional.empty()); @@ -405,7 +379,9 @@ public void testPushdownWithDuplicateExpressions() "column_ref", expression("just_bigint_0"), "negated_column_ref", expression("- just_bigint_0")), tableScan( - icebergTable.withProjectedColumns(ImmutableSet.of(bigintColumn))::equals, + IcebergTableHandle.buildFrom(icebergTable) + .withProjectedColumns(ImmutableSet.of(bigintColumn)) + .build()::equals, TupleDomain.all(), ImmutableMap.of("just_bigint_0", bigintColumn::equals)))); @@ -429,7 +405,9 @@ public void testPushdownWithDuplicateExpressions() "expr_deref", expression(new SymbolReference("struct_of_bigint#a")), "expr_deref_2", expression(new ArithmeticBinaryExpression(ADD, new SymbolReference("struct_of_bigint#a"), new LongLiteral("2")))), tableScan( - icebergTable.withProjectedColumns(ImmutableSet.of(partialColumn))::equals, + IcebergTableHandle.buildFrom(icebergTable) + .withProjectedColumns(ImmutableSet.of(partialColumn)) + .build()::equals, TupleDomain.all(), ImmutableMap.of("struct_of_bigint#a", partialColumn::equals))));