vvysotskyi commented on a change in pull request #1374: [CALCITE-3138] 
Restructuring ROW type fields is not supported
URL: https://github.com/apache/calcite/pull/1374#discussion_r314039354
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/sql2rel/RelStructuredTypeFlattener.java
 ##########
 @@ -296,42 +273,42 @@ protected int getNewForOldInput(int oldOrdinal) {
   }
 
   /**
-   * Maps the ordinal of a field pre-flattening to the ordinal of the
-   * corresponding field post-flattening, and also returns its type.
+   * Finds type and new ordinal relative to new inputs by oldOrdinal and
+   * innerOrdinal indexes.
    *
-   * @param oldOrdinal Pre-flattening ordinal
-   * @param existingOffset offset already calculated the target column inside 
the oldOrdinal column.
-   *                       For unnested column, it should be 0.
-   * @return Post-flattening ordinal and type
+   * @param oldOrdinal   ordinal of the field relative to old inputs
+   * @param innerOrdinal when oldOrdinal points to struct and target field
+   *                     is inner field of struct, this argument should contain
+   *                     calculated field's ordinal within struct after 
flattening.
+   *                     Otherwise when oldOrdinal points to primitive field, 
this
+   *                     argument should be zero.
+   * @return flat type with new ordinal relative to new inputs
    */
-  private Ord<RelDataType> getNewFieldForOldInput(int oldOrdinal, int 
existingOffset) {
+  private Ord<RelDataType> getNewFieldForOldInput(int oldOrdinal, int 
innerOrdinal) {
     assert currentRel != null;
-    int newOrdinal = 0;
-
-    // determine which input rel oldOrdinal references, and adjust
-    // oldOrdinal to be relative to that input rel
-    RelNode oldInput = null;
-    RelNode newInput = null;
-    for (RelNode oldInput1 : currentRel.getInputs()) {
-      newInput = getNewForOldRel(oldInput1);
-      RelDataType oldInputType = oldInput1.getRowType();
-      int n = oldInputType.getFieldCount();
-      if (oldOrdinal < n) {
-        oldInput = oldInput1;
-        break;
-      }
-      newOrdinal += newInput.getRowType().getFieldCount();
-      oldOrdinal -= n;
-    }
-    assert oldInput != null;
-    assert newInput != null;
-
-    RelDataType oldInputType = oldInput.getRowType();
-    final int newOffset = calculateFlattenedOffset(oldInputType, oldOrdinal) + 
existingOffset;
-    newOrdinal += newOffset;
-    final RelDataTypeField field =
-        newInput.getRowType().getFieldList().get(newOffset);
-    return Ord.of(newOrdinal, field.getType());
+    // sum of predecessors post flatten sizes points to new ordinal
+    // of flat field or first field of flattened struct
+    final int postFlatteningOrdinal = currentRel.getInputs().stream()
+        .flatMap(node -> node.getRowType().getFieldList().stream())
 
 Review comment:
   I'm not sure that it will work for all types of rel nodes. If I understand 
correctly, there was used assumption, that row type of current rel node 
consists of fields from the inputs, but for some kinds of operators, like 
semi-join, fields of one of the input aren't included into the resulting row 
type.

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


With regards,
Apache Git Services

Reply via email to