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

项目:hue    文件:VeroGenExpFormatter.java   
@Override
protected String visitArithmeticExpression(ArithmeticExpression node, Void context)
{
    if (node.getType().equals(ArithmeticExpression.Type.DIVIDE)) {
        if (_outputDivideByZeroGuard == true) {
            if (node.getRight() instanceof FunctionCall) {
                if (getFunctionName((FunctionCall) node.getRight()).equals("nullifzero")) {
                    // bypass appending nullifzero
                    return formatBinaryExpression(node.getType().getValue(), node.getLeft(), node.getRight());
                }
            } else if (node.getRight() instanceof Literal) {
                // purely literal
                return formatBinaryExpression(node.getType().getValue(), node.getLeft(), node.getRight());
            }

            List<Expression> arguments = new ArrayList<Expression>();
            arguments.add(node.getRight());
            FunctionCall nullifzeroFunc = new FunctionCall(new QualifiedName("nullifzero"), arguments);
            return formatBinaryExpression(node.getType().getValue(), node.getLeft(), nullifzeroFunc);
        } else {
            return formatBinaryExpression(node.getType().getValue(), node.getLeft(), node.getRight());
        }
    } else {
        return formatBinaryExpression(node.getType().getValue(), node.getLeft(), node.getRight());
    }
}
项目:sql4es    文件:UpdateParser.java   
/**
 * 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;
}
项目:presto    文件:CountConstantOptimizer.java   
public static boolean isCountConstant(ProjectNode projectNode, FunctionCall functionCall, Signature signature)
{
    if (!"count".equals(signature.getName()) ||
            signature.getArgumentTypes().size() != 1 ||
            !signature.getReturnType().getBase().equals(StandardTypes.BIGINT)) {
        return false;
    }

    Expression argument = functionCall.getArguments().get(0);
    if (argument instanceof Literal && !(argument instanceof NullLiteral)) {
        return true;
    }

    if (argument instanceof QualifiedNameReference) {
        QualifiedNameReference qualifiedNameReference = (QualifiedNameReference) argument;
        QualifiedName qualifiedName = qualifiedNameReference.getName();
        Symbol argumentSymbol = Symbol.fromQualifiedName(qualifiedName);
        Expression argumentExpression = projectNode.getAssignments().get(argumentSymbol);
        return (argumentExpression instanceof Literal) && (!(argumentExpression instanceof NullLiteral));
    }

    return false;
}
项目:sql4es    文件:UpdateParser.java   
private Object getObject(Literal literal){
    Object value = null;
    if(literal instanceof LongLiteral) value = ((LongLiteral)literal).getValue();
    else if(literal instanceof BooleanLiteral) value = ((BooleanLiteral)literal).getValue();
    else if(literal instanceof DoubleLiteral) value = ((DoubleLiteral)literal).getValue();
    else if(literal instanceof StringLiteral) value = ((StringLiteral)literal).getValue();
    else if(literal instanceof TimeLiteral) value = ((TimeLiteral)literal).getValue();
    else if(literal instanceof TimestampLiteral) value = ((TimestampLiteral)literal).getValue();
    return value;
}
项目:presto    文件:LiteralInterpreter.java   
public static Object evaluate(Metadata metadata, ConnectorSession session, Expression node)
{
    if (!(node instanceof Literal)) {
        throw new IllegalArgumentException("node must be a Literal");
    }
    return new LiteralVisitor(metadata).process(node, session);
}
项目:sql4es    文件:HavingParser.java   
@Override
protected IComparison visitExpression(Expression node, QueryState state) {
    if( node instanceof LogicalBinaryExpression){
        LogicalBinaryExpression boolExp = (LogicalBinaryExpression)node;
        IComparison left = boolExp.getLeft().accept(this, state);
        IComparison right = boolExp.getRight().accept(this, state);
        return new BooleanComparison(left, right, boolExp.getType() == Type.AND);
    }else if( node instanceof ComparisonExpression){
        ComparisonExpression compareExp = (ComparisonExpression)node;
        Column column = new SelectParser().visitExpression(compareExp.getLeft(), state);
        Column leftCol = state.getHeading().getColumnByLabel(column.getLabel());
        if(leftCol == null){
            state.addException("Having reference "+column+" not found in SELECT clause");
            return null;
        }
        // right hand side is a concrete literal to compare with 
        if(compareExp.getRight() instanceof Literal){
            Object value;
            if(compareExp.getRight() instanceof LongLiteral) value = ((LongLiteral)compareExp.getRight()).getValue();
            else if(compareExp.getRight() instanceof BooleanLiteral) value = ((BooleanLiteral)compareExp.getRight()).getValue();
            else if(compareExp.getRight() instanceof DoubleLiteral) value = ((DoubleLiteral)compareExp.getRight()).getValue();
            else if(compareExp.getRight() instanceof StringLiteral) value = ((StringLiteral)compareExp.getRight()).getValue();
            else {
                state.addException("Unable to get value from "+compareExp.getRight());
                return null;
            }
            return new SimpleComparison(leftCol, compareExp.getType(), (Number)value);

            // right hand side refers to another column     
        } else if(compareExp.getRight() instanceof DereferenceExpression || compareExp.getRight() instanceof QualifiedNameReference){
            String col2;
            if(compareExp.getLeft() instanceof DereferenceExpression){
                // parse columns like 'reference.field'
                col2 = SelectParser.visitDereferenceExpression((DereferenceExpression)compareExp.getRight());
            }else{
                col2 = ((QualifiedNameReference)compareExp.getRight()).getName().toString();
            }
            col2 = Heading.findOriginal(state.originalSql(), col2, "having.+", "\\W");
            Column rightCol = state.getHeading().getColumnByLabel(col2);
            if(rightCol == null){
                state.addException("column "+col2+" not found in SELECT clause");
                return null;
            }
            return new SimpleComparison(leftCol, compareExp.getType(), rightCol);
        }else { // unknown right hand side so
            state.addException("Unable to get value from "+compareExp.getRight());
            return null;
        }

    }else if( node instanceof NotExpression){
        state.addException("NOT is currently not supported, use '<>' instead");
    }else{
        state.addException("Unable to parse "+node+" ("+node.getClass().getName()+") is not a supported expression");
    }
    return null;
}
项目:presto    文件:LiteralInterpreter.java   
@Override
protected Object visitLiteral(Literal node, ConnectorSession session)
{
    throw new UnsupportedOperationException("Unhandled literal type: " + node);
}
项目:presto    文件:ExpressionInterpreter.java   
@Override
protected Object visitLiteral(Literal node, Object context)
{
    return LiteralInterpreter.evaluate(metadata, session, node);
}
项目:presto    文件:AggregationAnalyzer.java   
@Override
protected Boolean visitLiteral(Literal node, Void context)
{
    return true;
}