-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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 'is not null' is invalid for array-type in druid-sql #10921
Conversation
is not null
is invalid for array-type in druid-sqlThere 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.
👍 thanks for the fix, this was my bad I think 😅
Any chance you could add a test for this case? https://github.com/apache/druid/blob/master/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java is the catch-all bucket where we typically add functional query tests, and https://github.com/apache/druid/blob/master/sql/src/test/java/org/apache/druid/sql/calcite/util/CalciteTests.java is where you can find the data that these tests operate on, if it helps.
Hey, i had try to add a test in https://github.com/apache/druid/blob/master/sql/src/test/java/org/apache/druid/sql/calcite/CalciteQueryTest.java. |
Hmm, yeah, true array types aren't quite fully supported throughout the query engine yet. We've got some functions to interact with multi-value string dimensions as if they were arrays, as well as array constants, but the result row signatures are still for the most part non-array types because it's not quite there yet (no grouping on the rows as complete arrays for example). You might be able to use an array constant on a scan query to get the right row signature, but I'm not certain about that because in the native druid query, array types will still currently end up as STRING virtual columns I believe. |
Thanks for your tips, I have try to run |
Ah yeah, don't do that 😅 Hmm, I guess i'm having trouble determining how this bug is hit if we can't replicate it in the tests. I guess this area of the code has seem a fair bit of refactor over the last few releases, so maybe it used to be possible? That said, it seems like it should be a harmless change. I'll have a closer look and see if I can think of a way to trigger it. |
I have checked the latest code in master branch, and it's still return |
Oops, forgot to look into this, sorry! I will try to have a look this weekend. |
This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the dev@druid.apache.org list. Thank you for your contributions. |
This pull request/issue has been closed due to lack of activity. If you think that |
Fixes #10525
Description
Fix the bug : incorrect results (including nulls) when querying string-array column(let's say it's
col
) with col <> '' and col is not nullReason: When we use
is not null
filter in SQL, Calcite will treat it astruefilter
through call stack as beflow:DruidPlanner.plan(final String sql) -> PlannerImpl.rel(SqlNode sql) ->SqlToRelConverter.convertQuery(SqlNode query, boolean needsValidation, boolean top) ->SqlToRelConverter.convertQueryRecursive(SqlNode query, boolean top, RelDataType targetRowType)->SqlToRelConverter.convertSelect(SqlSelect select, boolean top) -> SqlToRelConverter.convertSelectImpl(SqlToRelConverter.Blackboard bb, SqlSelect select) -> SqlToRelConverter.convertWhere(SqlToRelConverter.Blackboard bb, SqlNode where) -> RexCall.isAlwaysTrue()-> AbstractSqlType.isNullable()
The last method
AbstractSqlType.isNullable()
will return false in our arrayColumnType. Because in the methodCalcites.createSqlArrayTypeWithNullability()
, we only specifynullable
praram for elementType in arrayColumnType,however,
typeFactory.createArrayType()
will invokenew ArraySqlType(elementType, false)
to return a new RelDataType.Thus, we will got incorrect results (including nulls) when use
is not null
Solution: support specify
nullable
praram for arrayColumnTypeThis PR has:
Key changed/added classes in this PR
org.apache.druid.sql.calcite.planner.Calcites