use of org.apache.phoenix.expression.function.ToNumberFunction in project phoenix by apache.
the class SortOrderExpressionTest method toNumber.
@Test
public void toNumber() throws Exception {
List<Expression> args = Lists.newArrayList(getInvertedLiteral("10", PVarchar.INSTANCE));
evaluateAndAssertResult(new ToNumberFunction(args, FunctionArgumentType.CHAR, "", null), new BigDecimal(BigInteger.valueOf(1), -1));
}
use of org.apache.phoenix.expression.function.ToNumberFunction in project phoenix by apache.
the class ToNumberParseNode method create.
@Override
public FunctionExpression create(List<Expression> children, StatementContext context) throws SQLException {
PDataType dataType = children.get(0).getDataType();
// either date or number format string
String formatString = (String) ((LiteralExpression) children.get(1)).getValue();
Format formatter = null;
FunctionArgumentType type;
if (dataType.isCoercibleTo(PTimestamp.INSTANCE)) {
if (formatString == null) {
formatString = context.getDateFormat();
formatter = context.getDateFormatter();
} else {
formatter = FunctionArgumentType.TEMPORAL.getFormatter(formatString);
}
type = FunctionArgumentType.TEMPORAL;
} else if (dataType.isCoercibleTo(PChar.INSTANCE)) {
if (formatString != null) {
formatter = FunctionArgumentType.CHAR.getFormatter(formatString);
}
type = FunctionArgumentType.CHAR;
} else {
throw new SQLException(dataType + " type is unsupported for TO_NUMBER(). Numeric and temporal types are supported.");
}
return new ToNumberFunction(children, type, formatString, formatter);
}
Aggregations