ramitg254 commented on code in PR #6565:
URL: https://github.com/apache/hive/pull/6565#discussion_r3503931068


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java:
##########
@@ -744,12 +744,14 @@ private void 
handleAddColumns(org.apache.hadoop.hive.metastore.api.Table hmsTabl
     boolean isORc = isOrcFileFormat(hmsTable);
     for (FieldSchema addedCol : addedCols) {
       String defaultValue = defaultValues.get(addedCol.getName());
-      Type type = 
HiveSchemaUtil.convert(TypeInfoUtils.getTypeInfoFromTypeString(addedCol.getType()),
 defaultValue);
-      Literal<Object> defaultVal = Optional.ofNullable(defaultValue).filter(v 
-> !type.isStructType())
-          .map(v -> Expressions.lit(HiveSchemaUtil.getDefaultValue(v, 
type))).orElse(null);
-
+      Type baseType = 
HiveSchemaUtil.convert(TypeInfoUtils.getTypeInfoFromTypeString(addedCol.getType()),
 defaultValue);
+      final Type resolvedType = (!isORc && baseType.isStructType()) ?
+          HiveSchemaUtil.applyInitialDefaultsToStruct(baseType) :
+          baseType;
+      Literal<Object> defaultVal = Optional.ofNullable(defaultValue).filter(v 
-> !resolvedType.isStructType())
+          .map(v -> Expressions.lit(HiveSchemaUtil.getDefaultValue(v, 
resolvedType))).orElse(null);
       // ORC doesn't have support for initialDefault from iceberg layer, we 
only need to set default for writeDefault.
-      updateSchema.addColumn(addedCol.getName(), type, addedCol.getComment(), 
isORc ? null : defaultVal);
+      updateSchema.addColumn(addedCol.getName(), resolvedType, 
addedCol.getComment(), isORc ? null : defaultVal);

Review Comment:
   yes that was the earlier approach  I was using but `isOrc` argument needs to 
be passed there in convert to determine initial default needs to be set or not 
for inner struct fields which doesn't looks good as it will introduce concern 
"which metadata should be attached while building column type" which is not 
objective of convert , so building a copy of type already built with the 
already present metadata and initial defaults of underlying fields if col is of 
struct type and isOrc is false



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to