Skip to content
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

[ES|QL] Function AST node subtypes #189268

Merged
merged 13 commits into from
Jul 26, 2024
Merged

Conversation

vadimkibana
Copy link
Contributor

Summary

Closes #189259

  • Introduces subtype property for function AST node types. This allows to discriminate between real functions an various expression types.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@vadimkibana vadimkibana requested a review from a team as a code owner July 26, 2024 10:44
@vadimkibana vadimkibana added review release_note:skip Skip the PR/issue when compiling release notes Feature:ES|QL ES|QL related features in Kibana Team:ESQL ES|QL related features in Kibana v8.16.0 labels Jul 26, 2024
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-esql (Team:ESQL)

@vadimkibana vadimkibana changed the title Function subtypes [ES|QL] Function node subtypes Jul 26, 2024
@vadimkibana vadimkibana changed the title [ES|QL] Function node subtypes [ES|QL] Function AST node subtypes Jul 26, 2024
@vadimkibana vadimkibana enabled auto-merge (squash) July 26, 2024 13:03
@elastic-vault-github-plugin-prod elastic-vault-github-plugin-prod bot requested a review from a team as a code owner July 26, 2024 13:53
Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

Seems reasonable. Just a couple questions


export type BinaryExpressionArithmeticOperator = '+' | '-' | '*' | '/' | '%';
export type BinaryExpressionAssignmentOperator = '=';
export type BinaryExpressionComparisonOperator = '==' | '=~' | '!=' | '<' | '<=' | '>' | '>=';
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think =~ is a valid operator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I took it from our ANTLR grammar:

image

But you are also right, I don't see it being used. It is either unused code or something for the future.

Copy link
Contributor Author

@vadimkibana vadimkibana Jul 26, 2024

Choose a reason for hiding this comment

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

I can remove it, or leave it, indifferent.

Comment on lines +126 to +129
export type BinaryExpressionArithmeticOperator = '+' | '-' | '*' | '/' | '%';
export type BinaryExpressionAssignmentOperator = '=';
export type BinaryExpressionComparisonOperator = '==' | '=~' | '!=' | '<' | '<=' | '>' | '>=';
export type BinaryExpressionRegexOperator = 'like' | 'not_like' | 'rlike' | 'not_rlike';
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the type checker catch it if the grammar changes in such a way that these lists are out-of-sync?

Copy link
Contributor Author

@vadimkibana vadimkibana Jul 26, 2024

Choose a reason for hiding this comment

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

It does not. But it is a good point: we have the createFunction helper, it currently allows any function, I could create createBinaryExpression, which would help in some cases with checking types.

However, the main reason I added these types was because of the (not_)(r)like regex expressions. Unlike the other operators, I cannot just print them when pretty-printing, so I wanted those expression captured in the types, so TypeScript would give me the correct autocomplete. When I was adding them, I decided to capture all binary operators.

Copy link
Contributor

@drewdaemon drewdaemon left a comment

Choose a reason for hiding this comment

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

LGTM

@yctercero yctercero requested a review from vitaliidm July 26, 2024 18:32
@yctercero
Copy link
Contributor

Hi @vadimkibana ! From the Detection Engine team here 👋🏽 Are there any changes we need to make to make sure existing ES|QL rules continue to function as intended?

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
@kbn/esql-ast 10 12 +2

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-srcJs 3.3MB 3.3MB +329.0B
Unknown metric groups

API count

id before after diff
@kbn/esql-ast 134 135 +1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@vadimkibana vadimkibana merged commit 6c093b6 into elastic:main Jul 26, 2024
19 checks passed
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jul 26, 2024
@vadimkibana
Copy link
Contributor Author

vadimkibana commented Jul 27, 2024

@yctercero This change adds a new subtype field to "function" AST nodes. I don't know how, and if, you are using ES|QL AST, but generally this is a non-breaking change, there will just be a new subtype field in some AST nodes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:ES|QL ES|QL related features in Kibana release_note:skip Skip the PR/issue when compiling release notes review Team:ESQL ES|QL related features in Kibana v8.16.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ES|QL] FunctionCallExpression, UnaryExpression, and BinaryExpression differentiation
6 participants