This is an automated email from the ASF dual-hosted git repository.

chengzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new ef5618b9357 Support copy statement sql bind and add bind test case 
(#34159)
ef5618b9357 is described below

commit ef5618b93575c892748748e8d2043476bf23db0e
Author: Zhengqiang Duan <[email protected]>
AuthorDate: Thu Dec 26 15:27:11 2024 +0800

    Support copy statement sql bind and add bind test case (#34159)
    
    * Support copy statement sql bind and add bind test case
    
    * update release note
---
 RELEASE-NOTES.md                                   |   3 +-
 .../sql/dml/ShardingCopySupportedChecker.java      |   4 +-
 .../sql/dml/ShardingCopySupportedCheckerTest.java  |   6 +-
 .../statement/dml/CopyStatementContext.java        |   7 +-
 .../infra/binder/engine/segment/SegmentType.java   |   2 +-
 .../PrepareStatementQuerySegmentBinder.java        |  50 ++++++++++
 .../engine/statement/dml/CopyStatementBinder.java  |  56 +++++++++++
 .../binder/engine/type/DMLStatementBindEngine.java |   5 +
 .../type/OpenGaussDMLStatementVisitor.java         |   2 +-
 .../type/PostgreSQLDMLStatementVisitor.java        |   6 +-
 .../core/statement/dml/CopyStatement.java          |  19 +++-
 .../binder/src/test/resources/cases/dml/copy.xml   | 105 +++++++++++++++++++++
 .../it/binder/src/test/resources/sqls/dml/copy.xml |  22 +++++
 .../statement/dml/impl/CopyStatementAssert.java    |   6 +-
 14 files changed, 277 insertions(+), 16 deletions(-)

diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md
index 0a0a6614430..02663ad74b9 100644
--- a/RELEASE-NOTES.md
+++ b/RELEASE-NOTES.md
@@ -41,7 +41,8 @@
 1. SQL Binder: Support select with statement sql bind and add bind test case - 
[#34141](https://github.com/apache/shardingsphere/pull/34141)
 1. SQL Binder: Support sql bind for select with current select projection 
reference - [#34151](https://github.com/apache/shardingsphere/pull/34151)
 1. SQL Binder: Support alter table, drop table sql bind and add test case - 
[#34154](https://github.com/apache/shardingsphere/pull/34154)
-1. Support rename table statement sql bind and split segment bind to ddl and 
dml package - [#34158](https://github.com/apache/shardingsphere/pull/34158)
+1. SQL Binder: Support rename table statement sql bind and split segment bind 
to ddl and dml package - 
[#34158](https://github.com/apache/shardingsphere/pull/34158)
+1. SQL Binder: Support copy statement sql bind and add bind test case - 
[#34159](https://github.com/apache/shardingsphere/pull/34159)
 
 ### Bug Fixes
 
diff --git 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedChecker.java
 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedChecker.java
index e619365e0fd..419db60f630 100644
--- 
a/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedChecker.java
+++ 
b/features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedChecker.java
@@ -35,12 +35,12 @@ public final class ShardingCopySupportedChecker implements 
SupportedSQLChecker<C
     
     @Override
     public boolean isCheck(final SQLStatementContext sqlStatementContext) {
-        return sqlStatementContext instanceof CopyStatementContext;
+        return sqlStatementContext instanceof CopyStatementContext && 
((CopyStatementContext) 
sqlStatementContext).getSqlStatement().getTable().isPresent();
     }
     
     @Override
     public void check(final ShardingRule rule, final ShardingSphereDatabase 
database, final ShardingSphereSchema currentSchema, final CopyStatementContext 
sqlStatementContext) {
-        String tableName = 
sqlStatementContext.getSqlStatement().getTableSegment().getTableName().getIdentifier().getValue();
+        String tableName = 
sqlStatementContext.getSqlStatement().getTable().map(optional -> 
optional.getTableName().getIdentifier().getValue()).orElse("");
         
ShardingSpherePreconditions.checkState(!rule.isShardingTable(tableName), () -> 
new UnsupportedShardingOperationException("COPY", tableName));
     }
 }
diff --git 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java
 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java
index 9b15a14b9f5..10c37fdb4ee 100644
--- 
a/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java
+++ 
b/features/sharding/core/src/test/java/org/apache/shardingsphere/sharding/checker/sql/dml/ShardingCopySupportedCheckerTest.java
@@ -45,14 +45,14 @@ class ShardingCopySupportedCheckerTest {
     @Test
     void assertCheckWhenTableSegmentForPostgreSQL() {
         PostgreSQLCopyStatement sqlStatement = new PostgreSQLCopyStatement();
-        sqlStatement.setTableSegment(new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("t_order"))));
+        sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 
0, new IdentifierValue("t_order"))));
         assertDoesNotThrow(() -> new 
ShardingCopySupportedChecker().check(rule, mock(), mock(), new 
CopyStatementContext(sqlStatement)));
     }
     
     @Test
     void assertCheckWhenTableSegmentForOpenGauss() {
         OpenGaussCopyStatement sqlStatement = new OpenGaussCopyStatement();
-        sqlStatement.setTableSegment(new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("t_order"))));
+        sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 
0, new IdentifierValue("t_order"))));
         assertDoesNotThrow(() -> new 
ShardingCopySupportedChecker().check(rule, mock(), mock(), new 
CopyStatementContext(sqlStatement)));
     }
     
@@ -67,7 +67,7 @@ class ShardingCopySupportedCheckerTest {
     }
     
     private void assertCheckCopyTable(final CopyStatement sqlStatement) {
-        sqlStatement.setTableSegment(new SimpleTableSegment(new 
TableNameSegment(0, 0, new IdentifierValue("t_order"))));
+        sqlStatement.setTable(new SimpleTableSegment(new TableNameSegment(0, 
0, new IdentifierValue("t_order"))));
         CopyStatementContext sqlStatementContext = new 
CopyStatementContext(sqlStatement);
         String tableName = "t_order";
         when(rule.isShardingTable(tableName)).thenReturn(true);
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/CopyStatementContext.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/CopyStatementContext.java
index ce39780ad48..5d2f8c6db8d 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/CopyStatementContext.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/context/statement/dml/CopyStatementContext.java
@@ -21,8 +21,12 @@ import lombok.Getter;
 import 
org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
 import 
org.apache.shardingsphere.infra.binder.context.statement.CommonSQLStatementContext;
 import org.apache.shardingsphere.infra.binder.context.type.TableAvailable;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.generic.table.SimpleTableSegment;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.CopyStatement;
 
+import java.util.Collection;
+import java.util.Collections;
+
 /**
  * Copy statement context.
  */
@@ -33,7 +37,8 @@ public final class CopyStatementContext extends 
CommonSQLStatementContext implem
     
     public CopyStatementContext(final CopyStatement sqlStatement) {
         super(sqlStatement);
-        tablesContext = new TablesContext(sqlStatement.getTableSegment());
+        Collection<SimpleTableSegment> tables = 
sqlStatement.getTable().isPresent() ? 
Collections.singleton(sqlStatement.getTable().get()) : Collections.emptyList();
+        tablesContext = new TablesContext(tables);
     }
     
     @Override
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/SegmentType.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/SegmentType.java
index 6cd02df131a..6ca1204fb71 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/SegmentType.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/SegmentType.java
@@ -22,5 +22,5 @@ package org.apache.shardingsphere.infra.binder.engine.segment;
  */
 public enum SegmentType {
     
-    PROJECTION, PREDICATE, JOIN_ON, JOIN_USING, ORDER_BY, GROUP_BY, LOCK, 
SET_ASSIGNMENT, VALUES, INSERT_COLUMNS, DEFINITION_COLUMNS
+    PROJECTION, PREDICATE, JOIN_ON, JOIN_USING, ORDER_BY, GROUP_BY, LOCK, 
SET_ASSIGNMENT, VALUES, COPY, INSERT_COLUMNS, DEFINITION_COLUMNS
 }
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/prepare/PrepareStatementQuerySegmentBinder.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/prepare/PrepareStatementQuerySegmentBinder.java
new file mode 100644
index 00000000000..73c3d92d9e9
--- /dev/null
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/segment/dml/prepare/PrepareStatementQuerySegmentBinder.java
@@ -0,0 +1,50 @@
+/*
+ * 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.shardingsphere.infra.binder.engine.segment.dml.prepare;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import 
org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
+import 
org.apache.shardingsphere.infra.binder.engine.statement.dml.DeleteStatementBinder;
+import 
org.apache.shardingsphere.infra.binder.engine.statement.dml.InsertStatementBinder;
+import 
org.apache.shardingsphere.infra.binder.engine.statement.dml.SelectStatementBinder;
+import 
org.apache.shardingsphere.infra.binder.engine.statement.dml.UpdateStatementBinder;
+import 
org.apache.shardingsphere.sql.parser.statement.core.segment.dml.prepare.PrepareStatementQuerySegment;
+
+/**
+ * Prepare statement query segment binder.
+ */
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class PrepareStatementQuerySegmentBinder {
+    
+    /**
+     * Bind prepare statement query segment.
+     *
+     * @param segment prepare statement query segment
+     * @param binderContext SQL statement binder context
+     * @return bound prepare statement query segment
+     */
+    public static PrepareStatementQuerySegment bind(final 
PrepareStatementQuerySegment segment, final SQLStatementBinderContext 
binderContext) {
+        PrepareStatementQuerySegment result = new 
PrepareStatementQuerySegment(segment.getStartIndex(), segment.getStopIndex());
+        segment.getSelect().ifPresent(optional -> result.setSelect(new 
SelectStatementBinder().bind(optional, binderContext)));
+        segment.getInsert().ifPresent(optional -> result.setInsert(new 
InsertStatementBinder().bind(optional, binderContext)));
+        segment.getUpdate().ifPresent(optional -> result.setUpdate(new 
UpdateStatementBinder().bind(optional, binderContext)));
+        segment.getDelete().ifPresent(optional -> result.setDelete(new 
DeleteStatementBinder().bind(optional, binderContext)));
+        return result;
+    }
+}
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/CopyStatementBinder.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/CopyStatementBinder.java
new file mode 100644
index 00000000000..6f69d87d4c1
--- /dev/null
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/statement/dml/CopyStatementBinder.java
@@ -0,0 +1,56 @@
+/*
+ * 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.shardingsphere.infra.binder.engine.statement.dml;
+
+import com.cedarsoftware.util.CaseInsensitiveMap.CaseInsensitiveString;
+import com.google.common.collect.LinkedHashMultimap;
+import com.google.common.collect.Multimap;
+import lombok.SneakyThrows;
+import org.apache.shardingsphere.infra.binder.engine.segment.SegmentType;
+import 
org.apache.shardingsphere.infra.binder.engine.segment.dml.expression.type.ColumnSegmentBinder;
+import 
org.apache.shardingsphere.infra.binder.engine.segment.dml.from.context.TableSegmentBinderContext;
+import 
org.apache.shardingsphere.infra.binder.engine.segment.dml.from.type.SimpleTableSegmentBinder;
+import 
org.apache.shardingsphere.infra.binder.engine.segment.dml.prepare.PrepareStatementQuerySegmentBinder;
+import 
org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinder;
+import 
org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
+import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.CopyStatement;
+
+/**
+ * Copy statement binder.
+ */
+public final class CopyStatementBinder implements 
SQLStatementBinder<CopyStatement> {
+    
+    @Override
+    public CopyStatement bind(final CopyStatement sqlStatement, final 
SQLStatementBinderContext binderContext) {
+        CopyStatement result = copy(sqlStatement);
+        Multimap<CaseInsensitiveString, TableSegmentBinderContext> 
tableBinderContexts = LinkedHashMultimap.create();
+        sqlStatement.getTable().ifPresent(optional -> 
result.setTable(SimpleTableSegmentBinder.bind(optional, binderContext, 
tableBinderContexts)));
+        sqlStatement.getPrepareStatementQuery().ifPresent(optional -> 
result.setPrepareStatementQuery(PrepareStatementQuerySegmentBinder.bind(optional,
 binderContext)));
+        sqlStatement.getColumns().forEach(each -> 
result.getColumns().add(ColumnSegmentBinder.bind(each, SegmentType.COPY, 
binderContext, tableBinderContexts, LinkedHashMultimap.create())));
+        return result;
+    }
+    
+    @SneakyThrows(ReflectiveOperationException.class)
+    private CopyStatement copy(final CopyStatement sqlStatement) {
+        CopyStatement result = 
sqlStatement.getClass().getDeclaredConstructor().newInstance();
+        
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments());
+        result.getCommentSegments().addAll(sqlStatement.getCommentSegments());
+        result.getVariableNames().addAll(sqlStatement.getVariableNames());
+        return result;
+    }
+}
diff --git 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DMLStatementBindEngine.java
 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DMLStatementBindEngine.java
index b164c09bb49..dacb5483c1e 100644
--- 
a/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DMLStatementBindEngine.java
+++ 
b/infra/binder/src/main/java/org/apache/shardingsphere/infra/binder/engine/type/DMLStatementBindEngine.java
@@ -19,12 +19,14 @@ package org.apache.shardingsphere.infra.binder.engine.type;
 
 import lombok.RequiredArgsConstructor;
 import 
org.apache.shardingsphere.infra.binder.engine.statement.SQLStatementBinderContext;
+import 
org.apache.shardingsphere.infra.binder.engine.statement.dml.CopyStatementBinder;
 import 
org.apache.shardingsphere.infra.binder.engine.statement.dml.DeleteStatementBinder;
 import 
org.apache.shardingsphere.infra.binder.engine.statement.dml.InsertStatementBinder;
 import 
org.apache.shardingsphere.infra.binder.engine.statement.dml.SelectStatementBinder;
 import 
org.apache.shardingsphere.infra.binder.engine.statement.dml.UpdateStatementBinder;
 import org.apache.shardingsphere.infra.hint.HintValueContext;
 import org.apache.shardingsphere.infra.metadata.ShardingSphereMetaData;
+import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.CopyStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DMLStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.DeleteStatement;
 import 
org.apache.shardingsphere.sql.parser.statement.core.statement.dml.InsertStatement;
@@ -63,6 +65,9 @@ public final class DMLStatementBindEngine {
         if (statement instanceof DeleteStatement) {
             return new DeleteStatementBinder().bind((DeleteStatement) 
statement, binderContext);
         }
+        if (statement instanceof CopyStatement) {
+            return new CopyStatementBinder().bind((CopyStatement) statement, 
binderContext);
+        }
         return statement;
     }
 }
diff --git 
a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDMLStatementVisitor.java
 
b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDMLStatementVisitor.java
index fe0c53ae243..cc2fa84df47 100644
--- 
a/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDMLStatementVisitor.java
+++ 
b/parser/sql/dialect/opengauss/src/main/java/org/apache/shardingsphere/sql/parser/opengauss/visitor/statement/type/OpenGaussDMLStatementVisitor.java
@@ -50,7 +50,7 @@ public final class OpenGaussDMLStatementVisitor extends 
OpenGaussStatementVisito
     public ASTNode visitCopy(final CopyContext ctx) {
         OpenGaussCopyStatement result = new OpenGaussCopyStatement();
         if (null != ctx.qualifiedName()) {
-            result.setTableSegment((SimpleTableSegment) 
visit(ctx.qualifiedName()));
+            result.setTable((SimpleTableSegment) visit(ctx.qualifiedName()));
         }
         return result;
     }
diff --git 
a/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDMLStatementVisitor.java
 
b/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDMLStatementVisitor.java
index ff919ad01c4..ce5187ac346 100644
--- 
a/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDMLStatementVisitor.java
+++ 
b/parser/sql/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/type/PostgreSQLDMLStatementVisitor.java
@@ -98,7 +98,7 @@ public final class PostgreSQLDMLStatementVisitor extends 
PostgreSQLStatementVisi
     public ASTNode visitCopyWithTableOrQuery(final CopyWithTableOrQueryContext 
ctx) {
         PostgreSQLCopyStatement result = new PostgreSQLCopyStatement();
         if (null != ctx.qualifiedName()) {
-            result.setTableSegment((SimpleTableSegment) 
visit(ctx.qualifiedName()));
+            result.setTable((SimpleTableSegment) visit(ctx.qualifiedName()));
             if (null != ctx.columnNames()) {
                 result.getColumns().addAll(((CollectionValue<ColumnSegment>) 
visit(ctx.columnNames())).getValue());
             }
@@ -127,7 +127,7 @@ public final class PostgreSQLDMLStatementVisitor extends 
PostgreSQLStatementVisi
     public ASTNode visitCopyWithTableOrQueryBinaryCsv(final 
CopyWithTableOrQueryBinaryCsvContext ctx) {
         PostgreSQLCopyStatement result = new PostgreSQLCopyStatement();
         if (null != ctx.qualifiedName()) {
-            result.setTableSegment((SimpleTableSegment) 
visit(ctx.qualifiedName()));
+            result.setTable((SimpleTableSegment) visit(ctx.qualifiedName()));
             if (null != ctx.columnNames()) {
                 result.getColumns().addAll(((CollectionValue<ColumnSegment>) 
visit(ctx.columnNames())).getValue());
             }
@@ -142,7 +142,7 @@ public final class PostgreSQLDMLStatementVisitor extends 
PostgreSQLStatementVisi
     public ASTNode visitCopyWithTableBinary(final CopyWithTableBinaryContext 
ctx) {
         PostgreSQLCopyStatement result = new PostgreSQLCopyStatement();
         if (null != ctx.qualifiedName()) {
-            result.setTableSegment((SimpleTableSegment) 
visit(ctx.qualifiedName()));
+            result.setTable((SimpleTableSegment) visit(ctx.qualifiedName()));
         }
         return result;
     }
diff --git 
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dml/CopyStatement.java
 
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dml/CopyStatement.java
index 3ae2d1673fd..67912be7a64 100644
--- 
a/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dml/CopyStatement.java
+++ 
b/parser/sql/statement/core/src/main/java/org/apache/shardingsphere/sql/parser/statement/core/statement/dml/CopyStatement.java
@@ -35,7 +35,24 @@ import java.util.Optional;
 @Setter
 public abstract class CopyStatement extends AbstractSQLStatement implements 
DMLStatement {
     
-    private SimpleTableSegment tableSegment;
+    private SimpleTableSegment table;
+    
+    /**
+     * Get table.
+     *
+     * @return table
+     */
+    public Optional<SimpleTableSegment> getTable() {
+        return Optional.ofNullable(table);
+    }
+    
+    /**
+     * Set prepare statement query segment.
+     *
+     * @param prepareStatementQuery prepare statement query segment
+     */
+    public void setPrepareStatementQuery(final PrepareStatementQuerySegment 
prepareStatementQuery) {
+    }
     
     /**
      * Get prepare statement query segment.
diff --git a/test/it/binder/src/test/resources/cases/dml/copy.xml 
b/test/it/binder/src/test/resources/cases/dml/copy.xml
new file mode 100644
index 00000000000..06c673a4198
--- /dev/null
+++ b/test/it/binder/src/test/resources/cases/dml/copy.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<sql-parser-test-cases>
+    <copy sql-case-id="copy_from_table_column">
+        <table name="t_order" start-index="5" stop-index="11">
+            <table-bound>
+                <original-database name="foo_db_1" />
+                <original-schema name="public" />
+            </table-bound>
+        </table>
+        <column name="order_id" start-index="13" stop-index="20" />
+        <column name="user_id" start-index="23" stop-index="29" />
+    </copy>
+
+    <copy sql-case-id="copy_from_query">
+        <query start-index="6" stop-index="26">
+            <select>
+                <projections start-index="13" stop-index="13">
+                    <shorthand-projection start-index="13" stop-index="13">
+                        <actual-projections>
+                            <column-projection name="order_id" start-index="0" 
stop-index="0" start-delimiter="&quot;" end-delimiter="&quot;">
+                                <owner name="t_order" start-index="0" 
stop-index="0" />
+                                <column-bound>
+                                    <original-database name="foo_db_1" />
+                                    <original-schema name="public" />
+                                    <original-table name="t_order" />
+                                    <original-column name="order_id" 
start-delimiter="&quot;" end-delimiter="&quot;" />
+                                </column-bound>
+                            </column-projection>
+                            <column-projection name="user_id" start-index="0" 
stop-index="0" start-delimiter="&quot;" end-delimiter="&quot;">
+                                <owner name="t_order" start-index="0" 
stop-index="0" />
+                                <column-bound>
+                                    <original-database name="foo_db_1" />
+                                    <original-schema name="public" />
+                                    <original-table name="t_order" />
+                                    <original-column name="user_id" 
start-delimiter="&quot;" end-delimiter="&quot;" />
+                                </column-bound>
+                            </column-projection>
+                            <column-projection name="status" start-index="0" 
stop-index="0" start-delimiter="&quot;" end-delimiter="&quot;">
+                                <owner name="t_order" start-index="0" 
stop-index="0" />
+                                <column-bound>
+                                    <original-database name="foo_db_1" />
+                                    <original-schema name="public" />
+                                    <original-table name="t_order" />
+                                    <original-column name="status" 
start-delimiter="&quot;" end-delimiter="&quot;" />
+                                </column-bound>
+                            </column-projection>
+                            <column-projection name="merchant_id" 
start-index="0" stop-index="0" start-delimiter="&quot;" end-delimiter="&quot;">
+                                <owner name="t_order" start-index="0" 
stop-index="0" />
+                                <column-bound>
+                                    <original-database name="foo_db_1" />
+                                    <original-schema name="public" />
+                                    <original-table name="t_order" />
+                                    <original-column name="merchant_id" 
start-delimiter="&quot;" end-delimiter="&quot;" />
+                                </column-bound>
+                            </column-projection>
+                            <column-projection name="remark" start-index="0" 
stop-index="0" start-delimiter="&quot;" end-delimiter="&quot;">
+                                <owner name="t_order" start-index="0" 
stop-index="0" />
+                                <column-bound>
+                                    <original-database name="foo_db_1" />
+                                    <original-schema name="public" />
+                                    <original-table name="t_order" />
+                                    <original-column name="remark" 
start-delimiter="&quot;" end-delimiter="&quot;" />
+                                </column-bound>
+                            </column-projection>
+                            <column-projection name="creation_date" 
start-index="0" stop-index="0" start-delimiter="&quot;" end-delimiter="&quot;">
+                                <owner name="t_order" start-index="0" 
stop-index="0" />
+                                <column-bound>
+                                    <original-database name="foo_db_1" />
+                                    <original-schema name="public" />
+                                    <original-table name="t_order" />
+                                    <original-column name="creation_date" 
start-delimiter="&quot;" end-delimiter="&quot;" />
+                                </column-bound>
+                            </column-projection>
+                        </actual-projections>
+                    </shorthand-projection>
+                </projections>
+                <from>
+                    <simple-table name="t_order" start-index="20" 
stop-index="26">
+                        <table-bound>
+                            <original-database name="foo_db_1" />
+                            <original-schema name="public" />
+                        </table-bound>
+                    </simple-table>
+                </from>
+            </select>
+        </query>
+    </copy>
+</sql-parser-test-cases>
diff --git a/test/it/binder/src/test/resources/sqls/dml/copy.xml 
b/test/it/binder/src/test/resources/sqls/dml/copy.xml
new file mode 100644
index 00000000000..994ffd39c84
--- /dev/null
+++ b/test/it/binder/src/test/resources/sqls/dml/copy.xml
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<sql-cases>
+    <sql-case id="copy_from_table_column" value="COPY t_order(order_id, 
user_id) TO 'file.txt' DELIMITER ','" db-types="PostgreSQL"/>
+    <sql-case id="copy_from_query" value="COPY (SELECT * FROM t_order) TO 
STDOUT" db-types="PostgreSQL"/>
+</sql-cases>
diff --git 
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dml/impl/CopyStatementAssert.java
 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dml/impl/CopyStatementAssert.java
index 8cd762a4665..61116c2d451 100644
--- 
a/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dml/impl/CopyStatementAssert.java
+++ 
b/test/it/parser/src/main/java/org/apache/shardingsphere/test/it/sql/parser/internal/asserts/statement/dml/impl/CopyStatementAssert.java
@@ -32,7 +32,6 @@ import java.util.Collection;
 import java.util.Optional;
 
 import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNull;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
 /**
@@ -56,9 +55,10 @@ public final class CopyStatementAssert {
     
     private static void assertTable(final SQLCaseAssertContext assertContext, 
final CopyStatement actual, final CopyStatementTestCase expected) {
         if (null == expected.getTable()) {
-            assertNull(actual.getTableSegment(), assertContext.getText("Actual 
table should not exist."));
+            assertFalse(actual.getTable().isPresent(), 
assertContext.getText("Actual table should not exist."));
         } else {
-            TableAssert.assertIs(assertContext, actual.getTableSegment(), 
expected.getTable());
+            assertTrue(actual.getTable().isPresent(), 
assertContext.getText("Actual table should exist."));
+            TableAssert.assertIs(assertContext, actual.getTable().get(), 
expected.getTable());
         }
     }
     

Reply via email to