Skip to content

Conversation

@asifabashar
Copy link

@asifabashar asifabashar commented Oct 10, 2025

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

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • New PPL command checklist all confirmed.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff or -s.
  • Public documentation issue/PR created.

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.

@asifabashar
Copy link
Author

@penghuo Please review

@penghuo penghuo added PPL Piped processing language enhancement New feature or request labels Oct 10, 2025
@asifabashar
Copy link
Author

@penghuo Thanks for your comments and review. I have made the changes, please check.

Signed-off-by: Asif Bashar <[email protected]>
@asifabashar
Copy link
Author

@penghuo please review

@asifabashar
Copy link
Author

please review @penghuo

@asifabashar asifabashar requested a review from penghuo October 21, 2025 04:44
@asifabashar
Copy link
Author

@penghuo please review

Signed-off-by: Asif Bashar <[email protected]>
Copy link
Author

@asifabashar asifabashar left a comment

Choose a reason for hiding this comment

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

Please review @penghuo

@asifabashar asifabashar requested a review from penghuo October 26, 2025 03:33
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
@penghuo
Copy link
Collaborator

penghuo commented Oct 27, 2025

@asifabashar Please resolve conflicts.

Signed-off-by: Asif Bashar <[email protected]>
* default-main: (34 commits)
  Enhance dynamic source clause to support only metadata filters (opensearch-project#4554)
  Make nested alias type support referring to outer context (opensearch-project#4673)
  Update big5 ppl queries and check plans (opensearch-project#4668)
  Support push down sort after limit (opensearch-project#4657)
  Use table scan rowType in filter pushdown could fix rename issue (opensearch-project#4670)
  Fix: Support Alias Fields in MIN, MAX, FIRST, LAST, and TAKE Aggregations (opensearch-project#4621)
  Fix bin nested fields issue (opensearch-project#4606)
  Add `per_minute`, `per_hour`, `per_day` function support (opensearch-project#4531)
  Pushdown sort aggregate metrics (opensearch-project#4603)
  Followup: Change ComparableLinkedHashMap to compare Key than Value (opensearch-project#4648)
  Mitigate the CI failure caused by 500 Internal Server Error (opensearch-project#4646)
  Allow renaming group-by fields to existing field names (opensearch-project#4586)
  Publish internal modules separately for downstream reuse (opensearch-project#4484)
  Revert "Update grammar files and developer guide (opensearch-project#4301)" (opensearch-project#4643)
  Support Automatic Type Conversion for REX/SPATH/PARSE Command Extractions (opensearch-project#4599)
  Replace all dots in fields of table scan's PhysType (opensearch-project#4633)
  Return comparable LinkedHashMap in `valueForCalcite()` of ExprTupleValue (opensearch-project#4629)
  Refactor JsonExtractAllFunctionIT and MapConcatFunctionIT (opensearch-project#4623)
  Pushdown case function in aggregations as range queries (opensearch-project#4400)
  Update GEOIP function to support IP types as input (opensearch-project#4613)
  ...

Signed-off-by: Asif Bashar <[email protected]>
@asifabashar
Copy link
Author

fixed merge conflicts

@asifabashar asifabashar requested a review from penghuo October 28, 2025 17:28
@penghuo
Copy link
Collaborator

penghuo commented Oct 28, 2025

fixed merge conflicts

@asifabashar
tostring docs missing after merge conflict, please double check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request PPL Piped processing language

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants