Skip to content

Commit

Permalink
Core: Optimize manifest evaluation for super wide tables (#9147)
Browse files Browse the repository at this point in the history
  • Loading branch information
irshadcc authored Dec 25, 2023
1 parent 6f4e33e commit 197b61e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String name() {

@Override
public BoundReference<T> bind(Types.StructType struct, boolean caseSensitive) {
Schema schema = new Schema(struct.fields());
Schema schema = struct.asSchema();
Types.NestedField field =
caseSensitive ? schema.findField(name) : schema.caseInsensitiveFindField(name);

Expand Down
16 changes: 16 additions & 0 deletions api/src/main/java/org/apache/iceberg/types/Types.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.iceberg.Schema;
import org.apache.iceberg.relocated.com.google.common.base.Joiner;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableList;
Expand Down Expand Up @@ -537,6 +538,7 @@ public static StructType of(List<NestedField> fields) {
private final NestedField[] fields;

// lazy values
private transient Schema schema = null;
private transient List<NestedField> fieldList = null;
private transient Map<String, NestedField> fieldsByName = null;
private transient Map<String, NestedField> fieldsByLowerCaseName = null;
Expand Down Expand Up @@ -592,6 +594,20 @@ public Types.StructType asStructType() {
return this;
}

/**
* Returns a schema which contains the columns inside struct type. This method can be used to
* avoid expensive conversion of StructType containing large number of columns to Schema during
* manifest evaluation.
*
* @return the schema containing columns of struct type.
*/
public Schema asSchema() {
if (this.schema == null) {
this.schema = new Schema(Arrays.asList(this.fields));
}
return this.schema;
}

@Override
public String toString() {
return String.format("struct<%s>", FIELD_SEP.join(fields));
Expand Down

0 comments on commit 197b61e

Please sign in to comment.