-
Notifications
You must be signed in to change notification settings - Fork 25.5k
ESQL: Fix CASE when conditions are multivalued #112401
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 6 commits
bbc4ddf
ecf9598
c91a561
3164322
0981475
0dad8df
e4084b7
2df137d
9a6437d
8dd6b0d
b6644ff
859b53f
2702313
7ef7330
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 |
---|---|---|
|
@@ -32,7 +32,8 @@ public void registerException(Exception exception) { | |
}; | ||
|
||
/** | ||
* Create a new warnings object based on the given mode | ||
* Create a new warnings object based on the given mode which warns that | ||
* it treats the result as {@code null}. | ||
* @param warningsMode The warnings collection strategy to use | ||
* @param source used to indicate where in the query the warning occurred | ||
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. I've given us a little more flexibility, specifically so I can tell folks that multivalues in CASE default to |
||
* @return A warnings collector object | ||
|
@@ -41,6 +42,17 @@ public static Warnings createWarnings(DriverContext.WarningsMode warningsMode, S | |
return createWarnings(warningsMode, source, "treating result as null"); | ||
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. nit: to avoid drift, we could put 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. 👍 |
||
} | ||
|
||
/** | ||
* Create a new warnings object based on the given mode which warns that | ||
* it treats the result as {@code false}. | ||
* @param warningsMode The warnings collection strategy to use | ||
* @param source used to indicate where in the query the warning occurred | ||
* @return A warnings collector object | ||
*/ | ||
public static Warnings createWarningsTreatedAsFalse(DriverContext.WarningsMode warningsMode, Source source) { | ||
return createWarnings(warningsMode, source, "treating result as false"); | ||
} | ||
|
||
/** | ||
* Create a new warnings object based on the given mode | ||
* @param warningsMode The warnings collection strategy to use | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -103,9 +103,12 @@ public Case( | |||||
type = { | ||||||
"boolean", | ||||||
"cartesian_point", | ||||||
"cartesian_shape", | ||||||
"date", | ||||||
"date_nanos", | ||||||
"double", | ||||||
"geo_point", | ||||||
"geo_shape", | ||||||
"integer", | ||||||
"ip", | ||||||
"keyword", | ||||||
|
@@ -224,18 +227,13 @@ public boolean foldable() { | |||||
if (condition.condition.foldable() == false) { | ||||||
return false; | ||||||
} | ||||||
Object o = condition.condition.fold(); | ||||||
if (o instanceof List) { | ||||||
if (Boolean.TRUE.equals(condition.condition.fold())) { | ||||||
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. ++ |
||||||
/* | ||||||
* multivalued fields fold to null which folds to false. | ||||||
* So they *are* foldable if the value is foldable. | ||||||
|
* So they *are* foldable if the value is foldable. | |
* So they *are* foldable if remaining list of conditions is foldable. |
Same in line 271.
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.
Nice tests!
ROW foo = CASE([true, true], ...
just to make it obvious thatCASE
doesn't have implicitANY
orALL
logic.ROW a = [true, false] | EVAL c = CASE(MV_SLICE(a, 0, 2), "foo", "bar")
as well? This one failed differently from others, so I guess it exercised a different code path? A test case with an mv expression insideCASE
is probably a good idea, anyway. Or, similarly but more realistically, using a conversion function likeROW a = ["true", "false"] | EVAL c = CASE(a::boolean, "foo", "bar")
FROM idx* | EVAL x = CASE(field::boolean, 1, 2)
; I'd only do that if we expect weird interactions with block loading, though, which probably is not the case.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.
Generally if you ask "should we add this csv-spec test?" the answer is just yes. It's cheap.