lincoln-lil commented on code in PR #21676:
URL: https://github.com/apache/flink/pull/21676#discussion_r1072009842


##########
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/operations/SqlToOperationConverter.java:
##########
@@ -1492,6 +1500,41 @@ private Operation convertStopJob(SqlStopJob sqlStopJob) {
                 sqlStopJob.getId(), sqlStopJob.isWithSavepoint(), 
sqlStopJob.isWithDrain());
     }
 
+    private Operation convertToDelete(SqlDelete sqlDelete) {
+        RelRoot updateRelational = flinkPlanner.rel(sqlDelete);
+        LogicalTableModify tableModify = (LogicalTableModify) 
updateRelational.rel;
+        UnresolvedIdentifier unresolvedTableIdentifier =
+                
UnresolvedIdentifier.of(tableModify.getTable().getQualifiedName());
+        ContextResolvedTable contextResolvedTable =
+                catalogManager.getTableOrError(
+                        
catalogManager.qualifyIdentifier(unresolvedTableIdentifier));
+        // try push down delete
+        Optional<DynamicTableSink> optionalDynamicTableSink =
+                DeletePushDownUtils.getDynamicTableSink(
+                        contextResolvedTable, tableModify, catalogManager);
+        if (optionalDynamicTableSink.isPresent()) {
+            DynamicTableSink dynamicTableSink = optionalDynamicTableSink.get();
+            // if the table sink supports delete push down
+            if (dynamicTableSink instanceof SupportsDeletePushDown) {
+                SupportsDeletePushDown supportsDeletePushDown =
+                        (SupportsDeletePushDown) dynamicTableSink;
+                // get resolved filter expression
+                Optional<List<ResolvedExpression>> filters =
+                        
DeletePushDownUtils.getResolveFilterExpressions(tableModify);
+                if (filters.isPresent()
+                        && 
supportsDeletePushDown.applyDeleteFilters(filters.get())) {
+                    return new 
DeleteFromFilterOperation(supportsDeletePushDown, filters.get());
+                }
+            }
+        }

Review Comment:
   the unified validation sounds good to me



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/runtime/batch/sql/DeleteTableITCase.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.table.planner.runtime.batch.sql;
+
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.StringData;
+import org.apache.flink.table.planner.factories.TestUpdateDeleteTableFactory;
+import org.apache.flink.table.planner.runtime.utils.BatchTestBase;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.CollectionUtil;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+/** The IT case for DELETE statement in batch mode. */
+public class DeleteTableITCase extends BatchTestBase {
+    private static final int ROW_NUM = 5;
+
+    @Test
+    public void testDeletePushDown() throws Exception {
+        String dataId = registerData();
+        tEnv().executeSql(
+                        String.format(
+                                "CREATE TABLE t (a int, b string, c double) 
WITH"
+                                        + " ('connector' = 
'test-update-delete',"
+                                        + " 'data-id' = '%s',"
+                                        + " 'only-accept-empty-filter' = 
'true'"
+                                        + ")",
+                                dataId));
+        List<Row> rows =
+                CollectionUtil.iteratorToList(tEnv().executeSql("DELETE FROM 
t").collect());
+        assertThat(rows.toString()).isEqualTo(String.format("[+I[%d], 
+I[OK]]", ROW_NUM));
+        rows = CollectionUtil.iteratorToList(tEnv().executeSql("SELECT * FROM 
t").collect());
+        assertThat(rows).isEmpty();
+
+        // should throw exception for non-empty filter
+        assertThatThrownBy(() -> tEnv().executeSql("DELETE FROM t where a = 
1"))

Review Comment:
   
   If I haven't missed it, we currently have no such test cases?
   
   and some thoughts for adding this case: for the delete scenarios, users may 
delete part of the data more offen? If they want to delete the whole table, I 
think `truncate` maybe the better choice.
   



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