-
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 all 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
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,6 @@ | ||
| pr: 130944 | ||
| summary: Remove unnecessary calls to Fold | ||
| area: ES|QL | ||
| type: enhancement | ||
| issues: | ||
| - 119756 |
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
151 changes: 151 additions & 0 deletions
151
...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,151 @@ | ||
| /* | ||
| * 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.core.Nullable; | ||
| import org.elasticsearch.xpack.esql.EsqlIllegalArgumentException; | ||
| import org.elasticsearch.xpack.esql.common.Failure; | ||
| 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 { | ||
| /** | ||
| * A utility class to validate the type resolution of expressions before and after logical planning. | ||
| * If null is passed for Failures to the constructor, it means we are only type resolution. | ||
| * This is usually called when doing pre-logical planning validation. | ||
| * If a {@link Failures} instance is passed, it means we are doing post-logical planning validation as well. | ||
| * This is usually called after folding is done, during | ||
| * {@link org.elasticsearch.xpack.esql.capabilities.PostOptimizationVerificationAware} verification | ||
| */ | ||
| public static class TypeResolutionValidator { | ||
|
|
||
| Expression.TypeResolution typeResolution = Expression.TypeResolution.TYPE_RESOLVED; | ||
| @Nullable | ||
| private final Failures postValidationFailures; // null means we are doing pre-folding validation only | ||
| private final Expression field; | ||
|
|
||
| public static TypeResolutionValidator forPreOptimizationValidation(Expression field) { | ||
| return new TypeResolutionValidator(field, null); | ||
| } | ||
|
|
||
| public static TypeResolutionValidator forPostOptimizationValidation(Expression field, Failures failures) { | ||
| return new TypeResolutionValidator(field, failures); | ||
| } | ||
|
|
||
| private TypeResolutionValidator(Expression field, Failures failures) { | ||
| this.field = field; | ||
| this.postValidationFailures = failures; | ||
| } | ||
|
|
||
| public void invalidIfPostValidation(Failure failure) { | ||
| if (postValidationFailures != null) { | ||
| postValidationFailures.add(failure); | ||
| } | ||
| } | ||
|
|
||
| public void invalid(Expression.TypeResolution message) { | ||
| typeResolution = message; | ||
| if (postValidationFailures != null) { | ||
| postValidationFailures.add(fail(field, message.message())); | ||
| } | ||
| } | ||
|
|
||
| public Expression.TypeResolution getResolvedType() { | ||
| return typeResolution; | ||
| } | ||
| } | ||
|
|
||
| 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 | ||
| * During postOptimizationVerification folding is already done, so we also verify that it is definitively a literal | ||
| */ | ||
| public static Expression.TypeResolution resolveTypeLimit(Expression limitField, String sourceText, TypeResolutionValidator validator) { | ||
| if (limitField == null) { | ||
| validator.invalid( | ||
| new Expression.TypeResolution(format(null, "Limit must be a constant integer in [{}], found [{}]", sourceText, limitField)) | ||
| ); | ||
| } else if (limitField instanceof Literal literal) { | ||
| if (literal.value() == null) { | ||
| validator.invalid( | ||
| new Expression.TypeResolution( | ||
| format(null, "Limit must be a constant integer in [{}], found [{}]", sourceText, limitField) | ||
| ) | ||
| ); | ||
| } else { | ||
| int value = (Integer) literal.value(); | ||
| if (value <= 0) { | ||
| validator.invalid( | ||
| new Expression.TypeResolution(format(null, "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 | ||
| validator.invalidIfPostValidation( | ||
| fail(limitField, "Limit must be a constant integer in [{}], found [{}]", sourceText, limitField) | ||
| ); | ||
| } | ||
| return validator.getResolvedType(); | ||
| } | ||
|
|
||
| /** | ||
| * We check that the query is not null and that if it is a literal, it is a string | ||
| * During postOptimizationVerification folding is already done, so we also verify that it is definitively a literal | ||
| */ | ||
| public static Expression.TypeResolution resolveTypeQuery(Expression queryField, String sourceText, TypeResolutionValidator validator) { | ||
| if (queryField == null) { | ||
| validator.invalid( | ||
| new Expression.TypeResolution(format(null, "Query must be a valid string in [{}], found [{}]", sourceText, queryField)) | ||
| ); | ||
| } else if (queryField instanceof Literal literal) { | ||
| if (literal.value() == null) { | ||
| validator.invalid( | ||
| new Expression.TypeResolution(format(null, "Query value cannot be null in [{}], but got [{}]", sourceText, queryField)) | ||
| ); | ||
| } | ||
| } else { | ||
| // it is expected that the expression is a literal after folding | ||
| // we fail if it is not a literal | ||
| validator.invalidIfPostValidation(fail(queryField, "Query must be a valid string in [{}], found [{}]", sourceText, queryField)); | ||
| } | ||
| return validator.getResolvedType(); | ||
| } | ||
|
|
||
| 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
Oops, something went wrong.
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.