snuyanzin commented on code in PR #29932:
URL: https://github.com/apache/flink/pull/29932#discussion_r4586426596
##########
flink-table/flink-table-planner/src/main/scala/org/apache/flink/table/planner/calcite/PreValidateReWriter.scala:
##########
@@ -122,102 +92,88 @@ object PreValidateReWriter {
if (table == null) {
// There is no table exists in current catalog,
// just skip to let other validation error throw.
- return source
+ return
}
- val rewriterUtils = new SqlRewriterUtils(validator)
val targetRowType = createTargetRowType(typeFactory, table)
- // validate partition fields first.
- val assignedFields = new util.LinkedHashMap[Integer, SqlNode]
val relOptTable = table match {
case t: RelOptTable => t
case _ => null
}
- for (node <- partitions.getList) {
- val sqlProperty = node.asInstanceOf[SqlProperty]
- val id = sqlProperty.getKey
- validateUnsupportedCompositeColumn(id)
- val targetField = SqlValidatorUtil.getTargetField(
- targetRowType,
- typeFactory,
- id,
- calciteCatalogReader,
- relOptTable)
- validateField(idx => !assignedFields.contains(idx), id, targetField)
- val value = sqlProperty.getValue.asInstanceOf[SqlLiteral]
- assignedFields.put(
- targetField.getIndex,
- validator.maybeCast(value, value.createSqlType(typeFactory),
targetField.getType))
- }
+ val assignedFields = new util.HashSet[Integer]
- // validate partial insert columns.
+ // validate partition fields first.
+ val partitionColumns = partitions.getList.map {
+ node =>
+ val id = node.asInstanceOf[SqlProperty].getKey
+ validateUnsupportedCompositeColumn(id)
+ val targetField = SqlValidatorUtil.getTargetField(
+ targetRowType,
+ typeFactory,
+ id,
+ calciteCatalogReader,
+ relOptTable)
+ validateField(assignedFields.add, id, targetField)
+ targetField
+ }
- // the columnList may reorder fields (compare with fields of sink)
- val targetPosition = new util.ArrayList[Int]()
+ if (sqlInsert.getTargetColumnList == null) {
+ return
+ }
- if (sqlInsert.getTargetColumnList != null) {
- val targetFields = new util.HashSet[Integer]
- val targetColumns =
- sqlInsert.getTargetColumnList.getList
- .map(
- id => {
- val identifier = id.asInstanceOf[SqlIdentifier]
- validateUnsupportedCompositeColumn(identifier)
- val targetField = SqlValidatorUtil.getTargetField(
- targetRowType,
- typeFactory,
- identifier,
- calciteCatalogReader,
- relOptTable)
- validateField(targetFields.add, id.asInstanceOf[SqlIdentifier],
targetField)
- targetField
- })
+ // validate partial insert columns.
+ val targetColumns = sqlInsert.getTargetColumnList.getList.map {
+ id =>
+ val identifier = id.asInstanceOf[SqlIdentifier]
+ validateUnsupportedCompositeColumn(identifier)
+ val targetField = SqlValidatorUtil.getTargetField(
+ targetRowType,
+ typeFactory,
+ identifier,
+ calciteCatalogReader,
+ relOptTable)
+ validateField(assignedFields.add, identifier, targetField)
+ targetField
+ }
- val partitionColumns =
- partitions.getList
- .map(
- property =>
- SqlValidatorUtil.getTargetField(
- targetRowType,
- typeFactory,
- property.asInstanceOf[SqlProperty].getKey,
- calciteCatalogReader,
- relOptTable))
+ // unlisted columns are padded with NULL after validation, which requires
them to be nullable
+ for (targetField <- targetRowType.getFieldList) {
+ if (
+ !partitionColumns.contains(targetField) &&
!targetColumns.contains(targetField)
Review Comment:
n^2 complexity?
--
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]