szehon-ho commented on code in PR #5443: URL: https://github.com/apache/iceberg/pull/5443#discussion_r940663982
########## core/src/main/java/org/apache/iceberg/BaseEntriesTable.java: ########## @@ -0,0 +1,160 @@ +/* + * 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.iceberg; + +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; +import java.util.Map; +import org.apache.iceberg.expressions.Expression; +import org.apache.iceberg.expressions.Expressions; +import org.apache.iceberg.expressions.ManifestEvaluator; +import org.apache.iceberg.expressions.ResidualEvaluator; +import org.apache.iceberg.io.CloseableIterable; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.relocated.com.google.common.collect.Sets; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.TypeUtil; +import org.apache.iceberg.types.Types.StructType; +import org.apache.iceberg.util.StructProjection; + +/** Base class logic for entries metadata tables */ +abstract class BaseEntriesTable extends BaseMetadataTable { + + BaseEntriesTable(TableOperations ops, Table table, String name) { + super(ops, table, name); + } + + @Override + public Schema schema() { + StructType partitionType = Partitioning.partitionType(table()); + Schema schema = ManifestEntry.getSchema(partitionType); + if (partitionType.fields().size() < 1) { + // avoid returning an empty struct, which is not always supported. instead, drop the partition + // field (id 102) + return TypeUtil.selectNot(schema, Sets.newHashSet(102)); + } else { + return schema; + } + } + + static CloseableIterable<FileScanTask> planFiles( + Table table, + CloseableIterable<ManifestFile> manifests, + Schema tableSchema, + Schema projectedSchema, + TableScanContext context) { + Expression rowFilter = context.rowFilter(); + boolean caseSensitive = context.caseSensitive(); + boolean ignoreResiduals = context.ignoreResiduals(); + + LoadingCache<Integer, ManifestEvaluator> evalCache = + Caffeine.newBuilder() + .build( + specId -> { + PartitionSpec spec = table.specs().get(specId); + PartitionSpec transformedSpec = BaseFilesTable.transformSpec(tableSchema, spec); + return ManifestEvaluator.forRowFilter(rowFilter, transformedSpec, caseSensitive); + }); + + CloseableIterable<ManifestFile> filteredManifests = + CloseableIterable.filter( + manifests, manifest -> evalCache.get(manifest.partitionSpecId()).eval(manifest)); + + String schemaString = SchemaParser.toJson(projectedSchema); + String specString = PartitionSpecParser.toJson(PartitionSpec.unpartitioned()); + Expression filter = ignoreResiduals ? Expressions.alwaysTrue() : rowFilter; + ResidualEvaluator residuals = ResidualEvaluator.unpartitioned(filter); + + return CloseableIterable.transform( + filteredManifests, + manifest -> + new ManifestReadTask( + table, manifest, projectedSchema, schemaString, specString, residuals)); + } + + @Override + MetadataTableType metadataTableType() { + return MetadataTableType.ALL_ENTRIES; Review Comment: Whoops you are right, thanks ########## core/src/main/java/org/apache/iceberg/BaseEntriesTable.java: ########## @@ -0,0 +1,160 @@ +/* + * 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.iceberg; + +import com.github.benmanes.caffeine.cache.Caffeine; +import com.github.benmanes.caffeine.cache.LoadingCache; +import java.util.Map; +import org.apache.iceberg.expressions.Expression; +import org.apache.iceberg.expressions.Expressions; +import org.apache.iceberg.expressions.ManifestEvaluator; +import org.apache.iceberg.expressions.ResidualEvaluator; +import org.apache.iceberg.io.CloseableIterable; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList; +import org.apache.iceberg.relocated.com.google.common.collect.Maps; +import org.apache.iceberg.relocated.com.google.common.collect.Sets; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.TypeUtil; +import org.apache.iceberg.types.Types.StructType; +import org.apache.iceberg.util.StructProjection; + +/** Base class logic for entries metadata tables */ +abstract class BaseEntriesTable extends BaseMetadataTable { + + BaseEntriesTable(TableOperations ops, Table table, String name) { + super(ops, table, name); + } + + @Override + public Schema schema() { + StructType partitionType = Partitioning.partitionType(table()); + Schema schema = ManifestEntry.getSchema(partitionType); + if (partitionType.fields().size() < 1) { + // avoid returning an empty struct, which is not always supported. instead, drop the partition + // field (id 102) + return TypeUtil.selectNot(schema, Sets.newHashSet(102)); Review Comment: Good catch, done -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
