AlanConfluent commented on code in PR #26817:
URL: https://github.com/apache/flink/pull/26817#discussion_r4792298924


##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/correlate/async/AsyncCorrelateRunner.java:
##########
@@ -102,17 +115,24 @@ private JoinedRowResultFuture(
         @Override
         public void complete(Collection<Object> result) {
             try {
-                Collection<RowData> rightRows = 
wrapPrimitivesAndConvert(result);
-                completeResultFuture(rightRows);
+                completeResultFuture(result);
             } catch (Throwable t) {
                 realOutput.completeExceptionally(t);
             }
         }
 
-        private void completeResultFuture(Collection<RowData> rightRows) {
+        private void completeResultFuture(Collection<Object> result) {
             realOutput.complete(
                     () -> {
+                        Collection<RowData> rightRows = 
wrapPrimitivesAndConvert(result);
                         if (rightRows == null || rightRows.isEmpty()) {
+                            if (joinType == FlinkJoinType.LEFT) {

Review Comment:
   Missed that.  Good catch.  I have essentially changed the default retry 
function to see if it's a padded response, and if so, it will treat it as empty 
and retry.  Only after exhausting retries will it use the padded response.  I 
believe that's how lookup LEFT joins work as well.



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/runtime/stream/table/AsyncCorrelateITCase.java:
##########
@@ -269,6 +271,35 @@ public void testRetries() {
                 .hasRootCauseMessage("Error 9");
     }
 
+    @Test
+    public void testGroupBy() {

Review Comment:
   Right, that one was an inner join and never padded. It's now a left join 
over the GROUP BY where the first sum gets an empty result, so the padded -U 
has to keep its row kind.



##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/correlate/async/AsyncCorrelateRunner.java:
##########
@@ -102,17 +115,24 @@ private JoinedRowResultFuture(
         @Override
         public void complete(Collection<Object> result) {
             try {
-                Collection<RowData> rightRows = 
wrapPrimitivesAndConvert(result);
-                completeResultFuture(rightRows);
+                completeResultFuture(result);
             } catch (Throwable t) {
                 realOutput.completeExceptionally(t);
             }
         }
 
-        private void completeResultFuture(Collection<RowData> rightRows) {
+        private void completeResultFuture(Collection<Object> result) {
             realOutput.complete(
                     () -> {
+                        Collection<RowData> rightRows = 
wrapPrimitivesAndConvert(result);

Review Comment:
   It does.  I should probably have figured out how to get this noticed a while 
back.  
   
   I added a separate commit for this with it's own ticket referenced 
https://issues.apache.org/jira/browse/FLINK-41808.
   
   I also added a test in 
`AsyncCorrelateRunnerTest.testConvertsOnThreadRunningSupplier`.



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/runtime/stream/table/AsyncCorrelateITCase.java:
##########
@@ -269,6 +271,35 @@ public void testRetries() {
                 .hasRootCauseMessage("Error 9");
     }
 
+    @Test
+    public void testGroupBy() {
+        Table t1 = tEnv.fromValues(row(1, 1), row(2, 4), row(1, 2)).as("f1", 
"f2");
+        tEnv.createTemporaryView("t1", t1);
+        tEnv.createTemporarySystemFunction("func", new Add10TableFunction(-1));
+        final List<Row> results =
+                executeSql(
+                        "select f1, res FROM (SELECT f1, SUM(f2) as thesum 
FROM t1 group by f1), LATERAL TABLE(func(thesum)) t(res)");
+        final List<Row> expectedRows =
+                Arrays.asList(
+                        Row.of(1, 11),
+                        Row.of(2, 14),
+                        Row.ofKind(RowKind.UPDATE_BEFORE, 1, 11),
+                        Row.ofKind(RowKind.UPDATE_AFTER, 1, 13));
+        assertThat(results).containsSequence(expectedRows);
+    }
+
+    @Test
+    public void testLeftJoin() {
+        Table t1 = tEnv.fromValues(row(1), row(2), row(1)).as("f1");
+        tEnv.createTemporaryView("t1", t1);
+        tEnv.createTemporarySystemFunction("func", new Add10TableFunction(1));
+        final List<Row> results =
+                executeSql("select * FROM t1 LEFT OUTER JOIN LATERAL 
TABLE(func(f1)) ON TRUE");

Review Comment:
   Done.



##########
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/correlate/async/AsyncCorrelateRunner.java:
##########
@@ -102,17 +115,24 @@ private JoinedRowResultFuture(
         @Override
         public void complete(Collection<Object> result) {
             try {
-                Collection<RowData> rightRows = 
wrapPrimitivesAndConvert(result);
-                completeResultFuture(rightRows);
+                completeResultFuture(result);
             } catch (Throwable t) {
                 realOutput.completeExceptionally(t);
             }
         }
 
-        private void completeResultFuture(Collection<RowData> rightRows) {
+        private void completeResultFuture(Collection<Object> result) {
             realOutput.complete(
                     () -> {
+                        Collection<RowData> rightRows = 
wrapPrimitivesAndConvert(result);
                         if (rightRows == null || rightRows.isEmpty()) {
+                            if (joinType == FlinkJoinType.LEFT) {
+                                GenericRowData nulls =
+                                        new 
GenericRowData(resultType.getFieldCount());

Review Comment:
   Done



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