- 
                Notifications
    You must be signed in to change notification settings 
- Fork 177
issue #4514 tonumber function as part of roadmap #4287 #4605
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?
issue #4514 tonumber function as part of roadmap #4287 #4605
Conversation
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]>
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]>
…ensearch-project#4287 Signed-off-by: Asif Bashar <[email protected]>
| @penghuo please review | 
        
          
                ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java
          
            Show resolved
            Hide resolved
        
              
          
                core/src/main/java/org/opensearch/sql/expression/function/PPLFuncImpTable.java
              
                Outdated
          
            Show resolved
            Hide resolved
        
      Signed-off-by: Asif Bashar <[email protected]>
Co-authored-by: ritvibhatt <[email protected]> Signed-off-by: Asif Bashar <[email protected]> Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
0e85841    to
    f070684      
    Compare
  
    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]>
| @penghuo please review | 
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
Signed-off-by: Asif Bashar <[email protected]>
|  | ||
| Following example converts a string in binary to the number representation:: | ||
|  | ||
| os> source=EMP | eval int_value = tonumber('010101',2) | fields int_value | head 1 | 
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.
using source=people, align with other test in same doc.
| // TEXT FUNCTIONS | ||
| SUBSTR: 'SUBSTR'; | ||
| SUBSTRING: 'SUBSTRING'; | ||
| TONUMBER: 'TONUMBER'; | 
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.
Add similar test to verify logical plan and Sql query.
e.g. https://github.com/opensearch-project/sql/pull/4497/files#diff-d8afd9bd8dc0f2e5ab069d8b37842fb0b41f6e582bd9dc63c248b2d81dd67674
| void testToNumberWithDecimalBase16() { | ||
| assertEquals(255.5, ToNumberFunction.toNumber("FF.8", 16)); | ||
| assertEquals(16.25, ToNumberFunction.toNumber("10.4", 16)); | ||
| assertEquals(171.6875, ToNumberFunction.toNumber("AB.B", 16)); | 
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.
Any standard we are following?
Seems SPL does not support tonumber("AB.B", 16)
If not, we should define the behaviour of tonumber as
- if base=10, convert to int / double, depend on whether there is .
- if base!=0, always convert to long, e.g. new BigInteger("FF", 16).
Description
tonumber(, )
This function converts a string to a number.
Usage
You can use this function with the eval and where commands, in the WHERE clause of the from command, and as part of evaluation expressions with other commands.
The argument can be a string or the name of a field that contains a string. If the string contains a decimal point ( . ), then the tonumber function converts it to a double. Otherwise, the function converts the string to an integer.
Be aware that integers are supported differently in different product contexts:
The argument is optional. It defines the base of the number in the argument. It defaults to 10, which corresponds to the decimal system. You can set to a number between 2 and 36, inclusive.
If the tonumber function cannot parse a literal string to a number, the function returns an error.
Basic examples
The following example converts the string values from the store_sales field to numbers, and then stores the numbers in a field named n. This example uses the default base of 10.
... | eval n=tonumber(store_sales)
The following example takes the hexadecimal number and uses a base of 16 to return the number "164".
... | eval n=tonumber("0A4",16)
Related Issues
Resolves #[4514]
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.