Skip to content

Commit

Permalink
fix copy method impl that broke some Hive tests that requires Partiti…
Browse files Browse the repository at this point in the history
…onKey#copy method
  • Loading branch information
stevenzwu committed Jun 8, 2023
1 parent 80ba5af commit 69693cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion api/src/main/java/org/apache/iceberg/PartitionKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public PartitionKey(PartitionSpec spec, Schema inputSchema) {

private PartitionKey(PartitionKey toCopy) {
// only need deep copy inside StructTransform
super(toCopy.inputSchema, fieldTransform(toCopy.spec));
super(toCopy);
this.spec = toCopy.spec;
this.inputSchema = toCopy.inputSchema;
}
Expand Down
15 changes: 13 additions & 2 deletions api/src/main/java/org/apache/iceberg/StructTransform.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@
class StructTransform implements StructLike, Serializable {

private final int size;
private final Object[] transformedTuple;
private final Accessor<StructLike>[] accessors;

@SuppressWarnings("rawtypes")
private final SerializableFunction[] transforms;

private final Object[] transformedTuple;

StructTransform(Schema schema, List<FieldTransform> fieldTransforms) {
Preconditions.checkArgument(fieldTransforms != null, "Invalid field transform list: null");

this.size = fieldTransforms.size();
this.transformedTuple = new Object[size];
this.accessors = (Accessor<StructLike>[]) Array.newInstance(Accessor.class, size);
this.transforms = new SerializableFunction[size];

Expand All @@ -59,6 +59,17 @@ class StructTransform implements StructLike, Serializable {
this.accessors[i] = accessor;
this.transforms[i] = transform.bind(accessor.type());
}

this.transformedTuple = new Object[size];
}

StructTransform(StructTransform toCopy) {
this.size = toCopy.size;
this.accessors = toCopy.accessors;
this.transforms = toCopy.transforms;

this.transformedTuple = new Object[size];
System.arraycopy(toCopy.transformedTuple, 0, this.transformedTuple, 0, size);
}

public void wrap(StructLike row) {
Expand Down

0 comments on commit 69693cd

Please sign in to comment.