-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[multistage] Fix return type for AVG aggregate function #10314
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,10 @@ | |
| */ | ||
| package org.apache.pinot.query.type; | ||
|
|
||
| import org.apache.calcite.rel.type.RelDataType; | ||
| import org.apache.calcite.rel.type.RelDataTypeFactory; | ||
| import org.apache.calcite.rel.type.RelDataTypeSystemImpl; | ||
| import org.apache.calcite.sql.type.SqlTypeName; | ||
|
|
||
|
|
||
| /** | ||
|
|
@@ -50,4 +53,11 @@ public int getMaxNumericScale() { | |
| public int getMaxNumericPrecision() { | ||
| return MAX_DECIMAL_PRECISION_DIGIT; | ||
| } | ||
|
|
||
| @Override | ||
| public RelDataType deriveAvgAggType(RelDataTypeFactory typeFactory, | ||
| RelDataType argumentType) { | ||
| return typeFactory.createTypeWithNullability( | ||
| typeFactory.createSqlType(SqlTypeName.DOUBLE), false); | ||
|
Comment on lines
+60
to
+61
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the right way to fix the issue. we should rely on Calcite's derived type system to figure out what the return type should be. this way all AVG results are returning as double which is going to cause more issue than it resolves.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. based on a coarse read, we should check the input decimal precision and try to do upcast to the appropriate floating point type. (e.g. the scale and precision
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review! I resorted to using double datatype for AVG because that's what we do in V1 engine. We could maybe do what postgres does. Thoughts?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on offline discussion, created oss issue #10318 to determine the logic for AVG return type. |
||
| } | ||
| } | ||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,11 +20,6 @@ | |
| } | ||
| }, | ||
| "queries": [ | ||
| { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Query on H2 database is returning an INT. Couldn't find a better workaround other than removing this test for H2. Would appreciate inputs here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we comment out this test for now instead of removing ? Will |
||
| "psql": "4.2.7", | ||
| "description": "average int", | ||
| "sql": "SELECT avg(int_col) FROM {tbl}" | ||
| }, | ||
| { | ||
| "psql": "4.2.7", | ||
| "description": "average double", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch! You will need to make some changes to the
WindowFunctionsPlans.jsonto pick up the casting in the plans (I've usedAVGquite extensively in that file)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved all test issues.