You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by "ClaireLytt (via GitHub)" <gi...@apache.org> on 2025/07/09 07:40:10 UTC

[PR] fix:support CREATE DATABASE statement [shardingsphere]

ClaireLytt opened a new pull request, #35929:
URL: https://github.com/apache/shardingsphere/pull/35929

   for https://github.com/apache/shardingsphere/issues/35925
   official document:https://hive.apache.org/docs/latest/languagemanual-ddl_27362034/#createdropalteruse-database
   
   Changes proposed in this pull request:
     -
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following options:
   - [x] My code follows the [code of conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) of this project.
   - [x] I have self-reviewed the commit code.
   - [ ] I have (or in comment I request) added corresponding labels for the pull request.
   - [x] I have passed maven check locally : `./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e`.
   - [ ] I have made corresponding changes to the documentation.
   - [x] I have added corresponding unit tests for my changes.
   - [ ] I have updated the Release Notes of the current development version. For more details, see [Update Release Note](https://shardingsphere.apache.org/community/en/involved/contribute/contributor/)
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


Re: [PR] fix:Support Hive CREATE DATABASE statment parse [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on code in PR #35929:
URL: https://github.com/apache/shardingsphere/pull/35929#discussion_r2196249773


##########
parser/sql/dialect/hive/src/main/antlr4/imports/hive/DDLStatement.g4:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+grammar DDLStatement;
+
+import BaseRule;
+
+createDatabase
+    : CREATE REMOTE? (DATABASE | SCHEMA) (IF NOT EXISTS)? identifier
+      (COMMENT string_)? 
+      (LOCATION string_)?
+      (MANAGEDLOCATION string_)?
+      (WITH DBPROPERTIES LP_ dbProperties RP_)?
+    ;
+
+dbProperties
+    : dbProperty (COMMA_ dbProperty)*
+    ;
+
+dbProperty
+    : string_ EQ_ string_
+    ;

Review Comment:
   Please add a new line at the end of file.



##########
test/it/parser/src/main/resources/case/ddl/create-database.xml:
##########
@@ -25,4 +25,127 @@
     <create-database sql-case-id="create_database_with_file" />
     <create-database sql-case-id="create_database_oracle1" />
     <create-database sql-case-id="create_database_oracle2" />
+    <!-- Hive CREATE DATABASE Test -->

Review Comment:
   Please remove comment and useless blank line.



##########
test/it/parser/src/main/resources/sql/supported/ddl/create-database.xml:
##########
@@ -90,4 +90,128 @@
         USER_DATA TABLESPACE usertbs
           DATAFILE '/u01/app/oracle/oradata/pdbseed/usertbs01.dbf'
           SIZE 200M REUSE AUTOEXTEND ON MAXSIZE UNLIMITED" db-types="Oracle" />
+    <!-- Hive CREATE DATABASE Test -->

Review Comment:
   Please remove comment and useless blank line.



##########
parser/sql/dialect/hive/src/main/antlr4/imports/hive/HiveKeyword.g4:
##########
@@ -3142,3 +3142,21 @@ ZONE
     : Z O N E
     ;
 
+REMOTE
+    : R E M O T E
+    ;
+
+LOCATION
+    : L O C A T I O N
+    ;
+

Review Comment:
   Please only keep one blank line.



##########
parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveDDLStatementVisitor.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.sql.parser.hive.visitor.statement.type;
+
+import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor;
+import org.apache.shardingsphere.sql.parser.hive.visitor.statement.HiveStatementVisitor;
+import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.CreateDatabaseContext;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.database.CreateDatabaseStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.sql.parser.api.ASTNode;
+
+public final class HiveDDLStatementVisitor extends HiveStatementVisitor implements DDLStatementVisitor {

Review Comment:
   Please add javadoc for HiveDDLStatementVisitor



##########
parser/sql/dialect/hive/src/main/antlr4/imports/hive/DDLStatement.g4:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+grammar DDLStatement;
+
+import BaseRule;
+
+createDatabase
+    : CREATE REMOTE? (DATABASE | SCHEMA) (IF NOT EXISTS)? identifier
+      (COMMENT string_)? 
+      (LOCATION string_)?

Review Comment:
   Please do not wrap unless the syntax has multiple branches.



##########
parser/sql/dialect/hive/src/test/java/org/apache/shardingsphere/test/it/sql/parser/it/hive/internal/InternalHiveParserIT.java:
##########
@@ -0,0 +1,25 @@
+/*
+ * 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.test.it.sql.parser.it.hive.internal;
+
+import org.apache.shardingsphere.test.it.sql.parser.internal.InternalSQLParserIT;
+import org.apache.shardingsphere.test.it.sql.parser.internal.InternalSQLParserITSettings;
+
+@InternalSQLParserITSettings("Hive")
+public class InternalHiveParserIT extends InternalSQLParserIT {

Review Comment:
   For unit test or it test, you don't need to add public modifier.



##########
parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveDDLStatementVisitor.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.sql.parser.hive.visitor.statement.type;
+
+import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor;
+import org.apache.shardingsphere.sql.parser.hive.visitor.statement.HiveStatementVisitor;
+import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.CreateDatabaseContext;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.database.CreateDatabaseStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.sql.parser.api.ASTNode;
+
+public final class HiveDDLStatementVisitor extends HiveStatementVisitor implements DDLStatementVisitor {
+    
+    @Override
+    public ASTNode visitCreateDatabase(final CreateDatabaseContext ctx) {
+        // 构造 CreateDatabaseStatement,并设置数据库名及 IF NOT EXISTS 标识

Review Comment:
   Please remove comment



##########
parser/sql/dialect/hive/src/main/java/org/apache/shardingsphere/sql/parser/hive/visitor/statement/type/HiveDDLStatementVisitor.java:
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.sql.parser.hive.visitor.statement.type;
+
+import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.DDLStatementVisitor;
+import org.apache.shardingsphere.sql.parser.hive.visitor.statement.HiveStatementVisitor;
+import org.apache.shardingsphere.sql.parser.autogen.HiveStatementParser.CreateDatabaseContext;
+import org.apache.shardingsphere.sql.parser.statement.core.statement.type.ddl.database.CreateDatabaseStatement;
+import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
+import org.apache.shardingsphere.sql.parser.api.ASTNode;
+
+public final class HiveDDLStatementVisitor extends HiveStatementVisitor implements DDLStatementVisitor {
+    
+    @Override
+    public ASTNode visitCreateDatabase(final CreateDatabaseContext ctx) {
+        // 构造 CreateDatabaseStatement,并设置数据库名及 IF NOT EXISTS 标识
+        return new CreateDatabaseStatement(new IdentifierValue(ctx.identifier().getText()).getValue(),

Review Comment:
   Why implement visitCreateDatabase twice? I think you can remove visitCreateDatabase in HiveStatementVisitor.java



##########
parser/sql/dialect/hive/src/main/antlr4/imports/hive/DDLStatement.g4:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+grammar DDLStatement;
+
+import BaseRule;
+
+createDatabase
+    : CREATE REMOTE? (DATABASE | SCHEMA) (IF NOT EXISTS)? identifier

Review Comment:
   Can you extract `IF NOT EXISTS` as a new sytax rule like `ifNotExists`?



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


Re: [PR] fix:Support Hive CREATE DATABASE statment parse [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on code in PR #35929:
URL: https://github.com/apache/shardingsphere/pull/35929#discussion_r2199099381


##########
parser/sql/dialect/hive/src/main/antlr4/imports/hive/DDLStatement.g4:
##########
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+grammar DDLStatement;
+
+import BaseRule;
+
+createDatabase
+    : CREATE REMOTE? (DATABASE | SCHEMA) ifNotExists? identifier (COMMENT string_)? (LOCATION string_)? (MANAGEDLOCATION string_)? (WITH DBPROPERTIES LP_ dbProperties RP_)?
+    ;
+
+ifNotExists
+    :IF NOT EXISTS

Review Comment:
   Please add empty string between `:` and `IF`



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


Re: [PR] fix:support CREATE DATABASE statement [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu commented on PR #35929:
URL: https://github.com/apache/shardingsphere/pull/35929#issuecomment-3051839533

   Hi @ClaireLytt, can you update this pr description to `Support Hive CREATE DATABASE statment parse`? Besides, you need update RELEASE NOTE for this chang.


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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


Re: [PR] fix:Support Hive CREATE DATABASE statment parse [shardingsphere]

Posted by "strongduanmu (via GitHub)" <gi...@apache.org>.
strongduanmu merged PR #35929:
URL: https://github.com/apache/shardingsphere/pull/35929


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

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