/** * Parses the list with values to insert and returns them as Objects */ @Override public List<Object> visitValues(Values values, QueryState state){ List<Object> result = new ArrayList<Object>(); for(Expression rowExpression : values.getRows()){ if(rowExpression instanceof Row) { Row row = (Row)rowExpression; for(Expression rowValue : row.getItems()){ if(!(rowValue instanceof Literal)) { state.addException("Unable to parse non-literal value : "+rowValue); return result; } result.add(getObject((Literal)rowValue)); } }else if (rowExpression instanceof Literal){ result.add(getObject((Literal)rowExpression)); }else { state.addException("Unknown VALUES type "+rowExpression.getClass()+" encountered"); return null; } } return result; }
@Override protected String visitRow(Row node, StackableAstVisitorContext<Integer> indent) { return "ROW (" + Joiner.on(", ").join(node.getItems().stream() .map((child) -> process(child, indent)) .collect(toList())) + ")"; }
@Override protected Void visitRow(Row node, Integer indent) { builder.append("ROW("); boolean firstItem = true; for (Expression item : node.getItems()) { if (!firstItem) { builder.append(", "); } process(item, indent); firstItem = false; } builder.append(")"); return null; }
@Override protected Type visitRow(Row node, StackableAstVisitorContext<AnalysisContext> context) { List<Type> types = node.getItems().stream() .map((child) -> process(child, context)) .collect(toImmutableList()); Type type = new RowType(types, Optional.empty()); expressionTypes.put(node, type); return type; }
@Override protected String visitRow(Row node, Boolean unmangleNames) { return "ROW (" + Joiner.on(", ").join(node.getItems().stream() .map((child) -> process(child, unmangleNames)) .collect(toList())) + ")"; }
@Override protected Object visitRow(Row node, Object context) { throw new PrestoException(NOT_SUPPORTED, "Row expressions not yet supported"); }
@Override public Boolean visitRow(Row node, final Void context) { return node.getItems().stream() .allMatch(item -> process(item, context)); }
@Override public Node visitRowConstructor(SqlBaseParser.RowConstructorContext context) { return new Row(getLocation(context), visit(context.expression(), Expression.class)); }
public static Values values(Row... row) { return new Values(ImmutableList.copyOf(row)); }
public static Row row(Expression... values) { return new Row(ImmutableList.copyOf(values)); }