You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "stevenzwu (via GitHub)" <gi...@apache.org> on 2023/05/05 15:47:24 UTC

[GitHub] [iceberg] stevenzwu commented on a diff in pull request #7517: API, Flink: StructProjection returns null projection object for null nested struct value

stevenzwu commented on code in PR #7517:
URL: https://github.com/apache/iceberg/pull/7517#discussion_r1185469804


##########
api/src/main/java/org/apache/iceberg/util/StructProjection.java:
##########
@@ -189,16 +189,12 @@ public int size() {
 
   @Override
   public <T> T get(int pos, Class<T> javaClass) {
-    if (struct == null) {
-      // Return a null struct when projecting a nested required field from an optional struct.
-      // See more details in issue #2738.
-      return null;
-    }
-
     int structPos = positionMap[pos];
-
     if (nestedProjections[pos] != null) {
-      return javaClass.cast(nestedProjections[pos].wrap(struct.get(structPos, StructLike.class)));
+      StructLike nestedStruct = struct.get(structPos, StructLike.class);

Review Comment:
   good question. this change avoided the wrapping null at nested level, [which is the main reason we added the lines from 192-196](https://github.com/apache/iceberg/issues/2738) that are removed in this PR. 
   
   I guess it can potentially happen if we use `StructProjection` to wrap a null `struct` at the root level. If it is a valid scenario, we need to bring back line 192-196. If it is not a valid scenario, we should add `Preconditions` check in the wrap method.
   ```
     public StructProjection wrap(StructLike newStruct) {
       this.struct = newStruct;
       return this;
     }
   ```
   
   My take is that StructProjection shouldn't wrap a null root value.



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org