lowka commented on code in PR #1798:
URL: https://github.com/apache/ignite-3/pull/1798#discussion_r1146329489


##########
modules/sql-engine/src/main/java/org/apache/ignite/internal/sql/engine/rule/TableModifyConverterRule.java:
##########
@@ -48,12 +67,63 @@ public TableModifyConverterRule() {
     @Override
     protected PhysicalNode convert(RelOptPlanner planner, RelMetadataQuery mq, 
LogicalTableModify rel) {
         RelOptCluster cluster = rel.getCluster();
+        RelOptTable relTable = rel.getTable();
+        IgniteTable igniteTable = relTable.unwrap(IgniteTable.class);
+        assert igniteTable != null;
+
         RelTraitSet traits = cluster.traitSetOf(IgniteConvention.INSTANCE)
-                .replace(IgniteDistributions.single())
+                .replace(igniteTable.distribution())
                 .replace(RelCollations.EMPTY);
+
         RelNode input = convert(rel.getInput(), traits);
 
-        return new IgniteTableModify(cluster, traits, rel.getTable(), input,
+        IgniteTableModify tableModify = new IgniteTableModify(cluster, traits, 
relTable, input,
                 rel.getOperation(), rel.getUpdateColumnList(), 
rel.getSourceExpressionList(), rel.isFlattened());
+
+        if (igniteTable.distribution().equals(IgniteDistributions.single())) {
+            return tableModify;
+        } else {
+            return createAggregate(tableModify, cluster);
+        }
+    }
+
+    private static PhysicalNode createAggregate(IgniteTableModify tableModify, 
RelOptCluster cluster) {
+
+        RelTraitSet inTrait = cluster.traitSetOf(IgniteConvention.INSTANCE);
+        RelTraitSet outTrait = cluster.traitSetOf(IgniteConvention.INSTANCE);
+
+        RelDataType rowType = tableModify.getRowType();
+        RelDataTypeFactory typeFactory = cluster.getTypeFactory();
+        RelDataType sumType = 
typeFactory.createTypeWithNullability(typeFactory.createSqlType(SqlTypeName.DECIMAL),
 true);
+        int aggCallCnt = rowType.getFieldCount();
+        List<AggregateCall> aggCalls = new ArrayList<>();
+
+        for (int i = 0; i < aggCallCnt; i++) {

Review Comment:
   @korlov42 Could you please point me how the RETURNING clause can be 
specified, since at the moment there is no support for `RETURNING` clause in 
neither Parser nor RelNodes (TableModify). I am 100% sure about the parser 
part, because it fails when you add a `RETURNING` clause.
   If is there a ticket for `RETURNING` clause, I would add a link to it here.



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