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

Fix StPoint scalar function usage in multi-stage engine intermediate stage #11731

Merged
merged 1 commit into from
Oct 4, 2023

Conversation

xiangfu0
Copy link
Contributor

@xiangfu0 xiangfu0 commented Oct 3, 2023

Current stPoint only supports boolean as 3rd argument, this is not aligned with Transformer function which can be either INT or BOOLEAN.

  1. Make Scalar function signature for stPoint to use Object as 3rd argument
  2. Update StPoint registration in TransformFunctionType
  3. Support both BYTES and STRING in H3IndexFilterOperator to handle binary literal values.
  4. Add test for v2 intermediate stage in org.apache.pinot.integration.tests.custom.GeoSpatialTest

@xiangfu0 xiangfu0 added backward-incompat Referenced by PRs that introduce or fix backward compat issues geo multi-stage Related to the multi-stage query engine labels Oct 3, 2023
@xiangfu0 xiangfu0 changed the title Add test for StPoint and stDistance functions in intermediate stage Modify StPoint scalar function signature for v2 compatibility Oct 3, 2023
@codecov-commenter
Copy link

codecov-commenter commented Oct 3, 2023

Codecov Report

Merging #11731 (e7481da) into master (78fc66b) will decrease coverage by 0.02%.
Report is 1 commits behind head on master.
The diff coverage is 63.63%.

@@             Coverage Diff              @@
##             master   #11731      +/-   ##
============================================
- Coverage     63.12%   63.10%   -0.02%     
  Complexity     1118     1118              
============================================
  Files          2342     2342              
  Lines        125889   125924      +35     
  Branches      19360    19364       +4     
============================================
+ Hits          79462    79469       +7     
- Misses        40783    40799      +16     
- Partials       5644     5656      +12     
Flag Coverage Δ
integration <0.01% <0.00%> (ø)
integration1 <0.01% <0.00%> (ø)
integration2 0.00% <0.00%> (ø)
java-11 50.13% <63.63%> (-12.93%) ⬇️
java-17 62.95% <63.63%> (-0.03%) ⬇️
java-20 62.95% <63.63%> (-0.01%) ⬇️
temurin 63.10% <63.63%> (-0.02%) ⬇️
unittests 63.10% <63.63%> (-0.02%) ⬇️
unittests1 67.25% <63.63%> (-0.04%) ⬇️
unittests2 14.43% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...e/pinot/common/function/TransformFunctionType.java 89.32% <100.00%> (ø)
...geospatial/transform/function/StPointFunction.java 100.00% <100.00%> (ø)
...geospatial/transform/function/ScalarFunctions.java 82.75% <0.00%> (-3.45%) ⬇️
...ot/core/operator/filter/H3IndexFilterOperator.java 82.65% <40.00%> (-0.69%) ⬇️

... and 18 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@xiangfu0 xiangfu0 force-pushed the fixing-binary-intermediate-stage branch from db36255 to 35d3db4 Compare October 3, 2023 21:16
@xiangfu0 xiangfu0 force-pushed the fixing-binary-intermediate-stage branch 3 times, most recently from 3bb7b74 to ad55f9f Compare October 3, 2023 23:11
@@ -213,7 +213,7 @@ public enum TransformFunctionType {
ST_GEOG_FROM_WKB("ST_GeogFromWKB", ReturnTypes.explicit(SqlTypeName.VARBINARY), OperandTypes.BINARY),
ST_GEOM_FROM_WKB("ST_GeomFromWKB", ReturnTypes.explicit(SqlTypeName.VARBINARY), OperandTypes.BINARY),
ST_POINT("ST_Point", ReturnTypes.explicit(SqlTypeName.VARBINARY),
OperandTypes.family(ImmutableList.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
OperandTypes.family(ImmutableList.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.ANY),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
OperandTypes.family(ImmutableList.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.ANY),
OperandTypes.or(
OperandTypes.family(ImmutableList.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC)),
OperandTypes.family(ImmutableList.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.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.

somehow this doesn't honor ordinal -> ordinal > 1 && ordinal < 4 to handle variable number of parameters.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When I try to define this as:

  ST_POINT("ST_Point", ReturnTypes.explicit(SqlTypeName.VARBINARY),
      OperandTypes.or(
          OperandTypes.family(ImmutableList.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC),
              ordinal -> ordinal > 1 && ordinal < 4),
          OperandTypes.family(ImmutableList.of(SqlTypeFamily.NUMERIC, SqlTypeFamily.NUMERIC, SqlTypeFamily.BOOLEAN),
              ordinal -> ordinal > 1 && ordinal < 4)),
      "stPoint"),

The StPoint(1,2) will fail.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah. i see. that's fine for now

@xiangfu0 xiangfu0 force-pushed the fixing-binary-intermediate-stage branch 2 times, most recently from 702a0a5 to 8b03ee5 Compare October 4, 2023 04:21
@xiangfu0 xiangfu0 force-pushed the fixing-binary-intermediate-stage branch from 8b03ee5 to e7481da Compare October 4, 2023 07:43
Point point = GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(x, y));
if (isGeography) {
if (BooleanUtils.toBoolean(isGeography)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what if isGeography is not given boolean up?

Copy link
Contributor

Choose a reason for hiding this comment

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

BooleanUtils.toBoolean actually works for number/string/boolean type.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. for non-boolean value, will it handle exception?

Copy link
Contributor Author

@xiangfu0 xiangfu0 Oct 4, 2023

Choose a reason for hiding this comment

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

this is our internal boolean util, it can handle number/string/boolean

public static boolean toBoolean(Object booleanObject) {
    if (booleanObject == null) {
      return false;
    } else if (booleanObject instanceof String) {
      return BooleanUtils.toBoolean((String) booleanObject);
    } else if (booleanObject instanceof Number) {
      return ((Number) booleanObject).intValue() == INTERNAL_TRUE;
    } else if (booleanObject instanceof Boolean) {
      return (boolean) booleanObject;
    } else {
      throw new IllegalArgumentException("Illegal type for boolean conversion: " + booleanObject.getClass());
    }
  }

Copy link
Contributor

@walterddr walterddr left a comment

Choose a reason for hiding this comment

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

lgtm we should add more tests for other ST later

@xiangfu0 xiangfu0 merged commit 3329d83 into apache:master Oct 4, 2023
19 checks passed
@xiangfu0 xiangfu0 deleted the fixing-binary-intermediate-stage branch October 4, 2023 17:46
@xiangfu0 xiangfu0 removed the backward-incompat Referenced by PRs that introduce or fix backward compat issues label Oct 4, 2023
@xiangfu0 xiangfu0 changed the title Modify StPoint scalar function signature for v2 compatibility Fix StPoint scalar function usage in multi-stage engine intermediate stage Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
geo multi-stage Related to the multi-stage query engine
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants