Skip to content

expression virtual column selector fix for expressions which produce array types#7958

Merged
clintropolis merged 5 commits intoapache:masterfrom
clintropolis:expr-multi-val-selector-fix
Jun 26, 2019
Merged

expression virtual column selector fix for expressions which produce array types#7958
clintropolis merged 5 commits intoapache:masterfrom
clintropolis:expr-multi-val-selector-fix

Conversation

@clintropolis
Copy link
Copy Markdown
Member

This PR fixes an omission in #7588 of coercing ExprEval that output array types back into a string list, which caused issues with using filters against expression virtual columns that produced an array output, as well as problems coercing output for scan queries in druid-sql.

The added test to MultiValueDimensionTest.java would fail with no matching results prior to the changes of this PR.

Additionally, added a few druid-sql tests using multi-value string dimensions as varchar to ensure things work as expected, 3 of which would have failed prior to this PR.

@clintropolis clintropolis changed the title Expr multi val selector fix expression virtual column selector fix for expressions which produce array types Jun 25, 2019
@@ -108,7 +108,11 @@ public Object getObject()
{
// No need for null check on getObject() since baseSelector impls will never return null.
//noinspection ConstantConditions
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the //noinspection still on the right line?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't believe it is needed anymore, will remove.

return baseSelector.getObject().value();
ExprEval eval = baseSelector.getObject();
if (eval.isArray()) {
return Arrays.stream(eval.asArray()).map(String::valueOf).collect(Collectors.toList());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we allow null numbers in lists? If so, this'll turn them into "null" rather than keeping them as null. What's the right behavior?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oops, probably not "null". There are a few other places are doing this as well, will fix and add some tests around this behavior.

Copy link
Copy Markdown
Contributor

@jihoonson jihoonson left a comment

Choose a reason for hiding this comment

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

LGTM

private static Object coerceListDimToStringArray(List val)
{
Object[] arrayVal = val.stream().map(Object::toString).toArray(String[]::new);
Object[] arrayVal = val.stream().map(x -> x != null ? x.toString() : x).toArray(String[]::new);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: x != null ? x.toString() : null looks more clear to me.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have some more follow-up work to do, will try to revisit and clean stuff up a bit more in the future.

@clintropolis clintropolis merged commit 151edee into apache:master Jun 26, 2019
@clintropolis clintropolis deleted the expr-multi-val-selector-fix branch June 26, 2019 23:57
gianm pushed a commit to implydata/druid-public that referenced this pull request Jul 4, 2019
…array types (apache#7958)

* fix bug in multi-value string expression column selector

* more test

* imports!!

* fixes
@clintropolis clintropolis added this to the 0.16.0 milestone Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants