-
Notifications
You must be signed in to change notification settings - Fork 188
added cloudwatch style contains operator #5219
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
base: main
Are you sure you want to change the base?
Changes from all commits
ad44495
852e5fb
f5b3bbf
ac8c74f
0dc8e95
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 |
|---|---|---|
|
|
@@ -945,6 +945,7 @@ geoIpProperty | |
| | GREATER | ||
| | NOT_GREATER | ||
| | REGEXP | ||
| | CONTAINS | ||
| ; | ||
|
|
||
| singleFieldRelevanceFunctionName | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -213,6 +213,18 @@ public UnresolvedExpression visitCompareExpr(CompareExprContext ctx) { | |
| String operator = ctx.comparisonOperator().getText(); | ||
| if ("==".equals(operator)) { | ||
| operator = EQUAL.getName().getFunctionName(); | ||
| } else if ("contains".equalsIgnoreCase(operator)) { | ||
|
Collaborator
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: In principle this should be a const like We already broke the const in the previous if with
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. That makes sense to me. Thank you for reviewing it! |
||
| UnresolvedExpression left = visit(ctx.left); | ||
| UnresolvedExpression right = visit(ctx.right); | ||
| if (!(right instanceof Literal) || ((Literal) right).getType() != DataType.STRING) { | ||
| throw new SemanticCheckException( | ||
| "The right-hand side of 'contains' must be a string literal"); | ||
| } | ||
| String raw = ((Literal) right).getValue().toString(); | ||
| String escaped = raw.replace("\\", "\\\\").replace("%", "\\%").replace("_", "\\_"); | ||
| String wrapped = "%" + escaped + "%"; | ||
| return new Compare( | ||
| ILIKE.getName().getFunctionName(), left, new Literal(wrapped, DataType.STRING)); | ||
| } else if (LIKE.getName().getFunctionName().equalsIgnoreCase(operator) | ||
| && UnresolvedPlanHelper.isCalciteEnabled(astBuilder.getSettings())) { | ||
| operator = | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
is the
containscase-sensitive or insensitive? Need more tests for this.Can you link the cloudwatch doc link in description?
And this PR should include user document updates. maybe in
condition.mdThere 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.
I think contains is case-insensitive since it's implemented with ILIKE with %value% wrapping.
If a user writes firstname contains '%', the wrapped pattern becomes %%% which would match everything, which is likely unintended. I'll fix this and add more test cases.
Here is the doc provided: https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax-Filter.html