Skip to content

[FLINK-39812][table] Migrate FlinkTypeFactory to java#28284

Merged
snuyanzin merged 3 commits into
apache:masterfrom
snuyanzin:flink39812
Jun 1, 2026
Merged

[FLINK-39812][table] Migrate FlinkTypeFactory to java#28284
snuyanzin merged 3 commits into
apache:masterfrom
snuyanzin:flink39812

Conversation

@snuyanzin
Copy link
Copy Markdown
Contributor

What is the purpose of the change

This is a preliminary change before bumping Calcite to 1.39.0

The main reason here is that this class is relatively often a problem while Calcite upgrade if something is changed in interfaces (new default methods for instance)
maven just fails as

 [ERROR] error: Error while emitting FlinkTypeFactory.scala
  [ERROR] assertion failed:
  [ERROR]   cannot invokespecial org/apache/calcite/rel/type/RelDataTypeFactory.leastRestrictive, the interface is not a direct parent.
  [ERROR]      while compiling: .../flink-table-planner/src/main/scala/org/apache/flink/table/planner/calcite/FlinkTypeFactory.scala
  [ERROR]         during phase: jvm
  [ERROR]      library version: version 2.12.20
  [ERROR]     compiler version: version 2.12.20
  ...
  [INFO]   last tree to typer: TypeTree(class FlinkHintStrategies)
  [INFO]             tree tpe: org.apache.flink.table.planner.hint.FlinkHintStrategies
  ...
  [WARNING] 42 warnings found
  [ERROR] one error found

Brief change log

FlinkTypeFactory to java

Verifying this change

existing tests

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

  • Dependencies (does it add or upgrade a dependency): ( no)
  • 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 )

Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

@flinkbot
Copy link
Copy Markdown
Collaborator

flinkbot commented Jun 1, 2026

CI report:

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

Copy link
Copy Markdown
Contributor

@liuyongvs liuyongvs left a comment

Choose a reason for hiding this comment

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

LGTM +1

String[] fieldNames, LogicalType[] fieldTypes, StructKind structKind) {
FieldInfoBuilder b = builder();
b.kind(structKind);
// mirror Scala's `fieldNames.zip(fieldTypes)`, which truncates to the shorter sequence
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can be simplified. Remove comment and Math.min

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sure, done

.map(PlannerTypeUtils::removeLegacyTypes)
.collect(Collectors.toList());
.collect(Collectors.toList())
.toArray(new LogicalType[0]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: isn't List easier to handle than arrays?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

made using lists here

@snuyanzin snuyanzin force-pushed the flink39812 branch 2 times, most recently from 9a1c183 to 2c97164 Compare June 1, 2026 14:23
Copy link
Copy Markdown
Contributor

@fhueske fhueske left a comment

Choose a reason for hiding this comment

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

Thanks for porting the type factory @snuyanzin.

I've checked the ported code and didn't spot any correctness issues.
Left a few comments with minor improvement suggestions.
Maybe we can use Java lists rather than arrays where possible?

Cheers, Fabian

.map(PlannerTypeUtils::removeLegacyTypes)
.collect(Collectors.toList());
.collect(Collectors.toList())
.toArray(new LogicalType[0]);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

+1

return createSqlType(SqlTypeName.TINYINT);
case SMALLINT:
return createSqlType(SqlTypeName.SMALLINT);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit

Suggested change

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed

Comment on lines +256 to +258
final Optional<RelDataType> resolved = resolveAllIdenticalTypes(types);
final RelDataType leastRestrictive =
resolved.isPresent() ? resolved.get() : super.leastRestrictive(types);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit:

Should be possible to simplified to something like

Suggested change
final Optional<RelDataType> resolved = resolveAllIdenticalTypes(types);
final RelDataType leastRestrictive =
resolved.isPresent() ? resolved.get() : super.leastRestrictive(types);
final RelDataType leastRestrictive = resolveAllIdenticalTypes(types)
.getOrElse(super.leastRestrictive(types));

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

case DECIMAL:
return new DecimalType(relDataType.getPrecision(), relDataType.getScale());

// time indicators
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit:
the comment does not really apply anymore because the outer else branch of case TIMESTAMP does not handle a time indicator but a regular TIMESTAMP type.

Copy link
Copy Markdown
Contributor Author

@snuyanzin snuyanzin Jun 1, 2026

Choose a reason for hiding this comment

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

removed

}
}
return new LocalZonedTimestampType(relDataType.getPrecision());
// temporal types
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TIMESTAMP and TIMESTAMP_WITH_LOCAL_TIME_ZONE are missing from the temporal types because they are handled above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed, not sure we need it there...

Comment on lines +79 to +81
new String[] {"f1", "f2", "f3"},
new LogicalType[] {
new IntType(), new BigIntType(), new VarCharType()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
new String[] {"f1", "f2", "f3"},
new LogicalType[] {
new IntType(), new BigIntType(), new VarCharType()
List.of("f1", "f2", "f3"),
List.of(new IntType(), new BigIntType(), new VarCharType())

should work as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yep, done

Copy link
Copy Markdown
Contributor

@fhueske fhueske left a comment

Choose a reason for hiding this comment

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

+1 to merge.

Thank you, Fabian

@github-actions github-actions Bot added the community-reviewed PR has been reviewed by the community. label Jun 1, 2026
@snuyanzin snuyanzin merged commit 50ff839 into apache:master Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-reviewed PR has been reviewed by the community.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants