private static Expression orNullHashCode(Expression expression) { return new CoalesceExpression(expression, new LongLiteral(String.valueOf(NULL_HASH_CODE))); }
@Override protected Void visitLongLiteral(LongLiteral node, Integer indentLevel) { print(indentLevel, "Long[" + node.getValue() + "]"); return null; }
return new LongLiteral(object.toString()); LongLiteral expression = new LongLiteral(object.toString()); if (expression.getValue() >= Integer.MIN_VALUE && expression.getValue() <= Integer.MAX_VALUE) { return new GenericLiteral("BIGINT", object.toString()); return new LongLiteral(object.toString());
private static Expression bigint(long value) { return new Cast(new LongLiteral(String.valueOf(value)), BIGINT.toString()); }
@Override protected Long visitLongLiteral(LongLiteral node, ConnectorSession session) { return node.getValue(); }
@Override public Result apply(TableFinishNode node, Captures captures, Context context) { return Result.ofPlanNode( new ValuesNode( node.getId(), node.getOutputSymbols(), ImmutableList.of(ImmutableList.of(new LongLiteral("0"))))); } }
@Override protected String visitLongLiteral(LongLiteral node, Void context) { return Long.toString(node.getValue()); }
private static LongLiteral number(long number) { return new LongLiteral(String.valueOf(number)); }
@Test public void testBetween() { assertExpression("1 BETWEEN 2 AND 3", new BetweenPredicate(new LongLiteral("1"), new LongLiteral("2"), new LongLiteral("3"))); assertExpression("1 NOT BETWEEN 2 AND 3", new NotExpression(new BetweenPredicate(new LongLiteral("1"), new LongLiteral("2"), new LongLiteral("3")))); }
@Override public Node visitIntegerLiteral(SqlBaseParser.IntegerLiteralContext context) { return new LongLiteral(getLocation(context), context.getText()); }
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()); } }
public static Optional<Expression> getHashExpression(List<Symbol> symbols) { if (symbols.isEmpty()) { return Optional.empty(); } Expression result = new LongLiteral(String.valueOf(INITIAL_HASH_VALUE)); for (Symbol symbol : symbols) { Expression hashField = new FunctionCall( QualifiedName.of(HASH_CODE), Optional.empty(), false, ImmutableList.of(new SymbolReference(symbol.getName()))); hashField = new CoalesceExpression(hashField, new LongLiteral(String.valueOf(NULL_HASH_CODE))); result = new FunctionCall(QualifiedName.of("combine_hash"), ImmutableList.of(result, hashField)); } return Optional.of(result); }
long ordinal = ((LongLiteral) column).getValue(); if (ordinal < 1 || ordinal > outputExpressions.size()) { throw new SemanticException(INVALID_ORDINAL, column, "GROUP BY position %s is not in select list", ordinal);
public PlanNode planStatement(Analysis analysis, Statement statement) { if (statement instanceof CreateTableAsSelect && analysis.isCreateTableAsSelectNoOp()) { checkState(analysis.getCreateTableDestination().isPresent(), "Table destination is missing"); Symbol symbol = symbolAllocator.newSymbol("rows", BIGINT); PlanNode source = new ValuesNode(idAllocator.getNextId(), ImmutableList.of(symbol), ImmutableList.of(ImmutableList.of(new LongLiteral("0")))); return new OutputNode(idAllocator.getNextId(), source, ImmutableList.of("rows"), ImmutableList.of(symbol)); } return createOutputPlan(planStatementWithoutOutput(analysis, statement), analysis); }
long ordinal = ((LongLiteral) expression).getValue(); if (ordinal < 1 || ordinal > orderByScope.getRelationType().getVisibleFieldCount()) { throw new SemanticException(INVALID_ORDINAL, expression, "ORDER BY position %s is not in select list", ordinal);
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)); }
@Override protected String visitLongLiteral(LongLiteral node, Boolean negate) { return Long.toString(node.getValue()); }
@Test public void testArraySubscript() { assertExpression("ARRAY [1, 2][1]", new SubscriptExpression( new ArrayConstructor(ImmutableList.of(new LongLiteral("1"), new LongLiteral("2"))), new LongLiteral("1"))); try { assertExpression("CASE WHEN TRUE THEN ARRAY[1,2] END[1]", null); fail(); } catch (RuntimeException e) { // Expected } }