generated from amazon-archives/__template_Custom
-
Notifications
You must be signed in to change notification settings - Fork 178
bin command error message enhancement #4690
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
5 commits
Select commit
Hold shift + click to select a range
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
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
64 changes: 64 additions & 0 deletions
64
core/src/main/java/org/opensearch/sql/calcite/utils/binning/BinnableField.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,64 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.calcite.utils.binning; | ||
|
|
||
| import lombok.Getter; | ||
| import org.apache.calcite.rel.type.RelDataType; | ||
| import org.apache.calcite.rex.RexNode; | ||
| import org.opensearch.sql.calcite.utils.OpenSearchTypeFactory; | ||
| import org.opensearch.sql.exception.SemanticCheckException; | ||
|
|
||
| /** | ||
| * Represents a validated field that supports binning operations. The existence of this class | ||
| * guarantees that validation has been run - the field is either numeric or time-based. | ||
| * | ||
| * <p>This design encodes validation in the type system, preventing downstream code from forgetting | ||
| * to validate or running validation multiple times. | ||
| */ | ||
| @Getter | ||
| public class BinnableField { | ||
| private final RexNode fieldExpr; | ||
| private final RelDataType fieldType; | ||
| private final String fieldName; | ||
| private final boolean isTimeBased; | ||
| private final boolean isNumeric; | ||
|
|
||
| /** | ||
| * Creates a validated BinnableField. Throws SemanticCheckException if the field is neither | ||
| * numeric nor time-based. | ||
| * | ||
| * @param fieldExpr The Rex expression for the field | ||
| * @param fieldType The relational data type of the field | ||
| * @param fieldName The name of the field (for error messages) | ||
| * @throws SemanticCheckException if the field is neither numeric nor time-based | ||
| */ | ||
| public BinnableField(RexNode fieldExpr, RelDataType fieldType, String fieldName) { | ||
| this.fieldExpr = fieldExpr; | ||
| this.fieldType = fieldType; | ||
| this.fieldName = fieldName; | ||
|
|
||
| this.isTimeBased = OpenSearchTypeFactory.isTimeBasedType(fieldType); | ||
| this.isNumeric = OpenSearchTypeFactory.isNumericType(fieldType); | ||
|
|
||
| // Validation: field must be either numeric or time-based | ||
| if (!isNumeric && !isTimeBased) { | ||
| throw new SemanticCheckException( | ||
| String.format( | ||
| "Cannot apply binning: field '%s' is non-numeric and not time-related, expected" | ||
| + " numeric or time-related type", | ||
| fieldName)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if this field requires numeric binning logic (not time-based binning). | ||
| * | ||
| * @return true if the field should use numeric binning, false if it should use time-based binning | ||
| */ | ||
| public boolean requiresNumericBinning() { | ||
| return !isTimeBased; | ||
| } | ||
| } | ||
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
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
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.
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.
nit: This method was confusing to me. It might be better changing it to
isNumericis it is actually used to check if the field is numeric.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.
Hi Tomo, this method exists because some parameters such as
minspan,start,endcurrently don't support time-based binning, so they will use this method to check first