Skip to content

[BEAM-9379] Simplify BeamCalcRel inputs - #13930

Merged
apilloud merged 4 commits into
apache:masterfrom
apilloud:passthrough
Apr 8, 2021
Merged

[BEAM-9379] Simplify BeamCalcRel inputs#13930
apilloud merged 4 commits into
apache:masterfrom
apilloud:passthrough

Conversation

@apilloud

@apilloudapilloud commented Feb 8, 2021

Copy link
Copy Markdown
Member

This is removing logical type optimizations broken by #11074 and removes the passthrough Beam types as Object optimization. After this change, inputs are always converted to Calcite types except for one special case of Row (which will be fixed in the next PR).


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • Format the pull request title like [BEAM-XXX] Fixes bug in ApproximateQuantiles, where you replace BEAM-XXX with the appropriate JIRA issue, if applicable. This will automatically link the pull request to the issue.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

Post-Commit Tests Status (on master branch)

LangSDKDataflowFlinkSamzaSparkTwister2
GoBuild Status---Build Status---Build Status---
JavaBuild StatusBuild Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build StatusBuild Status
Build Status
Build Status
Build Status
PythonBuild Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
Build Status
---Build Status---
XLangBuild StatusBuild StatusBuild Status---Build Status---

Pre-Commit Tests Status (on master branch)

---JavaPythonGoWebsiteWhitespaceTypescript
Non-portableBuild StatusBuild Status
Build Status
Build Status
Build Status
Build StatusBuild StatusBuild StatusBuild Status
Portable---Build Status------------

See .test-infra/jenkins/README for trigger phrase, status and link of all Jenkins jobs.

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests

See CI.md for more information about GitHub Actions CI.

@apilloudapilloud changed the title Complex Type Passthrough Test[BEAM-9379] Fix Complex Type Passthrough in BeamCalcRelApr 6, 2021
@apilloudapilloud changed the title [BEAM-9379] Fix Complex Type Passthrough in BeamCalcRel[BEAM-9379] Simplify BeamCalcRel inputsApr 7, 2021
value = Expressions.call(expression, "getArray", Expressions.constant(index));
if (storageType == Object.class
&& TypeName.ROW.equals(fieldType.getCollectionElementType().getTypeName())) {
// Workaround for missing row output support

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is the one special case that remains, it requires rewriting the output code to support rows. That is the next PR.

@apilloud

Copy link
Copy Markdown
MemberAuthor

R: @ibzib
cc: @robinyqiu
I've rewritten BeamCalcRel's code generator for reading inputs from Beam Schema to be more strict around inputs. (There were cases were we weren't converting to Calcite types before.)

@ibzibibzib left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. But I think this would be a good time to add some comments and rename some methods to make this class easier to follow.

if (value.getType() == java.sql.Time.class) {
valueDateTime = Expressions.call(BuiltInMethod.TIME_TO_INT.method, valueDateTime);
} else if (value.getType() == Long.class) {
} else if (value.getType() == Integer.class || value.getType() == Long.class) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why does this need to include Integer now?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

The internal type is actually suppose to be int. We've been passing Calcite a Long instead and the compiler just happily upconverts when doing math between the two types. We are still doing math somewhere (window functions?) that turns this into a Long sometimes. I think even before this change we were at risk of receiving a Integer here. (In the next CL I'm switching this to the java Number interface so we are permissive on outputs.)
https://github.com/apache/calcite-avatica/blob/89e0deb510311b85b8c8bacde6d2ff70c309930e/core/src/main/java/org/apache/calcite/avatica/SqlType.java#L306

private static Expression value(Expression value, FieldType fieldType) {
switch (fieldType.getTypeName()) {
case BYTE:
return Expressions.convert_(value, Byte.class);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why are these conversions necessary? e.g. doesn't getByte already return Byte?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

These may be coming out of a Map or List as an Object. This isn't strictly necessary, I'm doing it to ensure types are what we expect. It generates a cast which results in a ClassCastException if it isn't the type we expected.

@apilloud
apilloud merged commit 567cf8b into apache:masterApr 8, 2021
@apilloud
apilloud deleted the passthrough branch April 8, 2021 22:39
@apilloudapilloud mentioned this pull request Sep 7, 2021
4 tasks
Sign up for freeto 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.

2 participants

@apilloud@ibzib