sunshone commented on code in PR #13693:
URL: https://github.com/apache/gluten/pull/13693#discussion_r4691114450


##########
gluten-flink/planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecRank.java:
##########
@@ -287,25 +330,56 @@ protected Transformation<RowData> translateToPlanInternal(
             inputTransform.getParallelism(),
             false);
 
-    // set KeyType and Selector for state
-    RowDataKeySelector selector =
-        KeySelectorUtil.getRowDataSelector(
-            planner.getFlinkContext().getClassLoader(),
-            partitionSpec.getFieldIndices(),
-            inputRowTypeInfo);
-    transform.setStateKeySelector(selector);
-    transform.setStateKeyType(selector.getProducedType());
+    // The transformation stays NON-keyed (implementation contract): the key
+    // belongs to the velox keyed state backend via the plan's
+    // KeyedStateSpec, and declaring a Flink key selector would conflict
+    // with the native key-group routing at parallelism > 1.
     return transform;
   }
 
-  private List<SortOrder> generateSortOrders(SortSpec sortSpec) {
-    final List<SortOrder> sortOrders = new ArrayList<>();
-    boolean[] ascendingOrders = sortSpec.getAscendingOrders();
-    boolean[] nullLasts = sortSpec.getNullsIsLast();
-    checkArgument(ascendingOrders.length == nullLasts.length);
-    for (int i = 0; i < ascendingOrders.length; i++) {
-      sortOrders.add(new SortOrder(ascendingOrders[i], !nullLasts[i]));
+  // The native keyed state backend supports fixed-width scalar and
+  // varchar/varbinary key columns only (KeyTable::checkStateKeyTypes);
+  // unsupported partition key types fail loud at translation time instead
+  // of dying inside the first probe.
+  private static void checkPartitionKeyTypeSupported(LogicalType type, int 
fieldIndex) {
+    final boolean supported =
+        (TypeCheckUtils.isNumeric(type) && !TypeCheckUtils.isDecimal(type))
+            || TypeCheckUtils.isTimestamp(type)
+            || TypeCheckUtils.isTimestampWithLocalZone(type)
+            || TypeCheckUtils.isBoolean(type)
+            || TypeCheckUtils.isCharacterString(type)
+            || TypeCheckUtils.isBinaryString(type);
+    if (!supported) {
+      throw new TableException(
+          String.format(
+              "Gluten rank does not support partition key type %s at field 
%d", type, fieldIndex));
+    }
+  }
+
+  // The native sort-key comparator (RankOperator.cpp compareScalarValues)
+  // covers exactly these velox type kinds (design limit L11): the 11 base
+  // kinds plus DECIMAL (BIGINT/HUGEINT kind by precision) and DATE (INTEGER
+  // kind); a sort key outside the set fails loud at translation time
+  // instead of on the first row comparison.
+  private static void checkSortKeyTypeSupported(Type type, int fieldIndex) {

Review Comment:
   @ggjh-159 Done. The translation now checks every input column of the rank 
node against the exact kind set the native compact row storage accepts (its 
checkColumnKind): the scalar kinds plus DECIMAL by way of BIGINT/HUGEINT and 
DATE by way of INTEGER, with TIMESTAMP_LTZ normalized to TIMESTAMP by the 
converter. A column outside the set - nested types and anything else the 
storage rejects - fails at translation with a "Gluten rank row storage does not 
support input column type" message, the same fail-loud shape as the other 
guards. Covered by a new planner test (an ARRAY column in the rank input, 
rejected at translation).



##########
gluten-flink/planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecExchange.java:
##########
@@ -139,13 +134,19 @@ protected Transformation<RowData> translateToPlanInternal(
             KeySelectorUtil.getRowDataSelector(
                 planner.getFlinkContext().getClassLoader(), keys, inputType);
         // --- Begin Gluten-specific code changes ---
-        // The gluten exchange optimization below only applies when the input 
is
-        // already a gluten operator wrapped in a OneInputTransformation; other
-        // shapes (e.g. a SourceTransformation feeding the hash exchange in a
-        // plain GROUP BY) must take the vanilla Flink fallback instead of
-        // failing with a ClassCastException.
-        if (inputTransform instanceof OneInputTransformation
-            && ((OneInputTransformation) inputTransform).getOperator() 
instanceof GlutenOperator) {
+        // Key-group routing is always native: the native keyed state backend

Review Comment:
   @ggjh-159 Restored the shared-path guard: the native exchange applies when 
the input is a gluten operator and everything else takes the vanilla 
KeyGroupStreamPartitioner, as before this PR. One carve-out is kept, with 
runtime evidence: an offloaded gluten source emits StatefulRecord records on a 
source-direct edge, and the vanilla partitioner's RowData key selector cannot 
key them - ClassCastException: StatefulRecord cannot be cast to RowData inside 
KeyGroupStreamPartitioner.selectChannel, reproduced by the values-source 
planner tests when the guard is fully restored. That crash is the #13409 
fallback's own gap (it predates the rank work - a plain GROUP BY over an 
offloaded source hits it), so those source-direct edges route natively. 
Consistent with the interim design, rank plans at parallelism above 1 whose 
input would route vanilla fail loud at translation ("requires its input to be a 
gluten one-input operator") instead of misrouting against the native key-group 
ownership; the 
 keyed-state integration makes Flink's partitioner and key groups agree and 
lifts the restriction.



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