You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2019/12/23 14:53:25 UTC
[GitHub] [flink] wuchong opened a new pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
wuchong opened a new pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667
<!--
*Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
*Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
## Contribution Checklist
- Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
- Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
- Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
- Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Travis CI to do that following [this guide](https://flink.apache.org/contributing/contribute-code.html#open-a-pull-request).
- Each pull request should address only one issue, not mix up code from multiple issues.
- Each commit in the pull request has a meaningful commit message (including the JIRA id)
- Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
**(The sections below can be removed for hotfixes of typos)**
-->
## What is the purpose of the change
Fix can't insert decimal data into sink using TypeInformation
The root problem is we use TypeInformation for sink code generation which
loses the precision of decimal type. This result in the illegal accessing to
the internal Decimal value.
## Brief change log
The fixing including:
1. Add validation for query and sink field types should be compatible (including precision)
2. If not compatible, an implicit cast is added (this makes sure that it is still correct
to access internal decimal data using sink field type, e.g. genToExternal)
3. Checks logical schema (from DDL) and physical schema (from TableSink#getConsumedDataType)
are compatible.
4. Use new type system for sink code generation
## Verifying this change
This change is covered by existing test, but also added some other tests.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (yes / **no**)
- The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (yes / **no**)
- The serializers: (yes / **no** / don't know)
- The runtime per-record code paths (performance sensitive): (yes / **no** / don't know)
- Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: (yes / **no** / don't know)
- The S3 file system connector: (yes / **no** / don't know)
## Documentation
- Does this pull request introduce a new feature? (yes / **no**)
- If yes, how is the feature documented? (**not applicable** / docs / JavaDocs / not documented)
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] JingsongLi commented on issue #10667: [FLINK-15313][table]
Fix can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568829609
Can you verify:
https://issues.apache.org/jira/browse/FLINK-15309
https://issues.apache.org/jira/browse/FLINK-15310
https://issues.apache.org/jira/browse/FLINK-15326
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on issue #10667: [FLINK-15313][table] Fix
can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568496968
Note that, currently (even with this PR), only csv and Hive connector support decimal precision.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] JingsongLi commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361124987
##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/sinks/TableSinkUtils.scala
##########
@@ -18,67 +18,99 @@
package org.apache.flink.table.planner.sinks
-import org.apache.flink.table.api.ValidationException
-import org.apache.flink.table.catalog.ObjectIdentifier
+import org.apache.flink.api.java.tuple.{Tuple2 => JTuple2}
+import org.apache.flink.api.java.typeutils.{GenericTypeInfo, TupleTypeInfo}
+import org.apache.flink.api.scala.typeutils.CaseClassTypeInfo
+import org.apache.flink.table.api.{TableException, TableSchema, Types, ValidationException}
+import org.apache.flink.table.catalog.{CatalogTable, ObjectIdentifier}
+import org.apache.flink.table.dataformat.BaseRow
import org.apache.flink.table.operations.CatalogSinkModifyOperation
-import org.apache.flink.table.runtime.types.LogicalTypeDataTypeConverter.fromDataTypeToLogicalType
-import org.apache.flink.table.runtime.types.PlannerTypeUtils
-import org.apache.flink.table.sinks.{PartitionableTableSink, TableSink}
+import org.apache.flink.table.planner.calcite.FlinkTypeFactory
+import org.apache.flink.table.planner.plan.utils.RelOptUtils
+import org.apache.flink.table.sinks._
+import org.apache.flink.table.types.DataType
+import org.apache.flink.table.types.inference.TypeTransformations.{legacyDecimalToDefaultDecimal, toNullable}
+import org.apache.flink.table.types.logical.utils.{LogicalTypeCasts, LogicalTypeChecks}
+import org.apache.flink.table.types.logical.{LegacyTypeInformationType, RowType}
+import org.apache.flink.table.types.utils.DataTypeUtils
+import org.apache.flink.table.types.utils.TypeConversions.{fromLegacyInfoToDataType, fromLogicalToDataType}
+import org.apache.flink.table.utils.{TableSchemaUtils, TypeMappingUtils}
+import org.apache.flink.types.Row
+import org.apache.calcite.rel.RelNode
import scala.collection.JavaConversions._
object TableSinkUtils {
/**
- * Checks if the given [[CatalogSinkModifyOperation]]'s query can be written to
- * the given [[TableSink]]. It checks if the names & the field types match. If the table
- * sink is a [[PartitionableTableSink]], also check that the partitions are valid.
+ * Checks if the given query can be written into the given sink. It checks the field types
+ * should be compatible (types should equal including precisions). If types are not compatible,
+ * but can be implicitly casted, a cast projection will be applied. Otherwise, an exception will
+ * be thrown.
+ *
+ * @param query the query to be checked
+ * @param sinkSchema the schema of sink to be checked
+ * @param typeFactory type factory
+ * @return the query RelNode which may be applied the implicitly cast projection.
+ */
+ def validateSchemaAndApplyImplicitCast(
+ query: RelNode,
+ sinkSchema: TableSchema,
+ typeFactory: FlinkTypeFactory,
+ sinkIdentifier: Option[String] = None): RelNode = {
+
+ val queryLogicalType = DataTypeUtils
+ // convert type to nullable, because we ignore nullability when writing query into sink
+ .transform(FlinkTypeFactory.toTableSchema(query.getRowType).toRowDataType, toNullable)
+ .getLogicalType
+ .asInstanceOf[RowType]
+ val sinkLogicalType = DataTypeUtils
+ // convert type to nullable, because we ignore nullability when writing query into sink
+ .transform(sinkSchema.toRowDataType, legacyDecimalToDefaultDecimal, toNullable)
+ .getLogicalType
+ .asInstanceOf[RowType]
+ if (LogicalTypeChecks.areTypesCompatible(queryLogicalType, sinkLogicalType)) {
+ // types are compatible, do nothing
+ query
+ } else if (LogicalTypeCasts.supportsImplicitCast(queryLogicalType, sinkLogicalType)) {
+ // types can be implicit casted, add a cast project
+ val castedDataType = typeFactory.buildRelNodeRowType(
+ sinkLogicalType.getFieldNames,
+ sinkLogicalType.getFields.map(_.getType))
+ RelOptUtils.createCastRel(query, castedDataType)
+ } else {
+ // format query and sink schema strings
+ val srcSchema = queryLogicalType.getFields
+ .map(f => s"${f.getName}: ${f.getType}")
+ .mkString("[", ", ", "]")
+ val sinkSchema = sinkLogicalType.getFields
+ .map(f => s"${f.getName}: ${f.getType}")
+ .mkString("[", ", ", "]")
+
+ val sinkDesc: String = sinkIdentifier.getOrElse("")
+
+ throw new ValidationException(
+ s"Field types of query result and registered TableSink $sinkDesc do not match.\n" +
+ s"Query schema: $srcSchema\n" +
+ s"Sink schema: $sinkSchema")
+ }
+ }
+
+ /**
+ * It checks whether the [[TableSink]] is compatible to the INSERT INTO clause, e.g.
+ * whether the sink is a [[PartitionableTableSink]] and the partitions are valid.
*
* @param sinkOperation The sink operation with the query that is supposed to be written.
* @param sinkIdentifier Tha path of the sink. It is needed just for logging. It does not
* participate in the validation.
* @param sink The sink that we want to write to.
* @param partitionKeys The partition keys of this table.
*/
- def validateSink(
+ def validateTableSink(
Review comment:
Can we just add `validateLogicalPhysicalTypesCompatible` to this method and do more check?
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot edited a comment on issue #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568504832
<!--
Meta data
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142124640 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://travis-ci.com/flink-ci/flink/builds/142212396 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142222152 TriggerType:PUSH TriggerID:154a6b2af5e9b78a5a554e60fdd40bf8effd4596
Hash:154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3891 TriggerType:PUSH TriggerID:154a6b2af5e9b78a5a554e60fdd40bf8effd4596
Hash:4f0587d909b07156509eae046d029f8ee49a5cf8 Status:PENDING URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3911 TriggerType:PUSH TriggerID:4f0587d909b07156509eae046d029f8ee49a5cf8
Hash:4f0587d909b07156509eae046d029f8ee49a5cf8 Status:PENDING URL:https://travis-ci.com/flink-ci/flink/builds/142313125 TriggerType:PUSH TriggerID:4f0587d909b07156509eae046d029f8ee49a5cf8
-->
## CI report:
* 544133fefeb806ec9fd181f180108b62424b2a3e Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142124640) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865)
* a2255e91d70c97beb58aaa7713df392bca12edff Travis: [SUCCESS](https://travis-ci.com/flink-ci/flink/builds/142212396) Azure: [SUCCESS](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886)
* 154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142222152) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3891)
* 4f0587d909b07156509eae046d029f8ee49a5cf8 Travis: [PENDING](https://travis-ci.com/flink-ci/flink/builds/142313125) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3911)
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] JingsongLi commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361121577
##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/metadata/FlinkRelMdUniqueKeys.scala
##########
@@ -135,8 +135,8 @@ class FlinkRelMdUniqueKeys private extends MetadataHandler[BuiltInMetadata.Uniqu
}
case _ => // ignore
}
- //rename
- case a: RexCall if a.getKind.equals(SqlKind.AS) &&
+ //rename or cast
+ case a: RexCall if (a.getKind.equals(SqlKind.AS) || a.getKind.equals(SqlKind.CAST)) &&
Review comment:
This is for Upsert sink?
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot edited a comment on issue #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568504832
<!--
Meta data
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142124640 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://travis-ci.com/flink-ci/flink/builds/142212396 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142222152 TriggerType:PUSH TriggerID:154a6b2af5e9b78a5a554e60fdd40bf8effd4596
Hash:154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3891 TriggerType:PUSH TriggerID:154a6b2af5e9b78a5a554e60fdd40bf8effd4596
Hash:4f0587d909b07156509eae046d029f8ee49a5cf8 Status:UNKNOWN URL:TBD TriggerType:PUSH TriggerID:4f0587d909b07156509eae046d029f8ee49a5cf8
-->
## CI report:
* 544133fefeb806ec9fd181f180108b62424b2a3e Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142124640) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865)
* a2255e91d70c97beb58aaa7713df392bca12edff Travis: [SUCCESS](https://travis-ci.com/flink-ci/flink/builds/142212396) Azure: [SUCCESS](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886)
* 154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142222152) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3891)
* 4f0587d909b07156509eae046d029f8ee49a5cf8 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] JingsongLi commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361246115
##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/metadata/FlinkRelMdUniqueKeys.scala
##########
@@ -135,8 +138,8 @@ class FlinkRelMdUniqueKeys private extends MetadataHandler[BuiltInMetadata.Uniqu
}
case _ => // ignore
}
- //rename
- case a: RexCall if a.getKind.equals(SqlKind.AS) &&
+ //rename or cast
+ case a: RexCall if (a.getKind.equals(SqlKind.AS) || isFidelityCast(a)) &&
Review comment:
Do we have to add this?
There are some casts that break uniqueness. For example, if cast fails, it will return null.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot edited a comment on issue #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568504832
<!--
Meta data
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:PENDING URL:https://travis-ci.com/flink-ci/flink/builds/142124640 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:PENDING URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
-->
## CI report:
* 544133fefeb806ec9fd181f180108b62424b2a3e Travis: [PENDING](https://travis-ci.com/flink-ci/flink/builds/142124640) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865)
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361129271
##########
File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/typeutils/BaseRowTypeInfo.java
##########
@@ -60,7 +60,8 @@ public BaseRowTypeInfo(LogicalType... logicalTypes) {
public BaseRowTypeInfo(LogicalType[] logicalTypes, String[] fieldNames) {
super(BaseRow.class, Arrays.stream(logicalTypes)
- .map(TypeInfoLogicalTypeConverter::fromLogicalTypeToTypeInfo)
+ .map(TypeConversions::fromLogicalToDataType)
Review comment:
I reverted this line.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] JingsongLi commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361055773
##########
File path: flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/transforms/LegacyDecimalTypeTransformation.java
##########
@@ -0,0 +1,52 @@
+/*
+ * 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.table.types.inference.transforms;
+
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.inference.TypeTransformation;
+import org.apache.flink.table.types.logical.DecimalType;
+import org.apache.flink.table.types.logical.LegacyTypeInformationType;
+import org.apache.flink.table.types.logical.LogicalType;
+import org.apache.flink.table.types.logical.LogicalTypeRoot;
+
+/**
+ * This type transformation transforms the legacy decimal type (usually converted from
+ * {@link org.apache.flink.api.common.typeinfo.Types#BIG_DEC}) to DECIMAL(38, 18).
+ */
+public class LegacyDecimalTypeTransformation implements TypeTransformation {
+
+ public static final TypeTransformation INSTANCE = new LegacyDecimalTypeTransformation();
+
+ @Override
+ public DataType transform(DataType typeToTransform) {
+ LogicalType logicalType = typeToTransform.getLogicalType();
+ if (logicalType instanceof LegacyTypeInformationType && logicalType.getTypeRoot() == LogicalTypeRoot.DECIMAL) {
+ DataType decimalType = DataTypes
+ .DECIMAL(DecimalType.MAX_PRECISION, 18)
+ .bridgedTo(typeToTransform.getConversionClass());
+ if (!logicalType.isNullable()) {
Review comment:
return logicalType.isNullable() ? decimalType : decimalType.notNull();
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] JingsongLi commented on issue #10667: [FLINK-15313][table]
Fix can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568830177
You can fix failure cases too.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361125332
##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/metadata/FlinkRelMdUniqueKeys.scala
##########
@@ -135,8 +135,8 @@ class FlinkRelMdUniqueKeys private extends MetadataHandler[BuiltInMetadata.Uniqu
}
case _ => // ignore
}
- //rename
- case a: RexCall if a.getKind.equals(SqlKind.AS) &&
+ //rename or cast
+ case a: RexCall if (a.getKind.equals(SqlKind.AS) || a.getKind.equals(SqlKind.CAST)) &&
Review comment:
true.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361129746
##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/sinks/TableSinkUtils.scala
##########
@@ -18,67 +18,99 @@
package org.apache.flink.table.planner.sinks
-import org.apache.flink.table.api.ValidationException
-import org.apache.flink.table.catalog.ObjectIdentifier
+import org.apache.flink.api.java.tuple.{Tuple2 => JTuple2}
+import org.apache.flink.api.java.typeutils.{GenericTypeInfo, TupleTypeInfo}
+import org.apache.flink.api.scala.typeutils.CaseClassTypeInfo
+import org.apache.flink.table.api.{TableException, TableSchema, Types, ValidationException}
+import org.apache.flink.table.catalog.{CatalogTable, ObjectIdentifier}
+import org.apache.flink.table.dataformat.BaseRow
import org.apache.flink.table.operations.CatalogSinkModifyOperation
-import org.apache.flink.table.runtime.types.LogicalTypeDataTypeConverter.fromDataTypeToLogicalType
-import org.apache.flink.table.runtime.types.PlannerTypeUtils
-import org.apache.flink.table.sinks.{PartitionableTableSink, TableSink}
+import org.apache.flink.table.planner.calcite.FlinkTypeFactory
+import org.apache.flink.table.planner.plan.utils.RelOptUtils
+import org.apache.flink.table.sinks._
+import org.apache.flink.table.types.DataType
+import org.apache.flink.table.types.inference.TypeTransformations.{legacyDecimalToDefaultDecimal, toNullable}
+import org.apache.flink.table.types.logical.utils.{LogicalTypeCasts, LogicalTypeChecks}
+import org.apache.flink.table.types.logical.{LegacyTypeInformationType, RowType}
+import org.apache.flink.table.types.utils.DataTypeUtils
+import org.apache.flink.table.types.utils.TypeConversions.{fromLegacyInfoToDataType, fromLogicalToDataType}
+import org.apache.flink.table.utils.{TableSchemaUtils, TypeMappingUtils}
+import org.apache.flink.types.Row
+import org.apache.calcite.rel.RelNode
import scala.collection.JavaConversions._
object TableSinkUtils {
/**
- * Checks if the given [[CatalogSinkModifyOperation]]'s query can be written to
- * the given [[TableSink]]. It checks if the names & the field types match. If the table
- * sink is a [[PartitionableTableSink]], also check that the partitions are valid.
+ * Checks if the given query can be written into the given sink. It checks the field types
+ * should be compatible (types should equal including precisions). If types are not compatible,
+ * but can be implicitly casted, a cast projection will be applied. Otherwise, an exception will
+ * be thrown.
+ *
+ * @param query the query to be checked
+ * @param sinkSchema the schema of sink to be checked
+ * @param typeFactory type factory
+ * @return the query RelNode which may be applied the implicitly cast projection.
+ */
+ def validateSchemaAndApplyImplicitCast(
+ query: RelNode,
+ sinkSchema: TableSchema,
+ typeFactory: FlinkTypeFactory,
+ sinkIdentifier: Option[String] = None): RelNode = {
+
+ val queryLogicalType = DataTypeUtils
+ // convert type to nullable, because we ignore nullability when writing query into sink
+ .transform(FlinkTypeFactory.toTableSchema(query.getRowType).toRowDataType, toNullable)
+ .getLogicalType
+ .asInstanceOf[RowType]
+ val sinkLogicalType = DataTypeUtils
+ // convert type to nullable, because we ignore nullability when writing query into sink
+ .transform(sinkSchema.toRowDataType, legacyDecimalToDefaultDecimal, toNullable)
+ .getLogicalType
+ .asInstanceOf[RowType]
+ if (LogicalTypeChecks.areTypesCompatible(queryLogicalType, sinkLogicalType)) {
+ // types are compatible, do nothing
+ query
+ } else if (LogicalTypeCasts.supportsImplicitCast(queryLogicalType, sinkLogicalType)) {
+ // types can be implicit casted, add a cast project
+ val castedDataType = typeFactory.buildRelNodeRowType(
+ sinkLogicalType.getFieldNames,
+ sinkLogicalType.getFields.map(_.getType))
+ RelOptUtils.createCastRel(query, castedDataType)
+ } else {
+ // format query and sink schema strings
+ val srcSchema = queryLogicalType.getFields
+ .map(f => s"${f.getName}: ${f.getType}")
+ .mkString("[", ", ", "]")
+ val sinkSchema = sinkLogicalType.getFields
+ .map(f => s"${f.getName}: ${f.getType}")
+ .mkString("[", ", ", "]")
+
+ val sinkDesc: String = sinkIdentifier.getOrElse("")
+
+ throw new ValidationException(
+ s"Field types of query result and registered TableSink $sinkDesc do not match.\n" +
+ s"Query schema: $srcSchema\n" +
+ s"Sink schema: $sinkSchema")
+ }
+ }
+
+ /**
+ * It checks whether the [[TableSink]] is compatible to the INSERT INTO clause, e.g.
+ * whether the sink is a [[PartitionableTableSink]] and the partitions are valid.
*
* @param sinkOperation The sink operation with the query that is supposed to be written.
* @param sinkIdentifier Tha path of the sink. It is needed just for logging. It does not
* participate in the validation.
* @param sink The sink that we want to write to.
* @param partitionKeys The partition keys of this table.
*/
- def validateSink(
+ def validateTableSink(
Review comment:
I think it would better to separate them, because they do the different things and `validateTableSink` is only invoked in "INSERT" statements.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on issue #10667: [FLINK-15313][table] Fix
can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568953276
Hi @JingsongLi do you have future comments on this?
Travis is passed in my repo: https://travis-ci.org/wuchong/flink/builds/629333389
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on issue #10667: [FLINK-15313][table] Fix
can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568874926
@JingsongLi , I have verified related issues and this PR fixes those problems.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot edited a comment on issue #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568504832
<!--
Meta data
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142124640 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:PENDING URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:PENDING URL:https://travis-ci.com/flink-ci/flink/builds/142212396 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
-->
## CI report:
* 544133fefeb806ec9fd181f180108b62424b2a3e Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142124640) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865)
* a2255e91d70c97beb58aaa7713df392bca12edff Travis: [PENDING](https://travis-ci.com/flink-ci/flink/builds/142212396) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886)
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] JingsongLi commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361119627
##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/sinks/TableSinkUtils.scala
##########
@@ -18,67 +18,99 @@
package org.apache.flink.table.planner.sinks
-import org.apache.flink.table.api.ValidationException
-import org.apache.flink.table.catalog.ObjectIdentifier
+import org.apache.flink.api.java.tuple.{Tuple2 => JTuple2}
+import org.apache.flink.api.java.typeutils.{GenericTypeInfo, TupleTypeInfo}
+import org.apache.flink.api.scala.typeutils.CaseClassTypeInfo
+import org.apache.flink.table.api.{TableException, TableSchema, Types, ValidationException}
+import org.apache.flink.table.catalog.{CatalogTable, ObjectIdentifier}
+import org.apache.flink.table.dataformat.BaseRow
import org.apache.flink.table.operations.CatalogSinkModifyOperation
-import org.apache.flink.table.runtime.types.LogicalTypeDataTypeConverter.fromDataTypeToLogicalType
-import org.apache.flink.table.runtime.types.PlannerTypeUtils
-import org.apache.flink.table.sinks.{PartitionableTableSink, TableSink}
+import org.apache.flink.table.planner.calcite.FlinkTypeFactory
+import org.apache.flink.table.planner.plan.utils.RelOptUtils
+import org.apache.flink.table.sinks._
+import org.apache.flink.table.types.DataType
+import org.apache.flink.table.types.inference.TypeTransformations.{legacyDecimalToDefaultDecimal, toNullable}
+import org.apache.flink.table.types.logical.utils.{LogicalTypeCasts, LogicalTypeChecks}
+import org.apache.flink.table.types.logical.{LegacyTypeInformationType, RowType}
+import org.apache.flink.table.types.utils.DataTypeUtils
+import org.apache.flink.table.types.utils.TypeConversions.{fromLegacyInfoToDataType, fromLogicalToDataType}
+import org.apache.flink.table.utils.{TableSchemaUtils, TypeMappingUtils}
+import org.apache.flink.types.Row
+import org.apache.calcite.rel.RelNode
import scala.collection.JavaConversions._
object TableSinkUtils {
/**
- * Checks if the given [[CatalogSinkModifyOperation]]'s query can be written to
- * the given [[TableSink]]. It checks if the names & the field types match. If the table
- * sink is a [[PartitionableTableSink]], also check that the partitions are valid.
+ * Checks if the given query can be written into the given sink. It checks the field types
+ * should be compatible (types should equal including precisions). If types are not compatible,
+ * but can be implicitly casted, a cast projection will be applied. Otherwise, an exception will
+ * be thrown.
+ *
+ * @param query the query to be checked
+ * @param sinkSchema the schema of sink to be checked
+ * @param typeFactory type factory
+ * @return the query RelNode which may be applied the implicitly cast projection.
+ */
+ def validateSchemaAndApplyImplicitCast(
+ query: RelNode,
+ sinkSchema: TableSchema,
+ typeFactory: FlinkTypeFactory,
+ sinkIdentifier: Option[String] = None): RelNode = {
+
+ val queryLogicalType = DataTypeUtils
+ // convert type to nullable, because we ignore nullability when writing query into sink
Review comment:
Another choice is check in `if (LogicalTypeCasts.supportsImplicitCast(queryLogicalType, sinkLogicalType))`?
You can take a look to `supportsCasting`, there are some nullable related check.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong closed pull request #10667: [FLINK-15313][table]
Fix can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong closed pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] JingsongLi commented on issue #10667: [FLINK-15313][table]
Fix can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568829538
Shall https://issues.apache.org/jira/browse/FLINK-15381 is blocker to this PR?
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot edited a comment on issue #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568504832
<!--
Meta data
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142124640 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://travis-ci.com/flink-ci/flink/builds/142212396 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142222152 TriggerType:PUSH TriggerID:154a6b2af5e9b78a5a554e60fdd40bf8effd4596
Hash:154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3891 TriggerType:PUSH TriggerID:154a6b2af5e9b78a5a554e60fdd40bf8effd4596
-->
## CI report:
* 544133fefeb806ec9fd181f180108b62424b2a3e Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142124640) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865)
* a2255e91d70c97beb58aaa7713df392bca12edff Travis: [SUCCESS](https://travis-ci.com/flink-ci/flink/builds/142212396) Azure: [SUCCESS](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886)
* 154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142222152) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3891)
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361116539
##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/sinks/TableSinkUtils.scala
##########
@@ -18,67 +18,99 @@
package org.apache.flink.table.planner.sinks
-import org.apache.flink.table.api.ValidationException
-import org.apache.flink.table.catalog.ObjectIdentifier
+import org.apache.flink.api.java.tuple.{Tuple2 => JTuple2}
+import org.apache.flink.api.java.typeutils.{GenericTypeInfo, TupleTypeInfo}
+import org.apache.flink.api.scala.typeutils.CaseClassTypeInfo
+import org.apache.flink.table.api.{TableException, TableSchema, Types, ValidationException}
+import org.apache.flink.table.catalog.{CatalogTable, ObjectIdentifier}
+import org.apache.flink.table.dataformat.BaseRow
import org.apache.flink.table.operations.CatalogSinkModifyOperation
-import org.apache.flink.table.runtime.types.LogicalTypeDataTypeConverter.fromDataTypeToLogicalType
-import org.apache.flink.table.runtime.types.PlannerTypeUtils
-import org.apache.flink.table.sinks.{PartitionableTableSink, TableSink}
+import org.apache.flink.table.planner.calcite.FlinkTypeFactory
+import org.apache.flink.table.planner.plan.utils.RelOptUtils
+import org.apache.flink.table.sinks._
+import org.apache.flink.table.types.DataType
+import org.apache.flink.table.types.inference.TypeTransformations.{legacyDecimalToDefaultDecimal, toNullable}
+import org.apache.flink.table.types.logical.utils.{LogicalTypeCasts, LogicalTypeChecks}
+import org.apache.flink.table.types.logical.{LegacyTypeInformationType, RowType}
+import org.apache.flink.table.types.utils.DataTypeUtils
+import org.apache.flink.table.types.utils.TypeConversions.{fromLegacyInfoToDataType, fromLogicalToDataType}
+import org.apache.flink.table.utils.{TableSchemaUtils, TypeMappingUtils}
+import org.apache.flink.types.Row
+import org.apache.calcite.rel.RelNode
import scala.collection.JavaConversions._
object TableSinkUtils {
/**
- * Checks if the given [[CatalogSinkModifyOperation]]'s query can be written to
- * the given [[TableSink]]. It checks if the names & the field types match. If the table
- * sink is a [[PartitionableTableSink]], also check that the partitions are valid.
+ * Checks if the given query can be written into the given sink. It checks the field types
+ * should be compatible (types should equal including precisions). If types are not compatible,
+ * but can be implicitly casted, a cast projection will be applied. Otherwise, an exception will
+ * be thrown.
+ *
+ * @param query the query to be checked
+ * @param sinkSchema the schema of sink to be checked
+ * @param typeFactory type factory
+ * @return the query RelNode which may be applied the implicitly cast projection.
+ */
+ def validateSchemaAndApplyImplicitCast(
+ query: RelNode,
+ sinkSchema: TableSchema,
+ typeFactory: FlinkTypeFactory,
+ sinkIdentifier: Option[String] = None): RelNode = {
+
+ val queryLogicalType = DataTypeUtils
+ // convert type to nullable, because we ignore nullability when writing query into sink
Review comment:
It is equivalent no matter `toNullable` or not, because if the nullability is not the same, we will add a implicit cast. The purpose to ignore nullable at earlier stage is in order to avoid cast project as much as possible, otherwise, we have to update a lot of XML plan files.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot edited a comment on issue #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568504832
<!--
Meta data
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142124640 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
-->
## CI report:
* 544133fefeb806ec9fd181f180108b62424b2a3e Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142124640) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865)
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] JingsongLi commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361122091
##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/sinks/TableSinkUtils.scala
##########
@@ -98,5 +130,148 @@ object TableSinkUtils {
}
}
}
+
+ sink match {
+ case overwritableTableSink: OverwritableTableSink =>
+ overwritableTableSink.setOverwrite(sinkOperation.isOverwrite)
+ case _ =>
+ assert(!sinkOperation.isOverwrite, "INSERT OVERWRITE requires " +
+ s"${classOf[OverwritableTableSink].getSimpleName} but actually got " +
+ sink.getClass.getName)
+ }
+ }
+
+ /**
+ * Inferences the physical schema of [[TableSink]], the physical schema ignores change flag
+ * field and normalizes physical types (can be generic type or POJO type) into [[TableSchema]].
+ * @param queryLogicalType the logical type of query, will be used to full-fill sink physical
+ * schema if the sink physical type is not specified.
+ * @param sink the instance of [[TableSink]]
+ */
+ def inferSinkPhysicalSchema(
+ queryLogicalType: RowType,
+ sink: TableSink[_]): TableSchema = {
+ val withChangeFlag = sink match {
+ case _: RetractStreamTableSink[_] | _: UpsertStreamTableSink[_] => true
+ case _: StreamTableSink[_] => false
+ case dsts: DataStreamTableSink[_] => dsts.withChangeFlag
+ }
+ inferSinkPhysicalSchema(sink.getConsumedDataType, queryLogicalType, withChangeFlag)
+ }
+
+ /**
+ * Inferences the physical schema of [[TableSink]], the physical schema ignores change flag
+ * field and normalizes physical types (can be generic type or POJO type) into [[TableSchema]].
+ *
+ * @param consumedDataType the consumed data type of sink
+ * @param queryLogicalType the logical type of query, will be used to full-fill sink physical
+ * schema if the sink physical type is not specified.
+ * @param withChangeFlag true if the emitted records contains change flags.
+ */
+ def inferSinkPhysicalSchema(
+ consumedDataType: DataType,
+ queryLogicalType: RowType,
+ withChangeFlag: Boolean): TableSchema = {
+ // the requested output physical type which ignores the flag field
+ val requestedOutputType = inferSinkPhysicalDataType(
+ consumedDataType,
+ queryLogicalType,
+ withChangeFlag)
+ if (LogicalTypeChecks.isCompositeType(requestedOutputType.getLogicalType)) {
+ DataTypeUtils.expandCompositeTypeToSchema(requestedOutputType)
+ } else {
+ // atomic type
+ TableSchema.builder().field("f0", requestedOutputType).build()
+ }
+ }
+
+ /**
+ * Inferences the physical data type of [[TableSink]], the physical data type ignores
+ * the change flag field.
+ *
+ * @param consumedDataType the consumed data type of sink
+ * @param queryLogicalType the logical type of query, will be used to full-fill sink physical
+ * schema if the sink physical type is not specified.
+ * @param withChangeFlag true if the emitted records contains change flags.
+ */
+ def inferSinkPhysicalDataType(
Review comment:
Provide a method return `sinkPhysicalDataType` and `outputType`?
I think it is not good to extract physicalDataType from output type, and construct output type from physicalDataType again.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot edited a comment on issue #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568504832
<!--
Meta data
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142124640 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:UNKNOWN URL:TBD TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
-->
## CI report:
* 544133fefeb806ec9fd181f180108b62424b2a3e Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142124640) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865)
* a2255e91d70c97beb58aaa7713df392bca12edff UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot commented on issue #10667: [FLINK-15313][table]
Fix can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot commented on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568496676
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.
## Automated Checks
Last check on commit 544133fefeb806ec9fd181f180108b62424b2a3e (Mon Dec 23 14:56:36 UTC 2019)
**Warnings:**
* No documentation files were touched! Remember to keep the Flink docs up to date!
<sub>Mention the bot in a comment to re-run the automated checks.</sub>
## Review Progress
* ❓ 1. The [description] looks good.
* ❓ 2. There is [consensus] that the contribution should go into to Flink.
* ❓ 3. Needs [attention] from.
* ❓ 4. The change fits into the overall [architecture].
* ❓ 5. Overall code [quality] is good.
Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
- `@flinkbot approve all` to approve all aspects
- `@flinkbot approve-until architecture` to approve everything until `architecture`
- `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
- `@flinkbot disapprove architecture` to remove an approval you gave earlier
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] JingsongLi commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361082465
##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/sinks/TableSinkUtils.scala
##########
@@ -18,67 +18,99 @@
package org.apache.flink.table.planner.sinks
-import org.apache.flink.table.api.ValidationException
-import org.apache.flink.table.catalog.ObjectIdentifier
+import org.apache.flink.api.java.tuple.{Tuple2 => JTuple2}
+import org.apache.flink.api.java.typeutils.{GenericTypeInfo, TupleTypeInfo}
+import org.apache.flink.api.scala.typeutils.CaseClassTypeInfo
+import org.apache.flink.table.api.{TableException, TableSchema, Types, ValidationException}
+import org.apache.flink.table.catalog.{CatalogTable, ObjectIdentifier}
+import org.apache.flink.table.dataformat.BaseRow
import org.apache.flink.table.operations.CatalogSinkModifyOperation
-import org.apache.flink.table.runtime.types.LogicalTypeDataTypeConverter.fromDataTypeToLogicalType
-import org.apache.flink.table.runtime.types.PlannerTypeUtils
-import org.apache.flink.table.sinks.{PartitionableTableSink, TableSink}
+import org.apache.flink.table.planner.calcite.FlinkTypeFactory
+import org.apache.flink.table.planner.plan.utils.RelOptUtils
+import org.apache.flink.table.sinks._
+import org.apache.flink.table.types.DataType
+import org.apache.flink.table.types.inference.TypeTransformations.{legacyDecimalToDefaultDecimal, toNullable}
+import org.apache.flink.table.types.logical.utils.{LogicalTypeCasts, LogicalTypeChecks}
+import org.apache.flink.table.types.logical.{LegacyTypeInformationType, RowType}
+import org.apache.flink.table.types.utils.DataTypeUtils
+import org.apache.flink.table.types.utils.TypeConversions.{fromLegacyInfoToDataType, fromLogicalToDataType}
+import org.apache.flink.table.utils.{TableSchemaUtils, TypeMappingUtils}
+import org.apache.flink.types.Row
+import org.apache.calcite.rel.RelNode
import scala.collection.JavaConversions._
object TableSinkUtils {
/**
- * Checks if the given [[CatalogSinkModifyOperation]]'s query can be written to
- * the given [[TableSink]]. It checks if the names & the field types match. If the table
- * sink is a [[PartitionableTableSink]], also check that the partitions are valid.
+ * Checks if the given query can be written into the given sink. It checks the field types
+ * should be compatible (types should equal including precisions). If types are not compatible,
+ * but can be implicitly casted, a cast projection will be applied. Otherwise, an exception will
+ * be thrown.
+ *
+ * @param query the query to be checked
+ * @param sinkSchema the schema of sink to be checked
+ * @param typeFactory type factory
+ * @return the query RelNode which may be applied the implicitly cast projection.
+ */
+ def validateSchemaAndApplyImplicitCast(
+ query: RelNode,
+ sinkSchema: TableSchema,
+ typeFactory: FlinkTypeFactory,
+ sinkIdentifier: Option[String] = None): RelNode = {
+
+ val queryLogicalType = DataTypeUtils
+ // convert type to nullable, because we ignore nullability when writing query into sink
Review comment:
Why need to nullable?
Without this not work?
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361289645
##########
File path: flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/planner/plan/stream/sql/MiniBatchIntervalInferTest.xml
##########
@@ -222,7 +222,7 @@ LogicalProject(a=[$0], b=[$1])
<Resource name="planAfter">
<![CDATA[
Calc(select=[a, b])
-+- Join(joinType=[InnerJoin], where=[=(a0, a1)], select=[a, b, a0, b0, a1], leftInputSpec=[HasUniqueKey], rightInputSpec=[HasUniqueKey])
++- Join(joinType=[InnerJoin], where=[=(a0, a1)], select=[a, b, a0, b0, a1], leftInputSpec=[JoinKeyContainsUniqueKey], rightInputSpec=[HasUniqueKey])
Review comment:
`JoinKeyContainsUniqueKey` is correct, because `a` is the group by key of left stream and also the join field. And `a` is an int type, `cast(a as bigint)` doesn't lose information so that it keeps the unique key information of left stream.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on issue #10667: [FLINK-15313][table] Fix
can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568706092
updated to fix failed tests.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on issue #10667: [FLINK-15313][table] Fix
can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568496073
cc @JingsongLi
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on issue #10667: [FLINK-15313][table] Fix
can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568732647
Updated code according to the review comments.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot edited a comment on issue #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568504832
<!--
Meta data
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142124640 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://travis-ci.com/flink-ci/flink/builds/142212396 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Status:UNKNOWN URL:TBD TriggerType:PUSH TriggerID:154a6b2af5e9b78a5a554e60fdd40bf8effd4596
-->
## CI report:
* 544133fefeb806ec9fd181f180108b62424b2a3e Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142124640) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865)
* a2255e91d70c97beb58aaa7713df392bca12edff Travis: [SUCCESS](https://travis-ci.com/flink-ci/flink/builds/142212396) Azure: [SUCCESS](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886)
* 154a6b2af5e9b78a5a554e60fdd40bf8effd4596 UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot commented on issue #10667: [FLINK-15313][table]
Fix can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot commented on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568504832
<!--
Meta data
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:UNKNOWN URL:TBD TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
-->
## CI report:
* 544133fefeb806ec9fd181f180108b62424b2a3e UNKNOWN
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] JingsongLi commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361121651
##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/nodes/physical/batch/BatchExecSink.scala
##########
@@ -115,9 +114,9 @@ class BatchExecSink[T](
private def translateToTransformation(
withChangeFlag: Boolean,
planner: BatchPlanner): Transformation[T] = {
+
Review comment:
Remove.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361147091
##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/sinks/TableSinkUtils.scala
##########
@@ -98,5 +130,148 @@ object TableSinkUtils {
}
}
}
+
+ sink match {
+ case overwritableTableSink: OverwritableTableSink =>
+ overwritableTableSink.setOverwrite(sinkOperation.isOverwrite)
+ case _ =>
+ assert(!sinkOperation.isOverwrite, "INSERT OVERWRITE requires " +
+ s"${classOf[OverwritableTableSink].getSimpleName} but actually got " +
+ sink.getClass.getName)
+ }
+ }
+
+ /**
+ * Inferences the physical schema of [[TableSink]], the physical schema ignores change flag
+ * field and normalizes physical types (can be generic type or POJO type) into [[TableSchema]].
+ * @param queryLogicalType the logical type of query, will be used to full-fill sink physical
+ * schema if the sink physical type is not specified.
+ * @param sink the instance of [[TableSink]]
+ */
+ def inferSinkPhysicalSchema(
+ queryLogicalType: RowType,
+ sink: TableSink[_]): TableSchema = {
+ val withChangeFlag = sink match {
+ case _: RetractStreamTableSink[_] | _: UpsertStreamTableSink[_] => true
+ case _: StreamTableSink[_] => false
+ case dsts: DataStreamTableSink[_] => dsts.withChangeFlag
+ }
+ inferSinkPhysicalSchema(sink.getConsumedDataType, queryLogicalType, withChangeFlag)
+ }
+
+ /**
+ * Inferences the physical schema of [[TableSink]], the physical schema ignores change flag
+ * field and normalizes physical types (can be generic type or POJO type) into [[TableSchema]].
+ *
+ * @param consumedDataType the consumed data type of sink
+ * @param queryLogicalType the logical type of query, will be used to full-fill sink physical
+ * schema if the sink physical type is not specified.
+ * @param withChangeFlag true if the emitted records contains change flags.
+ */
+ def inferSinkPhysicalSchema(
+ consumedDataType: DataType,
+ queryLogicalType: RowType,
+ withChangeFlag: Boolean): TableSchema = {
+ // the requested output physical type which ignores the flag field
+ val requestedOutputType = inferSinkPhysicalDataType(
+ consumedDataType,
+ queryLogicalType,
+ withChangeFlag)
+ if (LogicalTypeChecks.isCompositeType(requestedOutputType.getLogicalType)) {
+ DataTypeUtils.expandCompositeTypeToSchema(requestedOutputType)
+ } else {
+ // atomic type
+ TableSchema.builder().field("f0", requestedOutputType).build()
+ }
+ }
+
+ /**
+ * Inferences the physical data type of [[TableSink]], the physical data type ignores
+ * the change flag field.
+ *
+ * @param consumedDataType the consumed data type of sink
+ * @param queryLogicalType the logical type of query, will be used to full-fill sink physical
+ * schema if the sink physical type is not specified.
+ * @param withChangeFlag true if the emitted records contains change flags.
+ */
+ def inferSinkPhysicalDataType(
Review comment:
I think even if we merge them in one method, we can't reduce code, it just mixes codes in one method. And the tuple2 type information is only needed in code generation. So I think it's better to keep them separately.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on issue #10667: [FLINK-15313][table] Fix
can't insert decimal data into sink using TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568830017
FLINK-15381 is not a blocker to this PR, that is an independent issue but should be fixed before 1.10 release.
I will verify the relative issues in my local machine. Thanks for the reminder.
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] JingsongLi commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
JingsongLi commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361123259
##########
File path: flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/typeutils/BaseRowTypeInfo.java
##########
@@ -60,7 +60,8 @@ public BaseRowTypeInfo(LogicalType... logicalTypes) {
public BaseRowTypeInfo(LogicalType[] logicalTypes, String[] fieldNames) {
super(BaseRow.class, Arrays.stream(logicalTypes)
- .map(TypeInfoLogicalTypeConverter::fromLogicalTypeToTypeInfo)
+ .map(TypeConversions::fromLogicalToDataType)
Review comment:
Just test need?
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot edited a comment on issue #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568504832
<!--
Meta data
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142124640 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:PENDING URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://travis-ci.com/flink-ci/flink/builds/142212396 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
-->
## CI report:
* 544133fefeb806ec9fd181f180108b62424b2a3e Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142124640) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865)
* a2255e91d70c97beb58aaa7713df392bca12edff Travis: [SUCCESS](https://travis-ci.com/flink-ci/flink/builds/142212396) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886)
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot edited a comment on issue #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568504832
<!--
Meta data
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142124640 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://travis-ci.com/flink-ci/flink/builds/142212396 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142222152 TriggerType:PUSH TriggerID:154a6b2af5e9b78a5a554e60fdd40bf8effd4596
Hash:154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3891 TriggerType:PUSH TriggerID:154a6b2af5e9b78a5a554e60fdd40bf8effd4596
Hash:4f0587d909b07156509eae046d029f8ee49a5cf8 Status:SUCCESS URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3911 TriggerType:PUSH TriggerID:4f0587d909b07156509eae046d029f8ee49a5cf8
Hash:4f0587d909b07156509eae046d029f8ee49a5cf8 Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142313125 TriggerType:PUSH TriggerID:4f0587d909b07156509eae046d029f8ee49a5cf8
-->
## CI report:
* 544133fefeb806ec9fd181f180108b62424b2a3e Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142124640) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865)
* a2255e91d70c97beb58aaa7713df392bca12edff Travis: [SUCCESS](https://travis-ci.com/flink-ci/flink/builds/142212396) Azure: [SUCCESS](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886)
* 154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142222152) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3891)
* 4f0587d909b07156509eae046d029f8ee49a5cf8 Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142313125) Azure: [SUCCESS](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3911)
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] flinkbot edited a comment on issue #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#issuecomment-568504832
<!--
Meta data
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://travis-ci.com/flink-ci/flink/builds/142124640 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:544133fefeb806ec9fd181f180108b62424b2a3e Status:FAILURE URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865 TriggerType:PUSH TriggerID:544133fefeb806ec9fd181f180108b62424b2a3e
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:a2255e91d70c97beb58aaa7713df392bca12edff Status:SUCCESS URL:https://travis-ci.com/flink-ci/flink/builds/142212396 TriggerType:PUSH TriggerID:a2255e91d70c97beb58aaa7713df392bca12edff
Hash:154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Status:PENDING URL:https://travis-ci.com/flink-ci/flink/builds/142222152 TriggerType:PUSH TriggerID:154a6b2af5e9b78a5a554e60fdd40bf8effd4596
Hash:154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Status:PENDING URL:https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3891 TriggerType:PUSH TriggerID:154a6b2af5e9b78a5a554e60fdd40bf8effd4596
-->
## CI report:
* 544133fefeb806ec9fd181f180108b62424b2a3e Travis: [FAILURE](https://travis-ci.com/flink-ci/flink/builds/142124640) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3865)
* a2255e91d70c97beb58aaa7713df392bca12edff Travis: [SUCCESS](https://travis-ci.com/flink-ci/flink/builds/142212396) Azure: [SUCCESS](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3886)
* 154a6b2af5e9b78a5a554e60fdd40bf8effd4596 Travis: [PENDING](https://travis-ci.com/flink-ci/flink/builds/142222152) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=3891)
<details>
<summary>Bot commands</summary>
The @flinkbot bot supports the following commands:
- `@flinkbot run travis` re-run the last Travis build
- `@flinkbot run azure` re-run the last Azure build
</details>
----------------------------------------------------------------
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
With regards,
Apache Git Services
[GitHub] [flink] wuchong commented on a change in pull request #10667:
[FLINK-15313][table] Fix can't insert decimal data into sink using
TypeInformation
Posted by GitBox <gi...@apache.org>.
wuchong commented on a change in pull request #10667: [FLINK-15313][table] Fix can't insert decimal data into sink using TypeInformation
URL: https://github.com/apache/flink/pull/10667#discussion_r361247666
##########
File path: flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/metadata/FlinkRelMdUniqueKeys.scala
##########
@@ -135,8 +138,8 @@ class FlinkRelMdUniqueKeys private extends MetadataHandler[BuiltInMetadata.Uniqu
}
case _ => // ignore
}
- //rename
- case a: RexCall if a.getKind.equals(SqlKind.AS) &&
+ //rename or cast
+ case a: RexCall if (a.getKind.equals(SqlKind.AS) || isFidelityCast(a)) &&
Review comment:
That's true. That's why we only pick the fidelity casts that just change the precision or nullabilities (not-null -> nullable).
----------------------------------------------------------------
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
With regards,
Apache Git Services