pvary commented on a change in pull request #1842:
URL: https://github.com/apache/iceberg/pull/1842#discussion_r532633290
##########
File path:
hive-metastore/src/main/java/org/apache/iceberg/hive/HiveTypeConverter.java
##########
@@ -30,7 +37,52 @@ private HiveTypeConverter() {
}
- public static String convert(Type type) {
+ /**
+ * Converts the Iceberg schema to a Hive schema.
+ * @param schema The original Iceberg schema to convert
+ * @return The Hive column list generated from the Iceberg schema
+ */
+ public static List<FieldSchema> hiveSchema(Schema schema) {
+ return schema.columns().stream()
+ .map(col -> new FieldSchema(col.name(),
HiveTypeConverter.convert(col.type()), ""))
+ .collect(Collectors.toList());
+ }
+
+ /**
+ * Converts the list of Hive FieldSchemas to an Iceberg schema.
+ * <p>
+ * The list should contain the columns and the partition columns as well.
+ * @param fieldSchemas The list of the columns
+ * @return An equivalent Iceberg Schema
+ */
+ public static Schema icebergSchema(List<FieldSchema> fieldSchemas) {
+ List<String> names = new ArrayList<>(fieldSchemas.size());
+ List<TypeInfo> typeInfos = new ArrayList<>(fieldSchemas.size());
+
+ for (FieldSchema col : fieldSchemas) {
+ names.add(col.getName());
+ typeInfos.add(TypeInfoUtils.getTypeInfoFromTypeString(col.getType()));
Review comment:
Thanks @rdsr for the review!
In my previous PRs I have been asked to stick to minimal changes so it is
easier to review, so I did not even started to think about adding any change
here 😄 (I have been in the reviewing end of the changes and I definitely
understand the pain of reviewing the big changes)
That said, your suggestion definitely worth checking. I have some concerns
that Hive might disregard the comments set in the schema. I have seen columns
with "from deserializer" and I am a little bit concerned about how Hive will
handle this.
Would you think this should be another PR, or should we handle this here?
Thanks,
Peter
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]