Skip to content

[FLINK-35854][table] Upgrade Calcite version to 1.35.0 #26547

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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

snuyanzin
Copy link
Contributor

@snuyanzin snuyanzin commented May 12, 2025

What is the purpose of the change

Upgrade Calcite to 1.35.0

Brief change log

There are several major changes done in Calcite 1.35.0

About commits
3242726 - Update poms and NOTICE files
bec22cc - Remove RelBuilder
2161225 - Remove SqlTimestampAddFunction
f7c5c96 - Remove CompositeSingleOperandTypeChecker
19cb1e3 - Update Calcite classes to be synced with https://github.com/apache/calcite/releases/tag/calcite-1.35.0
1d284f2 - Update Flink classes
9ba9ab6 - Add FlinkCalciteTableMappingRule
929ce63 - Update plans
985e500 - Update SqlNodeToCallOperationTest
0faf592 - Add LiteralAggFunction
acc7307 - Update plans after LiteralAggFunction
4dc67fd - Update JoinTest.testJoinUDTFWithInvalidJoinHint

Verifying this change

existing tests

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (yes )
  • The public API, i.e., is any changed class annotated with @Public(Evolving): ( no)
  • The serializers: ( no)
  • The runtime per-record code paths (performance sensitive): (no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: ( no)
  • The S3 file system connector: ( no)

Documentation

  • Does this pull request introduce a new feature? ( no)
  • If yes, how is the feature documented? (not applicable)

@flinkbot
Copy link
Collaborator

flinkbot commented May 12, 2025

CI report:

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

[INFO] | +- org.apache.calcite.avatica:avatica-core:jar:1.23.0:compile
[INFO] | +- org.apiguardian:apiguardian-api:jar:1.1.2:compile
[INFO] | +- org.checkerframework:checker-qual:jar:3.12.0:compile
[INFO] | +- org.checkerframework:checker-qual:jar:3.10.0:compile
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is not related to this commit, however seems at some point the version was downgraded in Flink.
There is no critical changes, so should be ok


@Override
public DataType getResultType() {
return DataTypes.BOOLEAN();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is probably the main question: should we have it for different types or boolean is enough?
So far in existing tests there is only boolean in use

@snuyanzin
Copy link
Contributor Author

@flinkbot run azure

@@ -3061,34 +3061,6 @@ SqlNode SqlReset() :
}
}


/** Parses a TRY_CAST invocation. */
Copy link
Contributor Author

@snuyanzin snuyanzin May 12, 2025

Choose a reason for hiding this comment

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

Since now TRY_CAST comes with Calcite https://issues.apache.org/jira/browse/CALCITE-4771

@@ -168,8 +168,8 @@ public SqlLibrary semantics() {
}

@Override
public boolean allowCoercionStringToArray() {
return SqlConformanceEnum.DEFAULT.allowCoercionStringToArray();
public boolean allowLenientCoercion() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suddenly was just renamed in Calcite apache/calcite@b042094

@snuyanzin snuyanzin force-pushed the flink35854_1 branch 4 times, most recently from 0bab0b8 to 6c34459 Compare May 14, 2025 07:19
@@ -293,6 +292,8 @@
"DATETIME_DIFF"
"DATETIME_INTERVAL_CODE"
"DATETIME_INTERVAL_PRECISION"
"DAYOFWEEK"
Copy link
Contributor

Choose a reason for hiding this comment

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

I am curious why these 2 re in this list and not in nonReservedKeywordsToAdd.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -224,7 +224,6 @@
"RESUME"
"TABLES"
"TIMESTAMP_LTZ"
"TRY_CAST"
Copy link
Contributor

Choose a reason for hiding this comment

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

I am curious why TRY_CAST is removed as a keyword. I had assumed it would still be a keyword but Calcite would now provide the implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because it was added to keywords on Calcite level, no need to add it one more time

@snuyanzin snuyanzin force-pushed the flink35854_1 branch 3 times, most recently from e616ba0 to b8a8b8b Compare May 26, 2025 20:58
@snuyanzin snuyanzin force-pushed the flink35854_1 branch 2 times, most recently from af327eb to 44d710b Compare May 27, 2025 19:59
@snuyanzin snuyanzin force-pushed the flink35854_1 branch 2 times, most recently from a8b5103 to fc3c7e7 Compare May 27, 2025 20:39
* <li>Added in FLINK-34057, FLINK-34058, FLINK-34312: Lines 452 ~ 469
* </ol>
*/
class AggConverter implements SqlVisitor<Void> {
Copy link
Contributor Author

@snuyanzin snuyanzin May 27, 2025

Choose a reason for hiding this comment

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

The result of this commit apache/calcite@568ce12

where SqlToRelConverter was splitted into 2 classes

@snuyanzin snuyanzin marked this pull request as ready for review May 27, 2025 21:20

/** Rules that determine whether a type is castable from another type. */
public class FlinkCalciteTableMappingRule implements SqlTypeMappingRule {
private static final FlinkCalciteTableMappingRule INSTANCE;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The behavior of SqlTypeCoercionRule was changed (https://issues.apache.org/jira/browse/CALCITE-5662) and started leading to a number of failures in CastFunctionITCase.
New mapping rule makes it working in same way as before

Copy link
Contributor

@twalthr twalthr left a comment

Choose a reason for hiding this comment

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

Thank you for this PR @snuyanzin. This must have been painful work. I added some comments.

* <li>Added in FLINK-32474: Lines 3046 ~ 3080
* <li>Added in FLINK-34312: Lines 5827 ~ 5838
* <li>Added in FLINK-34057, FLINK-34058, FLINK-34312: Lines 6285 ~ 6303
* <li>Added in FLINK-29081, FLINK-28682, FLINK-33395: Lines 673 ~ 690
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for updating all these lines. Very helpful, but I'm sure also a lot of work!

SqlStdOperatorTable.POSITION.createCall(
SqlParserPos.ZERO, call.operand(1), call.operand(0))));

// "INSTR(string, substring, position, occurrence) is equivalent to
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to document those function synonyms?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

don't think so
existing position, instr are covered in doc
with other args just fail with validation

@@ -8001,6 +8003,8 @@ SqlPostfixOperator PostfixRowOperator() :
| < DATETIME_INTERVAL_PRECISION: "DATETIME_INTERVAL_PRECISION" >
| < DATETIME_TRUNC: "DATETIME_TRUNC" >
| < DAY: "DAY" >
| < DAYOFWEEK: "DAYOFWEEK" >
Copy link
Contributor

Choose a reason for hiding this comment

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

update documentation, do we also support those in runtime code? or at least throw a proper error message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's already covered in doc

- sql: DAYOFYEAR(date)
description: Returns the day of a year (an integer between 1 and 366) from SQL date. Equivalent to EXTRACT(DOY FROM date). E.g., DAYOFYEAR(DATE '1994-09-27') returns 270.
- sql: DAYOFMONTH(date)
description: Returns the day of a month (an integer between 1 and 31) from SQL date. Equivalent to EXTRACT(DAY FROM date). E.g., DAYOFMONTH(DATE '1994-09-27') returns 27.
- sql: DAYOFWEEK(date)
description: Returns the day of a week (an integer between 1 and 7) from SQL date. Equivalent to EXTRACT(DOW FROM date). E.g., DAYOFWEEK(DATE '1994-09-27') returns 3.

}

/** Built-in Long Literal aggregate function. */
public static class LongLiteralAggFunction extends LiteralAggFunction {
Copy link
Contributor

Choose a reason for hiding this comment

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

No INT? Are byte and short ever called?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added for int as well
however we don't have any test calling anything else except for boolean


@Override
public UnresolvedReferenceExpression[] aggBufferAttributes() {
return new UnresolvedReferenceExpression[] {literalAgg};
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we actually need to use any state? Can't this be empty array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

looks like with current framework it is not possible to do it...
At least this test requires it JoinWithoutKeyITCase#testNonKeySemi

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

Successfully merging this pull request may close these issues.

4 participants