philo-he commented on code in PR #13558:
URL: https://github.com/apache/gluten/pull/13558#discussion_r4625532775
##########
gluten-flink/planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecGroupAggregate.java:
##########
@@ -226,15 +240,13 @@ protected Transformation<RowData> translateToPlanInternal(
inputTransform.getParallelism(),
false);
- // set KeyType and Selector for state
- final RowDataKeySelector selector =
- KeySelectorUtil.getRowDataSelector(
- planner.getFlinkContext().getClassLoader(),
- grouping,
- InternalTypeInfo.of(inputRowType));
- transform.setStateKeySelector(selector);
- transform.setStateKeyType(selector.getProducedType());
-
+ // Keys are owned by the velox side (KeyedStateSpec feeds the C++ keyed
state
Review Comment:
Since Flink no longer treats this operator as keyed, how is the Velox keyed
state checkpointed and restored? In particular:
- Restoring at a different parallelism: who redistributes the keys?
- Can a savepoint taken before this change still be restored?
A test that checkpoints at p=2 and restores at p=4 would answer most of this.
##########
.github/workflows/flink.yml:
##########
@@ -89,9 +89,8 @@ jobs:
export VELOX_DEPENDENCY_SOURCE=BUNDLED
export fmt_SOURCE=BUNDLED
export folly_SOURCE=BUNDLED
- git clone -b gluten-20260829 https://github.com/bigo-sg/velox4j.git
+ git clone -b feat/stateful-group-agg-keyed-state
https://github.com/ggjh-159/velox4j.git
Review Comment:
Revert this before merge.
##########
gluten-flink/planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecGroupAggregate.java:
##########
@@ -198,13 +197,28 @@ protected Transformation<RowData> translateToPlanInternal(
.collect(Collectors.toList());
List<Integer> keyIndexes =
Arrays.stream(grouping).boxed().collect(Collectors.toList());
PartitionFunctionSpec keySelectorSpec = new
HashPartitionFunctionSpec(inputType, keyIndexes);
+ KeyedStateSpec keyedStateSpec =
Review Comment:
For a global aggregation (no `GROUP BY` keys), the key list here is empty.
Does that work end to end? A test such as `SELECT COUNT(*) FROM t` would cover
it.
##########
gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/AggregateCallConverter.java:
##########
@@ -44,7 +43,14 @@ public static Aggregate toAggregate(
rawTypes.add(inputType.getChildren().get(arg));
}
CallTypedExpr call = toCall(aggregateCall, inputType);
- return new Aggregate(call, rawTypes, null, List.of(), List.of(),
aggregateCall.isDistinct());
+ FieldAccessTypedExpr mask = null;
+ if (aggregateCall.hasFilter()) {
Review Comment:
Good catch that FILTER was being dropped. Could you add a small test for:
- a filter column that is null (Flink skips the row)
- FILTER combined with retraction (retraction rows must be filtered the same
way)
##########
gluten-flink/planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/stream/StreamExecGroupAggregate.java:
##########
@@ -198,13 +197,28 @@ protected Transformation<RowData> translateToPlanInternal(
.collect(Collectors.toList());
List<Integer> keyIndexes =
Arrays.stream(grouping).boxed().collect(Collectors.toList());
PartitionFunctionSpec keySelectorSpec = new
HashPartitionFunctionSpec(inputType, keyIndexes);
+ KeyedStateSpec keyedStateSpec =
+ new KeyedStateSpec(
+ keyIndexes,
+ keyIndexes.stream()
+ .map(keyIndex -> inputType.getChildren().get(keyIndex))
+ .collect(Collectors.toList()));
PlanNode aggsHandlerNode =
new GroupAggsHandlerNode(
- PlanNodeIdGenerator.newId(), outputType, generateUpdateBefore,
needRetraction);
+ PlanNodeIdGenerator.newId(),
+ inputType,
+ outputType,
+ aggregates,
+ generateUpdateBefore,
+ needRetraction);
// TODO: velox agg may not equal to flink
PlanNode aggregation =
new GroupAggregationNode(
Review Comment:
`stateRetentionTime` is computed above but not passed to the native
operator, so `table.exec.state.ttl` and the `STATE_TTL` hint are ignored and
state can grow without bound. Could we pass it through, or fail at plan time
when a TTL is set?
##########
gluten-flink/planner/src/main/java/org/apache/gluten/rexnode/AggregateCallConverter.java:
##########
@@ -90,10 +96,6 @@ private static CallTypedExpr toCall(
}
private static CallTypedExpr convertAggregation(String name, List<TypedExpr>
args, Type outType) {
- if (name.equals("AVG")) {
- return new CallTypedExpr(new DoubleType(), args, name.toLowerCase());
- } else {
- return new CallTypedExpr(outType, args, name.toLowerCase());
- }
+ return new CallTypedExpr(outType, args, name.toLowerCase());
Review Comment:
With the AVG to DOUBLE rewrite removed, this relies on the flinksql `avg` in
Velox returning Flink's result types (e.g. BIGINT for `AVG(BIGINT)`, and
matching DECIMAL precision/scale). Could you link the Velox test that covers
this?
--
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]