Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the definition position of the create table SelectStatement class #28808

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import org.apache.shardingsphere.sql.parser.sql.common.segment.ddl.constraint.ConstraintDefinitionSegment;
import org.apache.shardingsphere.sql.parser.sql.common.segment.generic.table.SimpleTableSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.AbstractSQLStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;

import java.util.Collection;
import java.util.LinkedList;
import java.util.Optional;

/**
* Create table statement.
Expand All @@ -36,7 +38,18 @@ public abstract class CreateTableStatement extends AbstractSQLStatement implemen

private SimpleTableSegment table;

private SelectStatement selectStatement;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move selectStatement to CreateTableStatement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, mentor. When analyzing the SQL format of "CREATE TABLE AS SELECT" statement in MySQL, I found that Oracle, SQL Server, OpenGauss, and PostgreSQL all support similar SQL formats. The SelectStatement is currently defined in the SQLServerCreateTableStatement. Should we move the SelectStatement to the CreateTableStatement class for definition?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, commen segment should be moved to super class.


private final Collection<ColumnDefinitionSegment> columnDefinitions = new LinkedList<>();

private final Collection<ConstraintDefinitionSegment> constraintDefinitions = new LinkedList<>();

/**
* Get select statement.
*
* @return select statement
*/
public Optional<SelectStatement> getSelectStatement() {
return Optional.ofNullable(selectStatement);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@
import lombok.Setter;
import org.apache.shardingsphere.sql.parser.sql.common.segment.dml.column.ColumnSegment;
import org.apache.shardingsphere.sql.parser.sql.common.statement.ddl.CreateTableStatement;
import org.apache.shardingsphere.sql.parser.sql.common.statement.dml.SelectStatement;
import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.SQLServerStatement;

import java.util.LinkedList;
import java.util.List;
import java.util.Optional;

/**
* SQLServer create table statement.
Expand All @@ -36,15 +34,4 @@
public final class SQLServerCreateTableStatement extends CreateTableStatement implements SQLServerStatement {

private final List<ColumnSegment> columns = new LinkedList<>();

private SelectStatement selectStatement;

/**
* Get select statement.
*
* @return select statement
*/
public Optional<SelectStatement> getSelectStatement() {
return Optional.ofNullable(selectStatement);
}
}