Package org.apache.derby.impl.sql.compile

Examples of org.apache.derby.impl.sql.compile.ValueNode


* <A NAME="tableExpression">tableExpression</A>
*/
  final public SelectNode tableExpression(ResultColumnList selectList) throws ParseException, StandardException {
        SelectNode      selectNode;
        FromList        fromList;
        ValueNode       whereClause = null;
        GroupByList     groupByList = null;
        ValueNode       havingClause = null;
        Token           whereToken;
    fromList = fromClause();
    switch (jj_nt.kind) {
    case WHERE:
      whereToken = jj_consume_token(WHERE);
      whereClause = whereClause(whereToken);
      break;
    default:
      jj_la1[166] = jj_gen;
      ;
    }
    switch (jj_nt.kind) {
    case GROUP:
      groupByList = groupByClause();
      break;
    default:
      jj_la1[167] = jj_gen;
      ;
    }
    switch (jj_nt.kind) {
    case HAVING:
      havingClause = havingClause();
      break;
    default:
      jj_la1[168] = jj_gen;
      ;
    }
                selectNode = (SelectNode) nodeFactory.getNode(
                                                        C_NodeTypes.SELECT_NODE,
                                                        selectList,
                                                        null,           /* AGGREGATE list */
                                                        fromList,
                                                        whereClause,
                                                        groupByList,
                                                        getContextManager());

                /* A SELECT with a GROUP BY or HAVING clause is the one instance where the
     * parser will generate a tree that does not exactly match the query.
     * The resulting tree is an outer SelectNode with the HAVING clause
     * as its WHERE clause and a FromList containing a single FromSubquery -
     * the user SELECT, minus the HAVING clause.
     * The outer SELECT gets a SELECT *.
     * The FromSubquery will have a null name, something that the user cannot do,
     * to enable the binding of any correlated columns in the HAVING clause.
     */
                if (groupByList != null || havingClause != null)
                {
                        vetSelectList280( selectList );

                        FromSubquery            fromSubquery;
                        ResultColumnList        outerRCL =
                                                                                (ResultColumnList) nodeFactory.getNode(
                                                                                                C_NodeTypes.RESULT_COLUMN_LIST,
                                                                                                getContextManager());

                        /* Wrap the user SELECT in a FromSubquery */
                        fromList = (FromList) nodeFactory.getNode(
                                                                        C_NodeTypes.FROM_LIST,
                                                                        getNodeFactory().doJoinOrderOptimization(),
                                                                        getContextManager());
                        fromSubquery = (FromSubquery) nodeFactory.getNode(
                                                                                                        C_NodeTypes.FROM_SUBQUERY,
                                                                                                        selectNode,
                                                                                                        null,
                                                                                                        null,
                                                                                                        null,
                                                                                                        getContextManager());
                        fromList.addElement(fromSubquery);

                        /* Pull any aggregates out of the HAVING clause and append them to
       * SELECT list in the user's select, replacing the aggregates in
       * the HAVING clause with ColumnReferences to the aggregate.
       * Do NOT replace anything below a ResultSetNode.  This means that
       * we'll replace
       *     FROM x HAVING max(x.x) > 2
       * but not
       *    FROM x HAVING x.x = (select max(y.y) from y)
       * Aggregates under a SELECT are all fixed up correctly
       * later, but here we need to get the aggregates that
       * aren't under result sets.
       *
       * Appended ResultColumns marked as generated so the wrapper
       * select won't see them when the * is expanded.
       *
       * RESOLVE - someday we should try to find matching aggregates
       * instead of just adding them.
             *
             * NOTE: This rewriting of the query tree makes the handling of an ORDER BY
             * clause difficult. See OrderByColumn.pullUpOrderByColumn. It makes specific
             * assumptions about the structure of the generated query tree. Do not make
             * any changes to this transformation without carefully considering the
             * OrderByColumn pullUpOrderByColumn and bindOrderByColumn methods.
       */
                        if (havingClause != null)
                        {
                                ReplaceAggregatesWithCRVisitor visitor =
                                        new ReplaceAggregatesWithCRVisitor(selectList, ResultSetNode.class);
                                havingClause = (ValueNode)havingClause.accept(visitor);

                                // fix for HAVING without GROUP BY, makes sure we get one
                                // aggregate operator by adding a count(*), this fixes beetle 5853, 5890
                                if (groupByList == null) {
                                        ValueNode vn = (ValueNode) nodeFactory.getNode(
                                                                C_NodeTypes.AGGREGATE_NODE,
                                                                null,
                                                                org.apache.derby.impl.sql.compile.CountAggregateDefinition.class,
                                                                Boolean.FALSE, // distinct Boolean.TRUE?
                                                                "COUNT(*)",
 
View Full Code Here


        int                                     joinType = JoinNode.INNERJOIN;
        ResultSetNode           rightRSN;
        TableOperatorNode       ton = null;
        Object[]                        onOrUsingClause = null;
        ResultColumnList        usingClause = null;
        ValueNode                       onClause;
    switch (jj_nt.kind) {
    case INNER:
    case LEFT:
    case RIGHT:
      joinType = joinType();
View Full Code Here

  }

  final public Object[] joinSpecification(ResultSetNode leftRSN, ResultSetNode rightRSN) throws ParseException, StandardException {
        Object[]                        onOrUsingClause = new Object[ON_OR_USING_CLAUSE_SIZE];
        ResultColumnList        usingClause = null;
        ValueNode                       joinClause = null;
    joinClause = joinCondition();
                onOrUsingClause[ON_CLAUSE] = joinClause;
                onOrUsingClause[USING_CLAUSE] = usingClause;
                {if (true) return onOrUsingClause;}
    throw new Error("Missing return statement in function");
View Full Code Here

                {if (true) return onOrUsingClause;}
    throw new Error("Missing return statement in function");
  }

  final public ValueNode joinCondition() throws ParseException, StandardException {
        ValueNode joinClause;
    jj_consume_token(ON);
    joinClause = valueExpression(false);
                {if (true) return joinClause;}
    throw new Error("Missing return statement in function");
  }
View Full Code Here

** Note that set function and aggregate are used
** interchangeably in the parser.  The tree has
** aggregate nodes.
*/
  final public ValueNode aggregateNode() throws ParseException, StandardException {
        ValueNode agg;
    switch (jj_nt.kind) {
    case COUNT:
      jj_consume_token(COUNT);
      jj_consume_token(LEFT_PAREN);
      switch (jj_nt.kind) {
View Full Code Here

    throw new Error("Missing return statement in function");
  }

  final public ValueNode aggregateExpression(String aggName, Class aggClass) throws ParseException, StandardException {
        boolean         distinct = false;
        ValueNode       value;
    if (jj_2_40(1)) {
      distinct = setQuantifier();
    } else {
      ;
    }
View Full Code Here

  }

  final public ValueNode generalAggregate() throws ParseException, StandardException {
        Token                   aggToken;
        String                  methodAliasString;
        ValueNode       aggExpr;
        ValueNode               value;
    aggToken = builtInAggregateType();
    jj_consume_token(LEFT_PAREN);
    aggExpr = aggregateExpression(aggName(aggToken), aggClass(aggToken));
    jj_consume_token(RIGHT_PAREN);
                {if (true) return aggExpr;}
View Full Code Here

    throw new Error("Missing return statement in function");
  }

  final public ValueNode castSpecification() throws ParseException, StandardException {
        DataTypeDescriptor dts;
        ValueNode                treeTop;
        ValueNode                value;
        int                              charType;
        int                              length = -1;
    jj_consume_token(CAST);
    jj_consume_token(LEFT_PAREN);
    value = castOperand();
View Full Code Here

    }
    throw new Error("Missing return statement in function");
  }

  final public ValueNode castOperand() throws ParseException, StandardException {
        ValueNode value;
    if (jj_2_41(1)) {
      value = additiveExpression(null, 0, false);
                {if (true) return value;}
    } else {
      switch (jj_nt.kind) {
View Full Code Here

/*
* <A NAME="whereClause">whereClause</A>
*/
  final public ValueNode whereClause(Token beginToken) throws ParseException, StandardException {
        ValueNode       value;
        Token           endToken;
    /* valueExpression() was searchCondition() */
            value = valueExpression(false);
                endToken = getToken(0);

                value.setBeginOffset( beginToken.endOffset + 1 );
                value.setEndOffset( endToken.endOffset );

                {if (true) return value;}
    throw new Error("Missing return statement in function");
  }
View Full Code Here

TOP

Related Classes of org.apache.derby.impl.sql.compile.ValueNode

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.