Skip to content

Commit

Permalink
address nits
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinGe00 committed Jul 24, 2024
1 parent 901d560 commit dd20301
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public static RelDataType convert(StructTypeInfo structType, final RelDataTypeFa
// The schema of output Struct conforms to https://github.com/trinodb/trino/pull/3483
// except we adopted "integer" for the type of "tag" field instead of "tinyint" in the Trino patch
// for compatibility with other platforms that Iceberg currently doesn't support tinyint type.
// When the field count inside UnionTypeInfo is one, we surface the underlying RelDataType instead.

// Note: this is subject to change in the future pending on the discussion in
// https://mail-archives.apache.org/mod_mbox/iceberg-dev/202112.mbox/browser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,7 @@ public RexNode visitFieldAccess(RexFieldAccess rexFieldAccess) {
// UDFs calls could potentially be doubly (or more) field-referenced, for example, `extract_union(baz).single.tag_0`
// where baz is a struct containing a uniontype field. In this case, we simply need to use derived type of the entire
// call. Note that this also takes care of the simple one layer field reference on a UDF call.
String oldFieldName = rexFieldAccess.getField().getName();
String suggestNewFieldName = suggestedFieldNames.poll();
String newFieldName = SchemaUtilities.getFieldName(oldFieldName, suggestNewFieldName);

RelDataType fieldType = rexFieldAccess.getType();
boolean isNullable = SchemaUtilities.isFieldNullable((RexCall) referenceExpr, inputSchema);
// TODO: add field documentation
SchemaUtilities.appendField(newFieldName, fieldType, null, fieldAssembler, isNullable);
handleUDFFieldAccess(rexFieldAccess, (RexCall) referenceExpr);
return rexFieldAccess;
} else if (referenceExpr instanceof RexFieldAccess) {
// While selecting `int_field` from `struct_col:struct<inner_struct_col:struct<int_field:int>>` using `struct_col.inner_struct_col.int_field`,
Expand All @@ -527,16 +520,31 @@ public RexNode visitFieldAccess(RexFieldAccess rexFieldAccess) {
}
}

handleFieldAccess(rexFieldAccess, (RexInputRef) referenceExpr, innerRecordNames);
return rexFieldAccess;
}

private void handleFieldAccess(RexFieldAccess rexFieldAccess, RexInputRef referenceExpr,
Deque<String> innerRecordNames) {
String oldFieldName = rexFieldAccess.getField().getName();
String suggestNewFieldName = suggestedFieldNames.poll();
String newFieldName = SchemaUtilities.getFieldName(oldFieldName, suggestNewFieldName);
Schema topSchema = inputSchema.getFields().get(((RexInputRef) referenceExpr).getIndex()).schema();

Schema topSchema = inputSchema.getFields().get(referenceExpr.getIndex()).schema();
Schema.Field accessedField = getFieldFromTopSchema(topSchema, oldFieldName, innerRecordNames);
assert accessedField != null;
SchemaUtilities.appendField(newFieldName, accessedField, fieldAssembler);
}

return rexFieldAccess;
private void handleUDFFieldAccess(RexFieldAccess rexFieldAccess, RexCall referenceExpr) {
String oldFieldName = rexFieldAccess.getField().getName();
String suggestNewFieldName = suggestedFieldNames.poll();
String newFieldName = SchemaUtilities.getFieldName(oldFieldName, suggestNewFieldName);

RelDataType fieldType = rexFieldAccess.getType();
boolean isNullable = SchemaUtilities.isFieldNullable(referenceExpr, inputSchema);
// TODO: add field documentation
SchemaUtilities.appendField(newFieldName, fieldType, null, fieldAssembler, isNullable);
}

@Override
Expand Down

0 comments on commit dd20301

Please sign in to comment.