-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Remove deprecated function isNotNullAndFoldable #130944
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
Merged
Merged
Changes from 19 commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
0f080a5
Fix for top
julian-elastic 8a24206
Fix for sample function
julian-elastic 9dd5502
[CI] Auto commit changes from spotless
67dc79f
Handle Match function
julian-elastic 923dc02
Handle MatchPhrase function
julian-elastic 29cce29
Handle MultiMatch function
julian-elastic fdf54dc
Handle QueryString function
julian-elastic 2641cb3
Handle KNN function
julian-elastic 8e2c6b4
Merge remote-tracking branch 'origin/foldable' into foldable
julian-elastic 15dfed3
Migrate tests from VerifierTests to 230_folding.yml
julian-elastic 408c8fd
Remove partiallyFoldable code as it is not needed
julian-elastic f187139
Fix some of the failing UTs
julian-elastic d66fdfc
Merge branch 'main' into foldable
julian-elastic d80dd57
[CI] Auto commit changes from spotless
6f34981
Remove some debugging code
julian-elastic 4247581
Fix failing UTs in old version
julian-elastic b2213e1
Merge branch 'main' into foldable
julian-elastic 029f96a
Integrate with knn_function_v3
julian-elastic 18e18a2
Fix UT fails
julian-elastic 23359b5
Fix UT fail
julian-elastic 4007272
Merge branch 'main' into foldable
julian-elastic 9537344
Fix merge error
julian-elastic 8e9d34b
Merge branch 'main' into foldable
julian-elastic 20245b6
Fix merge error
julian-elastic b2e796c
[CI] Auto commit changes from spotless
cb676a7
Fix UT error
julian-elastic 910c1d0
Merge branch 'main' into foldable
julian-elastic 91f76d6
Remove isNotNullAndFoldable function completely
julian-elastic b3ee3a0
Update docs/changelog/130944.yaml
julian-elastic 8dfdf1a
Fix UT failures related to trying to get the datatype on unresolved a…
julian-elastic 4087f30
Merge branch 'main' into foldable
julian-elastic 8e11323
Merge branch 'main' into foldable
julian-elastic 89dfb4e
Update docs/changelog/130944.yaml
julian-elastic 55b9246
Fix failing UTs
julian-elastic 94909ec
Fix failing UT
julian-elastic 2444673
Merge branch 'main' into foldable
julian-elastic 1d730a5
Fix UT error
julian-elastic 6714b8b
Update docs/changelog/130944.yaml
julian-elastic 094aa80
Address code review feedback
julian-elastic 50918a4
Fix checkstyle
julian-elastic 5012a2e
Merge branch 'main' into foldable
julian-elastic 09bbf06
Address code review comments
julian-elastic 9fce42b
Merge branch 'main' into foldable
julian-elastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
...in/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/FunctionUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
| package org.elasticsearch.xpack.esql.expression.function; | ||
|
|
||
| import org.elasticsearch.common.lucene.BytesRefs; | ||
| import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException; | ||
| import org.elasticsearch.xpack.esql.common.Failures; | ||
| import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
| import org.elasticsearch.xpack.esql.core.expression.Literal; | ||
|
|
||
| import static org.elasticsearch.common.logging.LoggerMessageFormat.format; | ||
| import static org.elasticsearch.xpack.esql.common.Failure.fail; | ||
|
|
||
| public class FunctionUtils { | ||
| public static Integer limitValue(Expression limitField, String sourceText) { | ||
| if (limitField instanceof Literal literal) { | ||
| Object value = literal.value(); | ||
| if (value instanceof Integer intValue) { | ||
| return intValue; | ||
| } | ||
| } | ||
| throw new EsqlIllegalArgumentException(format(null, "Limit value must be an integer in [{}], found [{}]", sourceText, limitField)); | ||
| } | ||
|
|
||
| /** | ||
| * We check that the limit is not null and that if it is a literal, it is a positive integer | ||
| * We will do a more thorough check in the postOptimizationVerification once folding is done. | ||
| */ | ||
| public static Expression.TypeResolution resolveTypeLimit(Expression limitField, String sourceText) { | ||
| if (limitField == null) { | ||
| return new Expression.TypeResolution( | ||
| format(null, "Limit must be a constant integer in [{}], found [{}]", sourceText, limitField) | ||
| ); | ||
| } | ||
| if (limitField instanceof Literal literal) { | ||
| if (literal.value() == null) { | ||
| return new Expression.TypeResolution( | ||
| format(null, "Limit must be a constant integer in [{}], found [{}]", sourceText, limitField) | ||
| ); | ||
| } | ||
| int value = (Integer) literal.value(); | ||
| if (value <= 0) { | ||
| return new Expression.TypeResolution(format(null, "Limit must be greater than 0 in [{}], found [{}]", sourceText, value)); | ||
| } | ||
| } | ||
| return Expression.TypeResolution.TYPE_RESOLVED; | ||
| } | ||
|
|
||
| public static void postOptimizationVerificationLimit(Failures failures, Expression limitField, String sourceText) { | ||
| if (limitField == null) { | ||
| failures.add(fail(limitField, "Limit must be a constant integer in [{}], found [{}]", sourceText, limitField)); | ||
| } | ||
| if (limitField instanceof Literal literal) { | ||
| int value = (Integer) literal.value(); | ||
| if (value <= 0) { | ||
| failures.add(fail(limitField, "Limit must be greater than 0 in [{}], found [{}]", sourceText, value)); | ||
| } | ||
| } else { | ||
| // it is expected that the expression is a literal after folding | ||
| // we fail if it is not a literal | ||
| failures.add(fail(limitField, "Limit must be a constant integer in [{}], found [{}]", sourceText, limitField)); | ||
| } | ||
| } | ||
|
|
||
| public static Expression.TypeResolution resolveTypeQuery(Expression queryField, String sourceText) { | ||
| if (queryField == null) { | ||
| return new Expression.TypeResolution(format(null, "Query must be a valid string in [{}], found [{}]", sourceText, queryField)); | ||
| } | ||
| if (queryField instanceof Literal literal) { | ||
| if (literal.value() == null) { | ||
| return new Expression.TypeResolution( | ||
| format(null, "Query value cannot be null in [{}], but got [{}]", sourceText, queryField) | ||
| ); | ||
| } | ||
| } | ||
| return Expression.TypeResolution.TYPE_RESOLVED; | ||
| } | ||
|
|
||
| public static void postOptimizationVerificationQuery(Failures failures, Expression queryField, String sourceText) { | ||
| if (queryField == null) { | ||
| failures.add(fail(queryField, "Query must be a valid string in [{}], found [{}]", sourceText, queryField)); | ||
| } | ||
| if (queryField instanceof Literal literal) { | ||
| if (literal.value() == null) { | ||
| failures.add(fail(queryField, "Invalid query value in [{}], found [{}]", sourceText, literal.value())); | ||
| } | ||
| } else { | ||
| // it is expected that the expression is a literal after folding | ||
| // we fail if it is not a literal | ||
| failures.add(fail(queryField, "Query must be a valid string in [{}], found [{}]", sourceText, queryField)); | ||
| } | ||
| } | ||
|
|
||
| public static Object queryAsObject(Expression queryField, String sourceText) { | ||
| if (queryField instanceof Literal literal) { | ||
| return literal.value(); | ||
| } | ||
| throw new EsqlIllegalArgumentException( | ||
| format(null, "Query value must be a constant string in [{}], found [{}]", sourceText, queryField) | ||
| ); | ||
| } | ||
|
|
||
| public static String queryAsString(Expression queryField, String sourceText) { | ||
| if (queryField instanceof Literal literal) { | ||
| return BytesRefs.toString(literal.value()); | ||
| } | ||
| throw new EsqlIllegalArgumentException( | ||
| format(null, "Query value must be a constant string in [{}], found [{}]", sourceText, queryField) | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.