-
Notifications
You must be signed in to change notification settings - Fork 392
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#1313][#1471] feat(iceberg): Support struct column for iceberg #1721
Changes from 1 commit
567aff8
799255e
25e68f3
0eff76e
e011a9e
786d877
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,4 +61,22 @@ public static IcebergColumn fromNestedField(Types.NestedField nestedField) { | |
.withType(ConvertUtil.formIcebergType(nestedField.type())) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Convert the Gravitino field of Iceberg to the Iceberg column. | ||
* | ||
* @param field Gravitino field. | ||
* @param id | ||
* @return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a full comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I'll add it |
||
*/ | ||
public static IcebergColumn fromGravitinoField( | ||
FANNG1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
com.datastrato.gravitino.rel.types.Types.StructType.Field field, int id) { | ||
return new IcebergColumn.Builder() | ||
.withId(id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The iceberg type ID has generation rules, but it is uncertain whether the underlying layer is useful There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The input parameters of this method is StructType.Field, not a table, my understanding of iceberg type ID generation rules is aimed at IcebergTable |
||
.withName(field.name()) | ||
.withNullable(field.nullable()) | ||
.withComment(field.comment()) | ||
.withType(field.type()) | ||
.build(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,9 @@ | |
import com.datastrato.gravitino.rel.types.Type; | ||
import com.datastrato.gravitino.rel.types.Types; | ||
import com.google.common.collect.Lists; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* Type converter belonging to gravitino. | ||
|
@@ -52,6 +54,19 @@ public static <T> T visit(Type type, ToIcebergTypeVisitor<T> visitor) { | |
} else if (type instanceof Types.ListType) { | ||
Types.ListType list = (Types.ListType) type; | ||
return visitor.array(list, visit(list.elementType(), visitor)); | ||
} else if (type instanceof Types.StructType) { | ||
Types.StructType struct = (Types.StructType) type; | ||
Types.StructType.Field[] fields = struct.fields(); | ||
List<IcebergColumn> columns = | ||
Arrays.stream(fields) | ||
.map( | ||
field -> { | ||
return ConvertUtil.fromGravitinoField(field, 0); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The id is always zero? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's best to generate this ID according to iceberg's generation rules There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The id will not be used in the subsequent logic, visitor.struct() will generate this ID according to iceberg's generation rules.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think it is necessary to add generated ID logic in this method, though these ID will never be used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's confirmed that this won't be used, then I think we can pass a 0 to keep the code clean. We should first raise an issue to refactor the previous code and abandon the use of ID. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The 0 of id passed here will never be used in the subsequent logic, so It's not necessary to generate id here. |
||
}) | ||
.collect(Collectors.toList()); | ||
IcebergTable mockTable = | ||
new IcebergTable.Builder().withColumns(columns.toArray(new IcebergColumn[0])).build(); | ||
FANNG1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return visit(mockTable, visitor); | ||
} else { | ||
return visitor.atomic((Type.PrimitiveType) type); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's field of StructType, not Iceberg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I'll fix it