mihaibudiu commented on code in PR #4739:
URL: https://github.com/apache/calcite/pull/4739#discussion_r2684540576


##########
core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java:
##########
@@ -627,18 +627,39 @@ private RexProgram createProgramForLevel(
         outputRowType);
   }
 
-  private String deriveFieldName(RexNode expr, int ordinal) {
+  private String deriveFieldName(RexNode expr, int exprIndex, int ordinal) {
+    String fieldName = null;
     if (expr instanceof RexInputRef) {
-      int inputIndex = ((RexInputRef) expr).getIndex();
-      String fieldName =
-          child.getRowType().getFieldList().get(inputIndex).getName();
-      // Don't inherit field names like '$3' from child: that's
-      // confusing.
-      if (!fieldName.startsWith("$") || fieldName.startsWith("$EXPR")) {
-        return fieldName;
+      fieldName = getInputRefName((RexInputRef) expr);
+    } else {
+      fieldName = findProjectedFieldName(exprIndex);
+    }
+    return normalizeFieldName(fieldName, ordinal);
+  }
+
+  private String getInputRefName(RexInputRef ref) {
+    int inputIndex = ref.getIndex();
+    return child.getRowType().getFieldList().get(inputIndex).getName();
+  }
+
+  private @Nullable String findProjectedFieldName(int exprIndex) {

Review Comment:
   or even better `within `{@link #program}`



##########
core/src/main/java/org/apache/calcite/rel/rules/CalcRelSplitter.java:
##########
@@ -627,18 +627,39 @@ private RexProgram createProgramForLevel(
         outputRowType);
   }
 
-  private String deriveFieldName(RexNode expr, int ordinal) {
+  private String deriveFieldName(RexNode expr, int exprIndex, int ordinal) {
+    String fieldName = null;
     if (expr instanceof RexInputRef) {
-      int inputIndex = ((RexInputRef) expr).getIndex();
-      String fieldName =
-          child.getRowType().getFieldList().get(inputIndex).getName();
-      // Don't inherit field names like '$3' from child: that's
-      // confusing.
-      if (!fieldName.startsWith("$") || fieldName.startsWith("$EXPR")) {
-        return fieldName;
+      fieldName = getInputRefName((RexInputRef) expr);
+    } else {
+      fieldName = findProjectedFieldName(exprIndex);
+    }
+    return normalizeFieldName(fieldName, ordinal);
+  }
+
+  private String getInputRefName(RexInputRef ref) {
+    int inputIndex = ref.getIndex();
+    return child.getRowType().getFieldList().get(inputIndex).getName();
+  }
+
+  private @Nullable String findProjectedFieldName(int exprIndex) {

Review Comment:
   or even better `within {@link #program}`



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

Reply via email to