-
Couldn't load subscription status.
- Fork 176
PPL tostring() implementation issue #4492 #4497
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?
Conversation
|
@penghuo Please review |
ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLStringFunctionTest.java
Outdated
Show resolved
Hide resolved
ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLStringFunctionTest.java
Outdated
Show resolved
Hide resolved
ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLStringFunctionTest.java
Outdated
Show resolved
Hide resolved
ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLStringFunctionTest.java
Outdated
Show resolved
Hide resolved
ppl/src/test/java/org/opensearch/sql/ppl/calcite/CalcitePPLStringFunctionTest.java
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/udf/ToStringFunction.java
Show resolved
Hide resolved
|
@penghuo Thanks for your comments and review. I have made the changes, please check. |
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
… default duration is in seconds which will be used for duration format , added cast call for tostring with 1 argument Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
|
@penghuo please review |
ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java
Outdated
Show resolved
Hide resolved
ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java
Outdated
Show resolved
Hide resolved
ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
|
please review @penghuo |
|
@penghuo please review |
core/src/main/java/org/opensearch/sql/calcite/CalciteRexNodeVisitor.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/calcite/utils/PPLOperandTypes.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/udf/ToStringFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/udf/ToStringFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/udf/ToStringFunction.java
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/udf/ToStringFunction.java
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/udf/ToStringFunction.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/opensearch/sql/expression/function/udf/ToStringFunction.java
Show resolved
Hide resolved
Signed-off-by: Asif Bashar <[email protected]>
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.
Please review @penghuo
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
| @Strict | ||
| public static String toString(String str, String format) { | ||
| BigDecimal bd = new BigDecimal(str); | ||
| return toString(bd, format); | ||
| } |
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.
With string->numberic auto-conversion feature, this function may not required. e.g. tostring("42", "hex"), at query analysis stage, this query will be rewrite as tostring(SAFE_CAST("42" as double), "hex")
Please double confrim.
If this function still required, add try-catch to return null value is string. can not converted to number.
| public static final UDFOperandMetadata NUMERIC_STRING_OR_STRING_STRING = | ||
| UDFOperandMetadata.wrap( | ||
| (CompositeOperandTypeChecker) | ||
| (OperandTypes.family(SqlTypeFamily.NUMERIC, SqlTypeFamily.STRING)) | ||
| .or(OperandTypes.family(SqlTypeFamily.STRING, SqlTypeFamily.STRING))); |
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.
if leverage string->number auto-conversion, let's remove <STRING, STRING> signature.
https://github.com/opensearch-project/sql/pull/4497/files#r2466347484
|
@asifabashar Please resolve conflicts. |
Description
Is your feature request related to a problem?
SPL allows tostring which implemented here.
part of RFC #4287 - tostring implementation
issue #4492
What solution would you like?
Function: tostring(,)
Description
This function converts a value to a string. If the value is a number, this function reformats it as a string. If the value is a Boolean value, it returns the corresponding string value, "True" or "False".
Usage
You can use this function with the eval commands and as part of eval expressions.
The value argument can be a field name or a value.
Number is accepted as input to the function.
When you use the tostring function with the eval command, the returned values might not sort as expected. Use the tostring function to format the displayed values.
The format argument is optional and is only used when the value argument is a number. The tostring function supports the following formats.
Format Description
"binary" Converts a number to a binary value.
"hex" Converts the number to a hexadecimal value.
"commas" Formats the number with commas. If the number includes a decimal, the function rounds the number to nearest two decimal places.
"duration" Converts the value in seconds to the readable time format HH:MM:SS.
Binary conversion
You can use this function to convert a number to a string of its binary representation. For example, the result of the following function is 1001, because the binary representation of 9 is 1001.:
eval result = tostring(9, "binary")
For information about bitwise functions that you can use with the tostring function, see Bitwise functions.
Basic examples
The following example returns "True 0xF 12,345.68".
... | eval n=tostring(1==1) + " " + tostring(15, "hex") + " " + tostring(12345.6789, "commas")
The following example returns foo=615 and foo2=00:10:15. The 615 seconds is converted into minutes and seconds.
... | eval foo=615 | eval foo2 = tostring(foo, "duration")
The following example formats the column totalSales to display values with a currency symbol and commas. You must use a period between the currency value and the tostring function.
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.