Skip to content

[BEAM-2018] refine expression of Calcite method/function#2656

Closed
mingmxu wants to merge 2 commits intoapache:DSL_SQLfrom
mingmxu:BEAM-2018
Closed

[BEAM-2018] refine expression of Calcite method/function#2656
mingmxu wants to merge 2 commits intoapache:DSL_SQLfrom
mingmxu:BEAM-2018

Conversation

@mingmxu
Copy link

@mingmxu mingmxu commented Apr 23, 2017

In this PR, BeamSQLFnExecutor is introduced to replace BeamSQLSpELExecutor, as the executor of SqlOperator expressions.

Several common operators are added here as reference, more are needed to cover all operators defined in org.apache.calcite.sql.fun.SqlStdOperatorTable.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 3ce5f7b on XuMingmin:BEAM-2018 into ** on apache:DSL_SQL**.

@aaltay
Copy link
Member

aaltay commented Apr 24, 2017

R: @jbonofre

@mingmxu
Copy link
Author

mingmxu commented Apr 25, 2017

@davorbonaci can you also take a peek here?

boolean result = true;
for (BeamSqlExpression exp : operands) {
BeamSqlPrimitive<Boolean> expOut = exp.evaluate(inputRecord);
result = result && expOut.getValue();
Copy link
Contributor

Choose a reason for hiding this comment

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

short-circuit strategy can be applied here?

Copy link
Author

Choose a reason for hiding this comment

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

+1, also for OR

boolean result = false;
for (BeamSqlExpression exp : operands) {
BeamSqlPrimitive<Boolean> expOut = exp.evaluate(inputRecord);
result = result || expOut.getValue();
Copy link
Contributor

Choose a reason for hiding this comment

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

short-circuit strategy can be applied here

}
case SMALLINT:
case TINYINT:
if (!(fieldValue instanceof Integer)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Integer => Short?

Copy link
Author

Choose a reason for hiding this comment

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

+1

throw new InvalidFieldException(
String.format("[%s] doesn't match type [%s]", fieldValue, fieldType));
} else {
return Integer.valueOf(fieldValue.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that XXX.valueOf() calls in getFieldValue is not necessary? Because the return value of getFieldValue is Object, and since the value and type are checked in addField() method, so type cast in methods like getShort, getInteger are safe?

Copy link
Author

Choose a reason for hiding this comment

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

sounds right, it's already checked in both Constructor and addField

@@ -108,24 +107,24 @@ public BeamSQLRow decode(InputStream inStream, org.apache.beam.sdk.coders.Coder.

switch (type.getFieldsType().get(idx)) {
case INTEGER:
Copy link
Contributor

Choose a reason for hiding this comment

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

we should use the nested context to corresponds with the encode method?

Copy link
Author

Choose a reason for hiding this comment

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

My preferred way is NESTED...OUTER, any concern?

case INTEGER:
return value instanceof Integer;
case SMALLINT:
case TINYINT:
Copy link
Contributor

Choose a reason for hiding this comment

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

Maping sql TINYINT to Java Byte maybe more appropriate?(Both of them are 1 byte long).

Copy link
Author

Choose a reason for hiding this comment

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

sounds a good option

case VARCHAR:
stringCoder.encode(value.getString(idx), outStream, nested);
break;
case TIME:
Copy link
Contributor

Choose a reason for hiding this comment

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

Why Time, Timestamp related code are deleted?

Copy link
Author

Choose a reason for hiding this comment

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

It's moved to a separated task, as a hard dependency of window support in task 2006.

Changes:
1. revert BEAM dependency to 0.6.0 to avoid impact of changes in master branch;
2. updates as discussion during review;

refine BeamSqlRowCoder
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 1db5de8 on XuMingmin:BEAM-2018 into ** on apache:DSL_SQL**.

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 1db5de8 on XuMingmin:BEAM-2018 into ** on apache:DSL_SQL**.

@mingmxu
Copy link
Author

mingmxu commented May 2, 2017

Retest this please

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 1db5de8 on XuMingmin:BEAM-2018 into ** on apache:DSL_SQL**.

@mingmxu
Copy link
Author

mingmxu commented May 2, 2017

the failure should be safe to ignore.
all pass, except org.apache.beam.examples.WordCountIT.testE2EWordCount

Copy link
Member

@davorbonaci davorbonaci left a comment

Choose a reason for hiding this comment

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

LGTM; ready for merge to a feature branch modulo a few superficial comments.

dsls/pom.xml Outdated
<groupId>org.apache.beam</groupId>
<artifactId>beam-parent</artifactId>
<version>0.7.0-SNAPSHOT</version>
<version>0.6.0</version>
Copy link
Member

Choose a reason for hiding this comment

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

Use current version for the parent pom.

dsls/sql/pom.xml Outdated
<groupId>org.apache.beam</groupId>
<artifactId>beam-dsls-parent</artifactId>
<version>0.7.0-SNAPSHOT</version>
<version>0.6.0</version>
Copy link
Member

Choose a reason for hiding this comment

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

Use current version for the parent pom, but instead overwrite dependencyManagement section they way you need it.

/**
*
*/
private static final long serialVersionUID = 3445015747629217342L;
Copy link
Member

Choose a reason for hiding this comment

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

let's remove all UIDs?

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling d98b00a on XuMingmin:BEAM-2018 into ** on apache:DSL_SQL**.

@mingmxu
Copy link
Author

mingmxu commented May 4, 2017

@davorbonaci
The test failure org.apache.beam.examples.WordCountIT.testE2EWordCount is still there, I think an sync-up from beam/master is required after that.

asfgit pushed a commit that referenced this pull request May 4, 2017
@mingmxu
Copy link
Author

mingmxu commented May 4, 2017

Retest this please

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling d98b00a on XuMingmin:BEAM-2018 into ** on apache:DSL_SQL**.

@mingmxu mingmxu closed this May 4, 2017
@mingmxu mingmxu deleted the BEAM-2018 branch May 4, 2017 17:01
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.

5 participants