Skip to content

Commit f070684

Browse files
committed
fix per recommendation
Signed-off-by: Asif Bashar <[email protected]>
1 parent 370b9bc commit f070684

File tree

3 files changed

+16
-54
lines changed

3 files changed

+16
-54
lines changed

docs/user/ppl/functions/conversion.rst

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,50 +84,44 @@ TONUMBER
8484

8585
Description
8686
>>>>>>>>>>>
87+
8788
The following usage options are available, depending on the parameter types and the number of parameters.
8889

8990
Usage: tonumber(string, [base]) converts the value in first argument to provided base type string in second argument. If second argument is not provided, then it converts to base 10 number representation.
91+
9092
Return type: Number
9193

9294

9395
You can use this function with the eval commands and as part of eval expressions.
9496
Base values can be between 2 and 36.
9597

96-
97-
98-
Basic examples:
9998
You can use this function to convert a string representation of a binary number to return the corresponding number in base 10.
10099

101-
For example, the result of the following function is 5:
102-
eval result = tonumber("0101", 2)
103-
100+
Following example converts a string in binary to the number representation::
104101

105-
Example::
106-
Following example converts a string in binary to the number representation.
107-
os> source=EMP | eval int_value = tonumber('010101',2) | fields int_value|head 1
102+
os> source=EMP | eval int_value = tonumber('010101',2) | fields int_value | head 1
108103
fetched rows / total rows = 1/1
109-
+--------------+
110-
| int_value |
111-
|--------------+
112-
| 21.0 |
113-
+--------------+
104+
+---------------+
105+
| int_value |
106+
|---------------+
107+
| 21.0 |
108+
+---------------+
109+
114110

111+
Following example converts a string in hex to the number representation::
115112

116-
Following example converts a string in hex to the number representation.
117-
Example::
118113

119-
os> source=EMP | eval int_value = tonumber('FA34',16) | fields int_value|head 1
114+
os> source=EMP | eval int_value = tonumber('FA34',16) | fields int_value | head 1
120115
fetched rows / total rows = 1/1
121116
+---------------+
122117
| int_value |
123118
|---------------+
124119
| 64052.0 |
125120
+---------------+
126121

127-
Following example converts a string in decimal to the number representation.
128-
Example::
122+
Following example converts a string in decimal to the number representation::
129123

130-
os> source=EMP | eval int_value = tonumber('4598') | fields int_value|head 1
124+
os> source=EMP | eval int_value = tonumber('4598') | fields int_value | head 1
131125
fetched rows / total rows = 1/1
132126
+---------------+
133127
| int_value |

ppl/src/main/antlr/OpenSearchPPLParser.g4

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,10 +848,9 @@ evalFunctionCall
848848
;
849849

850850

851-
// cast, tostring function
851+
// cast function
852852
dataTypeFunctionCall
853853
: CAST LT_PRTHS logicalExpression AS convertedDataType RT_PRTHS
854-
| TONUMBER LT_PRTHS functionArgs RT_PRTHS
855854
;
856855

857856

@@ -1234,6 +1233,7 @@ textFunctionName
12341233
| LOCATE
12351234
| REPLACE
12361235
| REVERSE
1236+
| TONUMBER
12371237
;
12381238

12391239
positionFunctionName

ppl/src/main/java/org/opensearch/sql/ppl/parser/AstExpressionBuilder.java

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -431,39 +431,7 @@ public DataTypeFunctionCallContext createDataTypeFunctionCallContext(String cast
431431
/** Cast function. */
432432
@Override
433433
public UnresolvedExpression visitDataTypeFunctionCall(DataTypeFunctionCallContext ctx) {
434-
if (ctx.functionArgs() != null) {
435-
436-
ParseTree rootNode = ctx.getChild(0);
437-
String functionName = rootNode.getText();
438-
final String mappedName =
439-
FUNCTION_NAME_MAPPING.getOrDefault(functionName.toLowerCase(Locale.ROOT), functionName);
440-
System.out.println(mappedName);
441-
if (mappedName != null && mappedName.equals("tostring")) {
442-
if (ctx.functionArgs().functionArg().size() == 1) {
443-
List<OpenSearchPPLParser.FunctionArgContext> functionArgs =
444-
ctx.functionArgs().functionArg();
445-
446-
String castExpresstion =
447-
String.format("cast( %s as String)", functionArgs.getFirst().getText());
448-
DataTypeFunctionCallContext toStringDataTypeConversionContext =
449-
this.createDataTypeFunctionCallContext(castExpresstion);
450-
return new Cast(
451-
visit(toStringDataTypeConversionContext.logicalExpression()),
452-
visit(toStringDataTypeConversionContext.convertedDataType()));
453-
//
454-
} else {
455-
return buildFunction(mappedName, ctx.functionArgs().functionArg());
456-
}
457-
} else if (mappedName != null && mappedName.equals("tonumber")) {
458-
459-
return buildFunction(mappedName, ctx.functionArgs().functionArg());
460-
461-
} else {
462-
return new Cast(visit(ctx.logicalExpression()), visit(ctx.convertedDataType()));
463-
}
464-
} else {
465434
return new Cast(visit(ctx.logicalExpression()), visit(ctx.convertedDataType()));
466-
}
467435
}
468436

469437
@Override

0 commit comments

Comments
 (0)