You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/10/08 00:57:49 UTC

[GitHub] [incubator-doris] WingsGo opened a new pull request #4705: [CREATE TABLE]Support new syntax CREATE TABLE LIKE to clone an existe…

WingsGo opened a new pull request #4705:
URL: https://github.com/apache/incubator-doris/pull/4705


   ## Proposed changes
   
   Support new synatx `CREATE TABLE [IF NOT EXISTS] [db_name].table_name AS [db_name2].table_name2;` to create a new table from existed table with same table schema.Ref ISSUE: #4355 
   
   ## Types of changes
   
   What types of changes does your code introduce to Doris?
   _Put an `x` in the boxes that apply_
   
   - [] Bugfix (non-breaking change which fixes an issue)
   - [x] New feature (non-breaking change which adds functionality)
   - [] Breaking change (fix or feature that would cause existing functionality to not work as expected)
   - [] Documentation Update (if none of the other choices apply)
   - [] Code refactor (Modify the code structure, format the code, etc...)
   
   ## Checklist
   
   _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._
   
   - [x] I have create an issue on (Fix #ISSUE), and have described the bug/feature there in detail
   - [x] Compiling and unit tests pass locally with my changes
   - [x] I have added tests that prove my fix is effective or that my feature works
   - [] If this change need a document change, I have updated the document
   - [x] Any dependent changes have been merged
   
   ## Further comments
   
   If this is a relatively large or complex change, kick off the discussion at dev@doris.apache.org by explaining why you chose the solution you did and what alternatives you considered, etc...
   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] WingsGo commented on a change in pull request #4705: [CREATE TABLE]Support new syntax CREATE TABLE LIKE to clone an existe…

Posted by GitBox <gi...@apache.org>.
WingsGo commented on a change in pull request #4705:
URL: https://github.com/apache/incubator-doris/pull/4705#discussion_r501868667



##########
File path: fe/fe-core/src/main/cup/sql_parser.cup
##########
@@ -1128,6 +1128,10 @@ create_stmt ::=
         RESULT = new CreateTableStmt(ifNotExists, isExternal, name, columns, indexes, engineName, keys, partition,
         distribution, tblProperties, extProperties, tableComment, index);
     :}
+    | KW_CREATE opt_external:isExternal KW_TABLE opt_if_not_exists:ifNotExists table_name:name KW_LIKE table_name:existed_name

Review comment:
       yes, it is unnecessary, but if I remove it, it will cause shift/reduce conflict, maybe you can help me how to fix it?

##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableLikeStmt.java
##########
@@ -0,0 +1,130 @@
+// 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.doris.analysis;
+
+import com.google.common.collect.Lists;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.FeNameFormat;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.SqlParserUtils;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+
+/**
+ * @author wangcong
+ * @version 1.0
+ * @date 2020/10/7 10:32 上午
+ */
+public class CreateTableLikeStmt extends DdlStmt {
+    private static final Logger LOG = LogManager.getLogger(CreateTableLikeStmt.class);
+
+    private CreateTableStmt parsedCreateTableStmt;
+    private final boolean isExternal;
+    private final boolean ifNotExists;
+    private final TableName tableName;
+    private final TableName existedTableName;
+
+    public CreateTableLikeStmt(boolean ifNotExists, boolean isExternal, TableName tableName, TableName existedTableName) {
+        this.ifNotExists = ifNotExists;
+        this.isExternal = isExternal;
+        this.tableName = tableName;
+        this.existedTableName = existedTableName;
+    }
+
+    public boolean isSetIfNotExists() {
+        return ifNotExists;
+    }
+
+    public boolean isExternal() {
+        return isExternal;
+    }
+
+    public String getDbName() {
+        return tableName.getDb();
+    }
+
+    public String getTableName() {
+        return tableName.getTbl();
+    }
+
+    public String getExistedDbName() {
+        return existedTableName.getDb();
+    }
+
+    public String getExistedTableName() {
+        return existedTableName.getTbl();
+    }
+
+    public CreateTableStmt getParsedCreateTableStmt() {
+        return parsedCreateTableStmt;
+    }
+
+    @Override
+    public void analyze(Analyzer analyzer) throws UserException {
+        super.analyze(analyzer);
+        existedTableName.analyze(analyzer);
+        ConnectContext ctx = ConnectContext.get();
+        if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ctx, existedTableName.getDb(),
+                existedTableName.getTbl(), PrivPredicate.SELECT)) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "SELECT");
+        }
+
+        tableName.analyze(analyzer);
+        FeNameFormat.checkTableName(getTableName());
+        if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ctx, tableName.getDb(),
+                tableName.getTbl(), PrivPredicate.CREATE)) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "CREATE");
+        }
+
+        Database db = Catalog.getCurrentCatalog().getDb(getExistedDbName());

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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] WingsGo commented on a change in pull request #4705: [CREATE TABLE]Support new syntax CREATE TABLE LIKE to clone an existe…

Posted by GitBox <gi...@apache.org>.
WingsGo commented on a change in pull request #4705:
URL: https://github.com/apache/incubator-doris/pull/4705#discussion_r501868667



##########
File path: fe/fe-core/src/main/cup/sql_parser.cup
##########
@@ -1128,6 +1128,10 @@ create_stmt ::=
         RESULT = new CreateTableStmt(ifNotExists, isExternal, name, columns, indexes, engineName, keys, partition,
         distribution, tblProperties, extProperties, tableComment, index);
     :}
+    | KW_CREATE opt_external:isExternal KW_TABLE opt_if_not_exists:ifNotExists table_name:name KW_LIKE table_name:existed_name

Review comment:
       yes, it is unnecessary, but if I remove it, it will cause shift/reduce conflict, maybe you can help me how to fix it?

##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableLikeStmt.java
##########
@@ -0,0 +1,130 @@
+// 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.doris.analysis;
+
+import com.google.common.collect.Lists;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.FeNameFormat;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.SqlParserUtils;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+
+/**
+ * @author wangcong
+ * @version 1.0
+ * @date 2020/10/7 10:32 上午
+ */
+public class CreateTableLikeStmt extends DdlStmt {
+    private static final Logger LOG = LogManager.getLogger(CreateTableLikeStmt.class);
+
+    private CreateTableStmt parsedCreateTableStmt;
+    private final boolean isExternal;
+    private final boolean ifNotExists;
+    private final TableName tableName;
+    private final TableName existedTableName;
+
+    public CreateTableLikeStmt(boolean ifNotExists, boolean isExternal, TableName tableName, TableName existedTableName) {
+        this.ifNotExists = ifNotExists;
+        this.isExternal = isExternal;
+        this.tableName = tableName;
+        this.existedTableName = existedTableName;
+    }
+
+    public boolean isSetIfNotExists() {
+        return ifNotExists;
+    }
+
+    public boolean isExternal() {
+        return isExternal;
+    }
+
+    public String getDbName() {
+        return tableName.getDb();
+    }
+
+    public String getTableName() {
+        return tableName.getTbl();
+    }
+
+    public String getExistedDbName() {
+        return existedTableName.getDb();
+    }
+
+    public String getExistedTableName() {
+        return existedTableName.getTbl();
+    }
+
+    public CreateTableStmt getParsedCreateTableStmt() {
+        return parsedCreateTableStmt;
+    }
+
+    @Override
+    public void analyze(Analyzer analyzer) throws UserException {
+        super.analyze(analyzer);
+        existedTableName.analyze(analyzer);
+        ConnectContext ctx = ConnectContext.get();
+        if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ctx, existedTableName.getDb(),
+                existedTableName.getTbl(), PrivPredicate.SELECT)) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "SELECT");
+        }
+
+        tableName.analyze(analyzer);
+        FeNameFormat.checkTableName(getTableName());
+        if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ctx, tableName.getDb(),
+                tableName.getTbl(), PrivPredicate.CREATE)) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "CREATE");
+        }
+
+        Database db = Catalog.getCurrentCatalog().getDb(getExistedDbName());

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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] morningman commented on a change in pull request #4705: [CREATE TABLE]Support new syntax CREATE TABLE LIKE to clone an existe…

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #4705:
URL: https://github.com/apache/incubator-doris/pull/4705#discussion_r501756194



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableLikeStmt.java
##########
@@ -0,0 +1,130 @@
+// 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.doris.analysis;
+
+import com.google.common.collect.Lists;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.FeNameFormat;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.SqlParserUtils;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+
+/**
+ * @author wangcong
+ * @version 1.0
+ * @date 2020/10/7 10:32 上午
+ */
+public class CreateTableLikeStmt extends DdlStmt {
+    private static final Logger LOG = LogManager.getLogger(CreateTableLikeStmt.class);
+
+    private CreateTableStmt parsedCreateTableStmt;
+    private final boolean isExternal;
+    private final boolean ifNotExists;
+    private final TableName tableName;
+    private final TableName existedTableName;
+
+    public CreateTableLikeStmt(boolean ifNotExists, boolean isExternal, TableName tableName, TableName existedTableName) {
+        this.ifNotExists = ifNotExists;
+        this.isExternal = isExternal;
+        this.tableName = tableName;
+        this.existedTableName = existedTableName;
+    }
+
+    public boolean isSetIfNotExists() {
+        return ifNotExists;
+    }
+
+    public boolean isExternal() {
+        return isExternal;
+    }
+
+    public String getDbName() {
+        return tableName.getDb();
+    }
+
+    public String getTableName() {
+        return tableName.getTbl();
+    }
+
+    public String getExistedDbName() {
+        return existedTableName.getDb();
+    }
+
+    public String getExistedTableName() {
+        return existedTableName.getTbl();
+    }
+
+    public CreateTableStmt getParsedCreateTableStmt() {
+        return parsedCreateTableStmt;
+    }
+
+    @Override
+    public void analyze(Analyzer analyzer) throws UserException {
+        super.analyze(analyzer);
+        existedTableName.analyze(analyzer);
+        ConnectContext ctx = ConnectContext.get();
+        if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ctx, existedTableName.getDb(),
+                existedTableName.getTbl(), PrivPredicate.SELECT)) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "SELECT");
+        }
+
+        tableName.analyze(analyzer);
+        FeNameFormat.checkTableName(getTableName());
+        if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ctx, tableName.getDb(),
+                tableName.getTbl(), PrivPredicate.CREATE)) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "CREATE");
+        }
+
+        Database db = Catalog.getCurrentCatalog().getDb(getExistedDbName());

Review comment:
       line 102 to line 118 is better moved to `createTableLike()` in Catalog.java.
   Because analysis phase is usually used to analyze grammar, not semantics.

##########
File path: fe/fe-core/src/main/cup/sql_parser.cup
##########
@@ -1128,6 +1128,10 @@ create_stmt ::=
         RESULT = new CreateTableStmt(ifNotExists, isExternal, name, columns, indexes, engineName, keys, partition,
         distribution, tblProperties, extProperties, tableComment, index);
     :}
+    | KW_CREATE opt_external:isExternal KW_TABLE opt_if_not_exists:ifNotExists table_name:name KW_LIKE table_name:existed_name

Review comment:
       is `opt_external:isExternal` necessary?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] morningman merged pull request #4705: [CREATE TABLE]Support new syntax CREATE TABLE LIKE to clone an existe…

Posted by GitBox <gi...@apache.org>.
morningman merged pull request #4705:
URL: https://github.com/apache/incubator-doris/pull/4705


   


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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org


[GitHub] [incubator-doris] morningman commented on a change in pull request #4705: [CREATE TABLE]Support new syntax CREATE TABLE LIKE to clone an existe…

Posted by GitBox <gi...@apache.org>.
morningman commented on a change in pull request #4705:
URL: https://github.com/apache/incubator-doris/pull/4705#discussion_r501756194



##########
File path: fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableLikeStmt.java
##########
@@ -0,0 +1,130 @@
+// 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.doris.analysis;
+
+import com.google.common.collect.Lists;
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Database;
+import org.apache.doris.catalog.Table;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.FeNameFormat;
+import org.apache.doris.common.UserException;
+import org.apache.doris.common.util.SqlParserUtils;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+
+/**
+ * @author wangcong
+ * @version 1.0
+ * @date 2020/10/7 10:32 上午
+ */
+public class CreateTableLikeStmt extends DdlStmt {
+    private static final Logger LOG = LogManager.getLogger(CreateTableLikeStmt.class);
+
+    private CreateTableStmt parsedCreateTableStmt;
+    private final boolean isExternal;
+    private final boolean ifNotExists;
+    private final TableName tableName;
+    private final TableName existedTableName;
+
+    public CreateTableLikeStmt(boolean ifNotExists, boolean isExternal, TableName tableName, TableName existedTableName) {
+        this.ifNotExists = ifNotExists;
+        this.isExternal = isExternal;
+        this.tableName = tableName;
+        this.existedTableName = existedTableName;
+    }
+
+    public boolean isSetIfNotExists() {
+        return ifNotExists;
+    }
+
+    public boolean isExternal() {
+        return isExternal;
+    }
+
+    public String getDbName() {
+        return tableName.getDb();
+    }
+
+    public String getTableName() {
+        return tableName.getTbl();
+    }
+
+    public String getExistedDbName() {
+        return existedTableName.getDb();
+    }
+
+    public String getExistedTableName() {
+        return existedTableName.getTbl();
+    }
+
+    public CreateTableStmt getParsedCreateTableStmt() {
+        return parsedCreateTableStmt;
+    }
+
+    @Override
+    public void analyze(Analyzer analyzer) throws UserException {
+        super.analyze(analyzer);
+        existedTableName.analyze(analyzer);
+        ConnectContext ctx = ConnectContext.get();
+        if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ctx, existedTableName.getDb(),
+                existedTableName.getTbl(), PrivPredicate.SELECT)) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "SELECT");
+        }
+
+        tableName.analyze(analyzer);
+        FeNameFormat.checkTableName(getTableName());
+        if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ctx, tableName.getDb(),
+                tableName.getTbl(), PrivPredicate.CREATE)) {
+            ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "CREATE");
+        }
+
+        Database db = Catalog.getCurrentCatalog().getDb(getExistedDbName());

Review comment:
       line 102 to line 118 is better moved to `createTableLike()` in Catalog.java.
   Because analysis phase is usually used to analyze grammar, not semantics.

##########
File path: fe/fe-core/src/main/cup/sql_parser.cup
##########
@@ -1128,6 +1128,10 @@ create_stmt ::=
         RESULT = new CreateTableStmt(ifNotExists, isExternal, name, columns, indexes, engineName, keys, partition,
         distribution, tblProperties, extProperties, tableComment, index);
     :}
+    | KW_CREATE opt_external:isExternal KW_TABLE opt_if_not_exists:ifNotExists table_name:name KW_LIKE table_name:existed_name

Review comment:
       is `opt_external:isExternal` necessary?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org