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: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
