KurtYoung commented on a change in pull request #8626: [FLINK-12742] Add insert into partition grammar as hive dialect URL: https://github.com/apache/flink/pull/8626#discussion_r292248144
########## File path: flink-table/flink-sql-parser/src/main/java/org/apache/flink/sql/parser/dml/RichSqlInsert.java ########## @@ -0,0 +1,292 @@ +/* + * 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.flink.sql.parser.dml; + +import org.apache.flink.sql.parser.SqlProperty; +import org.apache.flink.sql.parser.ddl.ExtendedSqlNode; +import org.apache.flink.sql.parser.error.SqlParseException; + +import org.apache.calcite.plan.RelOptTable; +import org.apache.calcite.prepare.Prepare; +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.rel.type.RelDataTypeFactory; +import org.apache.calcite.rel.type.RelDataTypeField; +import org.apache.calcite.sql.SqlIdentifier; +import org.apache.calcite.sql.SqlInsert; +import org.apache.calcite.sql.SqlLiteral; +import org.apache.calcite.sql.SqlNode; +import org.apache.calcite.sql.SqlNodeList; +import org.apache.calcite.sql.SqlSelect; +import org.apache.calcite.sql.SqlUtil; +import org.apache.calcite.sql.SqlWriter; +import org.apache.calcite.sql.fun.SqlStdOperatorTable; +import org.apache.calcite.sql.parser.SqlParserPos; +import org.apache.calcite.sql.type.SqlTypeUtil; +import org.apache.calcite.sql.validate.SqlValidator; +import org.apache.calcite.sql.validate.SqlValidatorNamespace; +import org.apache.calcite.sql.validate.SqlValidatorScope; +import org.apache.calcite.sql.validate.SqlValidatorTable; +import org.apache.calcite.sql.validate.SqlValidatorUtil; +import org.apache.calcite.util.Pair; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.apache.calcite.util.Static.RESOURCE; + +/** A {@link SqlInsert} that have some extension functions like partition, overwrite. **/ +public class RichSqlInsert extends SqlInsert implements ExtendedSqlNode { + private final SqlNodeList staticPartitions; + + public RichSqlInsert(SqlParserPos pos, + SqlNodeList keywords, + SqlNode targetTable, + SqlNode source, + SqlNodeList columnList, + SqlNodeList staticPartitions) { + super(pos, keywords, targetTable, source, columnList); + this.staticPartitions = staticPartitions; + } + + @Override + public void validate(SqlValidator validator, SqlValidatorScope scope) { + final SqlNode source = this.getSource(); + if (this.staticPartitions != null + && this.staticPartitions.size() > 0 + && source instanceof SqlSelect) { + appendPartitionProjects(validator, (SqlSelect) source, this.staticPartitions); + } + super.validate(validator, scope); + } + + /** + * @return the list of partition key-value pairs, + * returns empty if there is no partition specifications. + */ + public SqlNodeList getStaticPartitions() { + return staticPartitions; + } + + /** This method is a tool to fetch string partition values, not expect to be removed. + * + * <p>Caution that we use {@link SqlLiteral#toString()} to get + * the string format of the literal. If the string format is not + * what you need, use {@link #getStaticPartitions()}. + * + * @return the mapping of column names to values of partition specifications, + * returns an empty map if there is no partition specifications. + */ + public LinkedHashMap<String, String> getStaticPartitionKVs() { Review comment: unused method? ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services