@Override protected String visitRow(Row node, Void context) { return "ROW (" + Joiner.on(", ").join(node.getItems().stream() .map((child) -> process(child, context)) .collect(toList())) + ")"; }
@Override protected Object visitRow(Row node, Object context) { RowType rowType = (RowType) type(node); List<Type> parameterTypes = rowType.getTypeParameters(); List<Expression> arguments = node.getItems(); int cardinality = arguments.size(); List<Object> values = new ArrayList<>(cardinality); for (Expression argument : arguments) { values.add(process(argument, context)); } if (hasUnresolvedValue(values)) { return new Row(toExpressions(values, parameterTypes)); } else { BlockBuilder blockBuilder = new RowBlockBuilder(parameterTypes, null, 1); BlockBuilder singleRowBlockWriter = blockBuilder.beginBlockEntry(); for (int i = 0; i < cardinality; ++i) { writeNativeValue(parameterTypes.get(i), singleRowBlockWriter, values.get(i)); } blockBuilder.closeEntry(); return rowType.getObject(blockBuilder, 0); } }
public static Row row(Expression... values) { return new Row(ImmutableList.copyOf(values)); }
private Expression createEmptyColumnStatsRow(String columnName) { ImmutableList.Builder<Expression> rowValues = ImmutableList.builder(); rowValues.add(new StringLiteral(columnName)); rowValues.add(NULL_DOUBLE); rowValues.add(NULL_DOUBLE); rowValues.add(NULL_DOUBLE); rowValues.add(NULL_DOUBLE); rowValues.add(NULL_VARCHAR); rowValues.add(NULL_VARCHAR); return new Row(rowValues.build()); }
@Override protected R visitRow(Row node, C context) { for (Expression expression : node.getItems()) { process(expression, context); } return null; }
private static Row createTableStatsRow(TableStatistics tableStatistics) { ImmutableList.Builder<Expression> rowValues = ImmutableList.builder(); rowValues.add(NULL_VARCHAR); rowValues.add(NULL_DOUBLE); rowValues.add(NULL_DOUBLE); rowValues.add(NULL_DOUBLE); rowValues.add(createEstimateRepresentation(tableStatistics.getRowCount())); rowValues.add(NULL_VARCHAR); rowValues.add(NULL_VARCHAR); return new Row(rowValues.build()); }
@Override public Boolean visitRow(Row node, final Void context) { return node.getItems().stream() .allMatch(item -> process(item, context)); }
private Row createColumnStatsRow(String columnName, Type type, ColumnStatistics columnStatistics) { ImmutableList.Builder<Expression> rowValues = ImmutableList.builder(); rowValues.add(new StringLiteral(columnName)); rowValues.add(createEstimateRepresentation(columnStatistics.getDataSize())); rowValues.add(createEstimateRepresentation(columnStatistics.getDistinctValuesCount())); rowValues.add(createEstimateRepresentation(columnStatistics.getNullsFraction())); rowValues.add(NULL_DOUBLE); rowValues.add(toStringLiteral(type, columnStatistics.getRange().map(DoubleRange::getMin))); rowValues.add(toStringLiteral(type, columnStatistics.getRange().map(DoubleRange::getMax))); return new Row(rowValues.build()); }
@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 public Node visitRowConstructor(SqlBaseParser.RowConstructorContext context) { return new Row(getLocation(context), visit(context.expression(), Expression.class)); }
@Override protected RowExpression visitRow(Row node, Void context) { List<RowExpression> arguments = node.getItems().stream() .map(value -> process(value, context)) .collect(toImmutableList()); Type returnType = getType(node); List<Type> argumentTypes = node.getItems().stream() .map(this::getType) .collect(toImmutableList()); return call(rowConstructorSignature(returnType, argumentTypes), returnType, arguments); } }
new QuerySpecification( selectList( new DereferenceExpression(new Cast(new Row(Lists.newArrayList(new LongLiteral("11"), new LongLiteral("12"))), "ROW(COL0 INTEGER,COL1 INTEGER)"), identifier("col0"))), Optional.empty(), Optional.empty(),
@Override protected Type visitRow(Row node, StackableAstVisitorContext<Context> context) { List<Type> types = node.getItems().stream() .map((child) -> process(child, context)) .collect(toImmutableList()); Type type = RowType.anonymous(types); return setExpressionType(node, type); }
public static Row row(Expression... values) { return new Row(ImmutableList.copyOf(values)); }
@Override protected RelationPlan visitValues(Values node, Void context) { Scope scope = analysis.getScope(node); ImmutableList.Builder<Symbol> outputSymbolsBuilder = ImmutableList.builder(); for (Field field : scope.getRelationType().getVisibleFields()) { Symbol symbol = symbolAllocator.newSymbol(field); outputSymbolsBuilder.add(symbol); } ImmutableList.Builder<List<Expression>> rows = ImmutableList.builder(); for (Expression row : node.getRows()) { ImmutableList.Builder<Expression> values = ImmutableList.builder(); if (row instanceof Row) { for (Expression item : ((Row) row).getItems()) { Expression expression = Coercer.addCoercions(item, analysis); values.add(ExpressionTreeRewriter.rewriteWith(new ParameterRewriter(analysis.getParameters(), analysis), expression)); } } else { Expression expression = Coercer.addCoercions(row, analysis); values.add(ExpressionTreeRewriter.rewriteWith(new ParameterRewriter(analysis.getParameters(), analysis), expression)); } rows.add(values.build()); } ValuesNode valuesNode = new ValuesNode(idAllocator.getNextId(), outputSymbolsBuilder.build(), rows.build()); return new RelationPlan(valuesNode, scope, outputSymbolsBuilder.build()); }
public static Row row(Expression... values) { return new Row(ImmutableList.copyOf(values)); }
List<Expression> items = ((Row) row).getItems(); for (int i = 0; i < items.size(); i++) { Type expectedType = fieldTypes.get(i);
@Override public Node visitRowConstructor(SqlBaseParser.RowConstructorContext context) { return new Row(getLocation(context), visit(context.expression(), Expression.class)); }
@Override protected String visitRow(Row node, Void context) { return "ROW (" + Joiner.on(", ").join(node.getItems().stream() .map((child) -> process(child, context)) .collect(toList())) + ")"; }
@Override public Node visitRowConstructor(SqlBaseParser.RowConstructorContext context) { return new Row(getLocation(context), visit(context.expression(), Expression.class)); }