Package org.apache.phoenix.parse

Examples of org.apache.phoenix.parse.ParseNode


   
    @Override
    public Expression visitLeave(CaseParseNode node, List<Expression> l) throws SQLException {
        final CaseExpression caseExpression = new CaseExpression(l);
        for (int i = 0; i < node.getChildren().size(); i+=2) {
            ParseNode childNode = node.getChildren().get(i);
            if (childNode instanceof BindParseNode) {
                context.getBindManager().addParamMetaData((BindParseNode)childNode, new DelegateDatum(caseExpression));
            }
        }
        if (ExpressionUtil.isConstant(caseExpression)) {
View Full Code Here


        return true;
    }

    @Override
    public Expression visitLeave(LikeParseNode node, List<Expression> children) throws SQLException {
        ParseNode lhsNode = node.getChildren().get(0);
        ParseNode rhsNode = node.getChildren().get(1);
        Expression lhs = children.get(0);
        Expression rhs = children.get(1);
        if ( rhs.getDataType() != null && lhs.getDataType() != null &&
                !lhs.getDataType().isCoercibleTo(rhs.getDataType())  &&
                !rhs.getDataType().isCoercibleTo(lhs.getDataType())) {
View Full Code Here

        return true;
    }

    @Override
    public Expression visitLeave(NotParseNode node, List<Expression> children) throws SQLException {
        ParseNode childNode = node.getChildren().get(0);
        Expression child = children.get(0);
        if (!PDataType.BOOLEAN.isCoercibleTo(child.getDataType())) {
            throw TypeMismatchException.newException(PDataType.BOOLEAN, child.getDataType(), node.toString());
        }
        if (childNode instanceof BindParseNode) { // TODO: valid/possibe?
View Full Code Here

        return true;
    }

    @Override
    public Expression visitLeave(CastParseNode node, List<Expression> children) throws SQLException {
        ParseNode childNode = node.getChildren().get(0);
        PDataType targetDataType = node.getDataType();
        Expression childExpr = children.get(0);
        PDataType fromDataType = childExpr.getDataType();
       
        if (childNode instanceof BindParseNode) {
View Full Code Here

    public Expression visitLeave(InListParseNode node, List<Expression> l) throws SQLException {
        List<Expression> inChildren = l;
        Expression firstChild = inChildren.get(0);
        ImmutableBytesWritable ptr = context.getTempPtr();
        PDataType firstChildType = firstChild.getDataType();
        ParseNode firstChildNode = node.getChildren().get(0);
       
        if (firstChildNode instanceof BindParseNode) {
            PDatum datum = firstChild;
            if (firstChildType == null) {
                datum = inferBindDatum(inChildren);
            }
            context.getBindManager().addParamMetaData((BindParseNode)firstChildNode, datum);
        }
        for (int i = 1; i < l.size(); i++) {
            ParseNode childNode = node.getChildren().get(i);
            if (childNode instanceof BindParseNode) {
                context.getBindManager().addParamMetaData((BindParseNode)childNode, firstChild);
            }
        }
        return wrapGroupByExpression(InListExpression.create(inChildren, node.isNegate(), ptr));
View Full Code Here

        return true;
    }

    @Override
    public Expression visitLeave(IsNullParseNode node, List<Expression> children) throws SQLException {
        ParseNode childNode = node.getChildren().get(0);
        Expression child = children.get(0);
        if (childNode instanceof BindParseNode) { // TODO: valid/possibe?
            context.getBindManager().addParamMetaData((BindParseNode)childNode, child);
        }
        return wrapGroupByExpression(IsNullExpression.create(child, node.isNegate(), context.getTempPtr()));
View Full Code Here

        }

        Expression expression = factory.create(node, children);

        for (int i = 0; i < node.getChildren().size(); i++) {
            ParseNode childNode = node.getChildren().get(i);
            if (childNode instanceof BindParseNode) {
                context.getBindManager().addParamMetaData((BindParseNode)childNode, binder == null ? expression : binder.getBindMetaData(i, children, expression));
            }
        }
View Full Code Here

    @Override
    public Expression visitLeave(StringConcatParseNode node, List<Expression> children) throws SQLException {
        final StringConcatExpression expression=new StringConcatExpression(children);
        for (int i = 0; i < children.size(); i++) {
            ParseNode childNode=node.getChildren().get(i);
            if(childNode instanceof BindParseNode) {
                context.getBindManager().addParamMetaData((BindParseNode)childNode,expression);
            }
            PDataType type=children.get(i).getDataType();
            if(type==PDataType.VARBINARY){
View Full Code Here

        if (isChildTypeUnknown && arrayElemDataType != null && arrayElemDataType.isCoercibleTo(PDataType.DECIMAL)) {
            arrayElemDataType = PDataType.DECIMAL;
        }
        final PDataType theArrayElemDataType = arrayElemDataType;
        for (int i = 0; i < node.getChildren().size(); i++) {
            ParseNode childNode = node.getChildren().get(i);
            if (childNode instanceof BindParseNode) {
                context.getBindManager().addParamMetaData((BindParseNode)childNode,
                        arrayElemDataType == arrayElemChild.getDataType() ? arrayElemChild :
                            new DelegateDatum(arrayElemChild) {
                    @Override
View Full Code Here

        }
        return (Long) PDataType.LONG.toObject(ptr, expression.getDataType());
    }

    public MutationPlan compile(final CreateSequenceStatement sequence) throws SQLException {
        ParseNode startsWithNode = sequence.getStartWith();
        ParseNode incrementByNode = sequence.getIncrementBy();
        ParseNode maxValueNode = sequence.getMaxValue();
        ParseNode minValueNode = sequence.getMinValue();
        ParseNode cacheNode = sequence.getCacheSize();

        // validate parse nodes
        if (startsWithNode!=null) {
            validateNodeIsStateless(sequence, startsWithNode,
                SQLExceptionCode.START_WITH_MUST_BE_CONSTANT);
        }
        validateNodeIsStateless(sequence, incrementByNode,
            SQLExceptionCode.INCREMENT_BY_MUST_BE_CONSTANT);
        validateNodeIsStateless(sequence, maxValueNode,
            SQLExceptionCode.MAXVALUE_MUST_BE_CONSTANT);
        validateNodeIsStateless(sequence, minValueNode,
            SQLExceptionCode.MINVALUE_MUST_BE_CONSTANT);
        if (cacheNode != null) {
            validateNodeIsStateless(sequence, cacheNode,
                SQLExceptionCode.CACHE_MUST_BE_NON_NEGATIVE_CONSTANT);
        }

        final PhoenixConnection connection = statement.getConnection();
        final StatementContext context = new StatementContext(statement);
       
        // add param meta data if required
        if (startsWithNode instanceof BindParseNode) {
            context.getBindManager().addParamMetaData((BindParseNode) startsWithNode, LONG_DATUM);
        }
        if (incrementByNode instanceof BindParseNode) {
            context.getBindManager().addParamMetaData((BindParseNode) incrementByNode, LONG_DATUM);
        }
        if (maxValueNode instanceof BindParseNode) {
            context.getBindManager().addParamMetaData((BindParseNode) maxValueNode, LONG_DATUM);
        }
        if (minValueNode instanceof BindParseNode) {
            context.getBindManager().addParamMetaData((BindParseNode) minValueNode, LONG_DATUM);
        }
        if (cacheNode instanceof BindParseNode) {
            context.getBindManager().addParamMetaData((BindParseNode) cacheNode, INTEGER_DATUM);
        }
       
        ExpressionCompiler expressionCompiler = new ExpressionCompiler(context);       
        final long incrementBy =
                evalExpression(sequence, context, incrementByNode.accept(expressionCompiler),
                    SQLExceptionCode.INCREMENT_BY_MUST_BE_CONSTANT);
        if (incrementBy == 0) {
            throw SequenceUtil.getException(sequence.getSequenceName().getSchemaName(), sequence
                    .getSequenceName().getTableName(),
                SQLExceptionCode.INCREMENT_BY_MUST_NOT_BE_ZERO);
        }
        final long maxValue =
                evalExpression(sequence, context, maxValueNode.accept(expressionCompiler),
                    SQLExceptionCode.MAXVALUE_MUST_BE_CONSTANT);
        final long minValue =
                evalExpression(sequence, context, minValueNode.accept(expressionCompiler),
                    SQLExceptionCode.MINVALUE_MUST_BE_CONSTANT);
        if (minValue>maxValue) {
            TableName sequenceName = sequence.getSequenceName();
            throw SequenceUtil.getException(sequenceName.getSchemaName(),
                sequenceName.getTableName(),
                SQLExceptionCode.MINVALUE_MUST_BE_LESS_THAN_OR_EQUAL_TO_MAXVALUE);
        }
       
        long startsWithValue;
        if (startsWithNode == null) {
            startsWithValue = incrementBy > 0 ? minValue : maxValue;
        } else {
            startsWithValue =
                    evalExpression(sequence, context, startsWithNode.accept(expressionCompiler),
                        SQLExceptionCode.START_WITH_MUST_BE_CONSTANT);
            if (startsWithValue < minValue || startsWithValue > maxValue) {
                TableName sequenceName = sequence.getSequenceName();
                throw SequenceUtil.getException(sequenceName.getSchemaName(),
                    sequenceName.getTableName(),
                    SQLExceptionCode.STARTS_WITH_MUST_BE_BETWEEN_MIN_MAX_VALUE);
            }
        }
        final long startsWith = startsWithValue;

        long cacheSizeValue;
        if (cacheNode == null) {
            cacheSizeValue =
                    connection
                            .getQueryServices()
                            .getProps()
                            .getLong(QueryServices.SEQUENCE_CACHE_SIZE_ATTRIB,
                                QueryServicesOptions.DEFAULT_SEQUENCE_CACHE_SIZE);
        }
        else {
            cacheSizeValue =
                    evalExpression(sequence, context, cacheNode.accept(expressionCompiler),
                        SQLExceptionCode.CACHE_MUST_BE_NON_NEGATIVE_CONSTANT);
            if (cacheSizeValue < 0) {
                TableName sequenceName = sequence.getSequenceName();
                throw SequenceUtil.getException(sequenceName.getSchemaName(),
                    sequenceName.getTableName(),
View Full Code Here

TOP

Related Classes of org.apache.phoenix.parse.ParseNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.