-
Notifications
You must be signed in to change notification settings - Fork 190
[FEATURE] RFC #4287 - tostring implementation #4492
Description
Is your feature request related to a problem?
SPL allows tostring which is planned to be implemented. This issue is to track the implementation
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.
What alternatives have you considered?
The feature does not exist yet.
Do you have any additional context?
SPL equivalent implementation.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Status