@Override protected Double visitDoubleLiteral(DoubleLiteral node, ConnectorSession session) { return node.getValue(); }
private static Expression createEstimateRepresentation(Estimate estimate) { if (estimate.isUnknown()) { return NULL_DOUBLE; } return new DoubleLiteral(Double.toString(estimate.getValue())); }
private static DoubleLiteral doubleLiteral(double value) { return new DoubleLiteral(Double.toString(value)); }
@Override protected String visitDoubleLiteral(DoubleLiteral node, Void context) { return doubleFormatter.get().format(node.getValue()); }
@Override public Node visitDoubleLiteral(SqlBaseParser.DoubleLiteralContext context) { return new DoubleLiteral(getLocation(context), context.getText()); }
@Override protected RowExpression visitDoubleLiteral(DoubleLiteral node, Void context) { return constant(node.getValue(), DOUBLE); }
private static Expression toExpression(Object value) throws PrestoException { if (value instanceof String) { return new StringLiteral(value.toString()); } if (value instanceof Boolean) { return new BooleanLiteral(value.toString()); } if (value instanceof Long || value instanceof Integer) { return new LongLiteral(value.toString()); } if (value instanceof Double) { return new DoubleLiteral(value.toString()); } if (value instanceof List) { List<?> list = (List<?>) value; return new ArrayConstructor(list.stream() .map(Visitor::toExpression) .collect(toList())); } throw new PrestoException(INVALID_TABLE_PROPERTY, format("Failed to convert object of type %s to expression: %s", value.getClass().getName(), value)); }
private static String getValueFromLiteral(Node expression) { if (expression instanceof LongLiteral) { return String.valueOf(((LongLiteral) expression).getValue()); } else if (expression instanceof BooleanLiteral) { return String.valueOf(((BooleanLiteral) expression).getValue()); } else if (expression instanceof DoubleLiteral) { return String.valueOf(((DoubleLiteral) expression).getValue()); } else if (expression instanceof DecimalLiteral) { return String.valueOf(((DecimalLiteral) expression).getValue()); } else if (expression instanceof GenericLiteral) { return ((GenericLiteral) expression).getValue(); } else { throw new IllegalArgumentException("Unsupported literal expression type: " + expression.getClass().getName()); } }
@Override public Result apply(SampleNode sample, Captures captures, Context context) { return Result.ofPlanNode(new FilterNode( sample.getId(), sample.getSource(), new ComparisonExpression( ComparisonExpression.Operator.LESS_THAN, new FunctionCall(QualifiedName.of("rand"), ImmutableList.of()), new DoubleLiteral(Double.toString(sample.getSampleRatio()))))); } }
@Override protected String visitDoubleLiteral(DoubleLiteral node, Boolean negate) { return Double.toString(node.getValue()); }
@Test public void testDouble() { assertExpression("123E7", new DoubleLiteral("123E7")); assertExpression("123.E7", new DoubleLiteral("123E7")); assertExpression("123.0E7", new DoubleLiteral("123E7")); assertExpression("123E+7", new DoubleLiteral("123E7")); assertExpression("123E-7", new DoubleLiteral("123E-7")); assertExpression("123.456E7", new DoubleLiteral("123.456E7")); assertExpression("123.456E+7", new DoubleLiteral("123.456E7")); assertExpression("123.456E-7", new DoubleLiteral("123.456E-7")); assertExpression(".4E42", new DoubleLiteral(".4E42")); assertExpression(".4E+42", new DoubleLiteral(".4E42")); assertExpression(".4E-42", new DoubleLiteral(".4E-42")); }
@Override protected String visitDoubleLiteral(DoubleLiteral node, Void context) { return Double.toString(node.getValue()); }
@Override public Node visitDecimalLiteral(SqlBaseParser.DecimalLiteralContext context) { switch (parsingOptions.getDecimalLiteralTreatment()) { case AS_DOUBLE: return new DoubleLiteral(getLocation(context), context.getText()); case AS_DECIMAL: return new DecimalLiteral(getLocation(context), context.getText()); case REJECT: throw new ParsingException("Unexpected decimal literal: " + context.getText()); } throw new AssertionError("Unreachable"); }
@Override protected String visitDoubleLiteral(DoubleLiteral node, Boolean unmangleNames) { String variableName = ":" + variable[1]++; valueBuilder.put(variableName, new AttributeValue().withN(Double.toString(node.getValue()))); return variableName; }
@Test public void testArrayConstructor() { assertExpression("ARRAY []", new ArrayConstructor(ImmutableList.of())); assertExpression("ARRAY [1, 2]", new ArrayConstructor(ImmutableList.of(new LongLiteral("1"), new LongLiteral("2")))); assertExpression("ARRAY [1e0, 2.5e0]", new ArrayConstructor(ImmutableList.of(new DoubleLiteral("1.0"), new DoubleLiteral("2.5")))); assertExpression("ARRAY ['hi']", new ArrayConstructor(ImmutableList.of(new StringLiteral("hi")))); assertExpression("ARRAY ['hi', 'hello']", new ArrayConstructor(ImmutableList.of(new StringLiteral("hi"), new StringLiteral("hello")))); }
@Override protected Double visitDoubleLiteral(DoubleLiteral node, ConnectorSession session) { return node.getValue(); }
@Test public void testDoubleInQuery() { assertStatement("SELECT 123.456E7 FROM DUAL", simpleQuery( selectList(new DoubleLiteral("123.456E7")), table(QualifiedName.of("DUAL")))); }
@Override protected String visitDoubleLiteral(DoubleLiteral node, Boolean unmangleNames) { return Double.toString(node.getValue()); }
return new FunctionCall(QualifiedName.of("infinity"), ImmutableList.of()); return new DoubleLiteral(object.toString());
@Override protected String visitDoubleLiteral(DoubleLiteral node, Boolean unmangleNames) { return Double.toString(node.getValue()); }