Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hotfix][Table SQL / API] fix create table from values decimal issue #24981

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

empathy87
Copy link
Contributor

What is the purpose of the change

The following code fails on the second fromValues:

List<Row> rows1 = new ArrayList<>();
rows1.add(Row.of(new BigDecimal("1.01")));
final Table table1 = tableEnv().fromValues(rows1);
List<Row> rows2 = new ArrayList<>();
rows2.add(Row.of(new BigDecimal("0.01")));
final Table table2 = tableEnv().fromValues(rows2);

with an exception

org.apache.flink.table.api.ValidationException: Decimal scale must be between 0 and the precision 1 (both inclusive).

	at org.apache.flink.table.types.logical.DecimalType.<init>(DecimalType.java:76)
	at org.apache.flink.table.types.logical.DecimalType.<init>(DecimalType.java:85)
	at org.apache.flink.table.api.DataTypes.DECIMAL(DataTypes.java:283)
	at org.apache.flink.table.types.utils.ValueDataTypeConverter.convertToDecimalType(ValueDataTypeConverter.java:131)
	at org.apache.flink.table.types.utils.ValueDataTypeConverter.extractDataType(ValueDataTypeConverter.java:69)
	at org.apache.flink.table.expressions.ValueLiteralExpression.deriveDataTypeFromValue(ValueLiteralExpression.java:354)

The reason is that the object new BigDecimal("0.01") has scale = 2 and precision = 1, which is not appropriate for Flink Decimal type. So, Flink Decimal type creation from BigDecimal value should be adjusted.

Brief change log

  • Added precision adjustment in ValueDataTypeConverter::convertToDecimalType to reflect that BigDecimal could have precision less than scale

Verifying this change

This change is a trivial rework / code cleanup without any test coverage.

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, Kubernetes/Yarn, 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)

@flinkbot
Copy link
Collaborator

flinkbot commented Jun 25, 2024

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run azure re-run the last Azure build

Copy link
Contributor

@dylanhz dylanhz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants