Java 类com.facebook.presto.sql.tree.ArrayConstructor 实例源码

项目:presto    文件:ExpressionInterpreter.java   
@Override
protected Object visitArrayConstructor(ArrayConstructor node, Object context)
{
    Type elementType = ((ArrayType) expressionTypes.get(node)).getElementType();
    BlockBuilder arrayBlockBuilder = elementType.createBlockBuilder(new BlockBuilderStatus(), node.getValues().size());

    for (Expression expression : node.getValues()) {
        Object value = process(expression, context);
        if (value instanceof Expression) {
            return visitFunctionCall(new FunctionCall(QualifiedName.of(ArrayConstructor.ARRAY_CONSTRUCTOR), node.getValues()), context);
        }
        writeNativeValue(elementType, arrayBlockBuilder, value);
    }

    return arrayBlockBuilder.build();
}
项目:presto    文件:TestSqlParser.java   
@Test
public void testArraySubscript()
        throws Exception
{
    assertExpression("ARRAY [1, 2][1]", new SubscriptExpression(
                    new ArrayConstructor(ImmutableList.<Expression>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
    }
}
项目:hue    文件:VeroGenExpFormatter.java   
@Override
protected String visitArrayConstructor(ArrayConstructor node, Void context)
{
    ImmutableList.Builder<String> valueStrings = ImmutableList.builder();
    for (Expression value : node.getValues()) {
        valueStrings.add(sqlFormatter.formatSql(value));
    }
    return "ARRAY[" + Joiner.on(",").join(valueStrings.build()) + "]";
}
项目:presto-query-formatter    文件:ExpressionFormatter.java   
@Override
protected String visitArrayConstructor(ArrayConstructor node, StackableAstVisitorContext<Integer> indent)
{
    ImmutableList.Builder<String> valueStrings = ImmutableList.builder();
    for (Expression value : node.getValues()) {
        valueStrings.add(formatExpression(value, parameters, indent.getContext() + 1));
    }
    return "ARRAY[" + Joiner.on(",").join(valueStrings.build()) + "]";
}
项目:presto    文件:SqlToRowExpressionTranslator.java   
@Override
protected RowExpression visitArrayConstructor(ArrayConstructor node, Void context)
{
    List<RowExpression> arguments = node.getValues().stream()
            .map(value -> process(value, context))
            .collect(toImmutableList());
    List<Type> argumentTypes = arguments.stream()
            .map(RowExpression::getType)
            .collect(toImmutableList());
    return call(arrayConstructorSignature(types.get(node), argumentTypes), types.get(node), arguments);
}
项目:presto    文件:ExpressionAnalyzer.java   
@Override
protected Type visitArrayConstructor(ArrayConstructor node, StackableAstVisitorContext<AnalysisContext> context)
{
    Type type = coerceToSingleType(context, "All ARRAY elements must be the same type: %s", node.getValues());
    Type arrayType = typeManager.getParameterizedType(ARRAY.getName(), ImmutableList.of(type.getTypeSignature()), ImmutableList.of());
    expressionTypes.put(node, arrayType);
    return arrayType;
}
项目:presto    文件:ExpressionFormatter.java   
@Override
protected String visitArrayConstructor(ArrayConstructor node, Boolean unmangleNames)
{
    ImmutableList.Builder<String> valueStrings = ImmutableList.builder();
    for (Expression value : node.getValues()) {
        valueStrings.add(formatSql(value, unmangleNames));
    }
    return "ARRAY[" + Joiner.on(",").join(valueStrings.build()) + "]";
}
项目:presto    文件:TestSqlParser.java   
@Test
public void testArrayConstructor()
        throws Exception
{
    assertExpression("ARRAY []", new ArrayConstructor(ImmutableList.<Expression>of()));
    assertExpression("ARRAY [1, 2]", new ArrayConstructor(ImmutableList.<Expression>of(new LongLiteral("1"), new LongLiteral("2"))));
    assertExpression("ARRAY [1.0, 2.5]", new ArrayConstructor(ImmutableList.<Expression>of(new DoubleLiteral("1.0"), new DoubleLiteral("2.5"))));
    assertExpression("ARRAY ['hi']", new ArrayConstructor(ImmutableList.<Expression>of(new StringLiteral("hi"))));
    assertExpression("ARRAY ['hi', 'hello']", new ArrayConstructor(ImmutableList.<Expression>of(new StringLiteral("hi"), new StringLiteral("hello"))));
}
项目:EchoQuery    文件:ExpressionFormatter.java   
@Override
protected String visitArrayConstructor(ArrayConstructor node, Boolean unmangleNames)
{
    ImmutableList.Builder<String> valueStrings = ImmutableList.builder();
    for (Expression value : node.getValues()) {
        valueStrings.add(formatSql(value, unmangleNames));
    }
    return "ARRAY[" + Joiner.on(",").join(valueStrings.build()) + "]";
}
项目:presto    文件:AggregationAnalyzer.java   
@Override
protected Boolean visitArrayConstructor(ArrayConstructor node, Void context)
{
    return node.getValues().stream().allMatch(expression -> process(expression, context));
}
项目:presto    文件:AstBuilder.java   
@Override
public Node visitArrayConstructor(SqlBaseParser.ArrayConstructorContext context)
{
    return new ArrayConstructor(getLocation(context), visit(context.expression(), Expression.class));
}