Package org.voltdb.expressions

Examples of org.voltdb.expressions.AbstractExpression


     * @return
     */
    AbstractExpression parseOperationExpression(Node exprNode, NamedNodeMap attrs, Database db) {
        String type = attrs.getNamedItem("type").getNodeValue();
        ExpressionType exprType = ExpressionType.get(type);
        AbstractExpression expr = null;

        if (exprType == ExpressionType.INVALID) {
            throw new PlanningErrorException("Unsupported operation type '" + type + "'");
        }
        try {
            expr = exprType.getExpressionClass().newInstance();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
        expr.setExpressionType(exprType);

        // Allow expressions to read expression-specific data from exprNode.
        // Looks like the design fully abstracts other volt classes from
        // the XML serialization?  Putting this here instead of in derived
        // Expression implementations.

        if (expr instanceof AggregateExpression) {
            Node node;
            if ((node = attrs.getNamedItem("distinct")) != null) {
                AggregateExpression ae = (AggregateExpression)expr;
                ae.m_distinct = Boolean.parseBoolean(node.getNodeValue());
            }
        }

        // setup for children access
        NodeList children = exprNode.getChildNodes();
        int i = 0;

        // get the first (left) node that is an element
        Node leftExprNode = children.item(i++);
        while ((leftExprNode != null) && (leftExprNode.getNodeType() != Node.ELEMENT_NODE))
            leftExprNode = children.item(i++);
        assert(leftExprNode != null);

        // get the second (right) node that is an element (might be null)
        Node rightExprNode = children.item(i++);
        while ((rightExprNode != null) && (rightExprNode.getNodeType() != Node.ELEMENT_NODE))
            rightExprNode = children.item(i++);

        // recursively parse the left subtree (could be another operator or
        // a constant/tuple/param value operand).
        AbstractExpression leftExpr = parseExpressionTree(leftExprNode, db);
        assert((leftExpr != null) || (exprType == ExpressionType.AGGREGATE_COUNT));
        expr.setLeft(leftExpr);

        if (ExpressionUtil.needsRightExpression(expr)) {
            assert(rightExprNode != null);

            // recursively parse the right subtree
            AbstractExpression rightExpr = parseExpressionTree(rightExprNode, db);
            assert(rightExpr != null);
            expr.setRight(rightExpr);
        }

        return expr;
View Full Code Here


        int loopOps;
        do {
            loopOps = 0;

            AbstractExpression inExpr = null;
            while ((inExpr = in.poll()) != null) {
                if (inExpr.getExpressionType() == ExpressionType.CONJUNCTION_AND) {
                    out.add(inExpr.getLeft());
                    out.add(inExpr.getRight());
                    loopOps++;
                }
                else {
                    out.add(inExpr);
                }
View Full Code Here

            // parse out the aggregation columns into the dest table
            for (int i = stmt.groupByColumns.size() + 1; i < stmt.displayColumns.size(); i++) {
                ParsedSelectStmt.ParsedColInfo col = stmt.displayColumns.get(i);
                Column destColumn = destColumnArray.get(i);

                AbstractExpression colExpr = col.expression.getLeft();
                assert(colExpr.getExpressionType() == ExpressionType.VALUE_TUPLE);
                processMaterializedViewColumn(matviewinfo, srcTable, destTable, destColumn,
                        col.expression.getExpressionType(), (TupleValueExpression)colExpr);

                // Correctly set the type of the column so that it's consistent.
                // Otherwise HSQLDB might promote types differently than Volt.
View Full Code Here

                msg += "must have column at index " + String.valueOf(i) + " be " + gbcol.alias;
                throw m_compiler.new VoltCompilerException(msg);
            }
        }

        AbstractExpression coli = stmt.displayColumns.get(i).expression;
        if ((coli.getExpressionType() != ExpressionType.AGGREGATE_COUNT) ||
                (coli.getLeft() != null) ||
                (coli.getRight() != null)) {
            msg += "is missing count(*) as the column after the group by columns, a materialized view requirement.";
            throw m_compiler.new VoltCompilerException(msg);
        }

        for (i++; i < displayColCount; i++) {
View Full Code Here

        // generate the delete node with the right target table
        DeletePlanNode deleteNode = new DeletePlanNode(m_context, getNextPlanNodeId());
        deleteNode.setTargetTableName(targetTable.getTypeName());

        ProjectionPlanNode projectionNode = new ProjectionPlanNode(m_context, getNextPlanNodeId());
        AbstractExpression addressExpr = new TupleAddressExpression();
        PlanColumn colInfo = m_context.getPlanColumn(addressExpr, "tuple_address");
        projectionNode.appendOutputColumn(colInfo);

        if (m_singlePartition == true) {
View Full Code Here

        // for each column in the table in order...
        for (Column column : columns) {

            // get the expression for the column
            AbstractExpression expr = m_parsedInsert.columns.get(column);

            // if there's no expression, make sure the column has
            // some supported default value
            if (expr == null) {
                // if it's not nullable or defaulted we have a problem
                if (column.getNullable() == false && column.getDefaulttype() == 0)
                {
                    throw new PlanningErrorException("Column " + column.getName()
                            + " has no default and is not nullable.");
                }
                ConstantValueExpression const_expr =
                    new ConstantValueExpression();
                expr = const_expr;
                if (column.getDefaulttype() != 0)
                {
                    const_expr.setValue(column.getDefaultvalue());
                }
                else
                {
                    const_expr.setValue("NULL");
                }
            }
            // set the expression type to match the corresponding Column.
            // in reality, the expression will cast its resulting NValue to
            // the intermediate table's tuple; but, that tuple takes its
            // type from these expression types (for now). The tempTuple is
            // eventually tableTuple::copy()'d into the persistent table
            // and must match the persistent table's column type and size.
            // A little round-about, I know. Will get better.
            expr.setValueSize(column.getSize());
            expr.setValueType(VoltType.get((byte)column.getType()));

            // add column to the materialize node.
            PlanColumn colInfo = m_context.getPlanColumn(expr, column.getTypeName());
            materializeNode.appendOutputColumn(colInfo);
        }
View Full Code Here

        // cloning the expression. Walk the clone and configure each TVE with
        // the offset into the input column array.
        for (ParsedSelectStmt.ParsedColInfo outputCol : m_parsedSelect.displayColumns) {
            assert(outputCol.expression != null);
            try {
                AbstractExpression expressionWithRealOffsets =
                    generateProjectionColumnExpression(outputCol,
                                                     rootNode.getOutputColumnGUIDs());
                colInfo = m_context.getPlanColumn(expressionWithRealOffsets, outputCol.alias);
                projectionNode.appendOutputColumn(colInfo);
            } catch (CloneNotSupportedException ex) {
View Full Code Here

    private AbstractExpression generateProjectionColumnExpression(
            ParsedSelectStmt.ParsedColInfo outputCol,
            List<Integer> sourceColumns) throws CloneNotSupportedException
    {
        Stack<AbstractExpression> stack = new Stack<AbstractExpression>();
        AbstractExpression expression = (AbstractExpression) outputCol.expression.clone();
        AbstractExpression currExp = expression;
        while (currExp != null) {

            // Found an aggregate expression.  This is already computed by
            // an earlier plannode and the column should be directly in
            // the output columns.  Look it up by the column alias.
            // We don't actually need to do the work in this if but this
            // allows the planner to barf if the aggregate column doesn't
            // exist.
            if (currExp instanceof AggregateExpression)
            {
                boolean found = false;
                int offset = 0;
                for (Integer colguid : sourceColumns) {
                    PlanColumn plancol = m_context.get(colguid);
                    /* System.out.printf("Expression: %s/%s. Candidate column: %s/%s\n",
                            tve.getColumnAlias(), tve.getTableName(),
                            plancol.originColumnName(), plancol.originTableName()); */
                    if (outputCol.alias.equals(plancol.getDisplayName()))
                    {
                        found = true;
                        expression = (AbstractExpression) plancol.m_expression.clone();
                        assert(expression instanceof TupleValueExpression);
                        TupleValueExpression tve = (TupleValueExpression) expression;
                        tve.setColumnIndex(offset);
                        break;
                    }
                    ++offset;
                }
                if (!found) {
                    LOG.error("PLANNER ERROR: could not match aggregate column alias");
                    LOG.error(getSQLText());
                    throw new RuntimeException("Could not match aggregate column alias.");
                }
                break;
            }

            // found a TVE - calculate its offset into the sourceColumns
            else if (currExp instanceof TupleValueExpression) {
                TupleValueExpression tve = (TupleValueExpression)currExp;
                boolean found = false;
                int offset = 0;
                for (Integer colguid : sourceColumns) {
                    PlanColumn plancol = m_context.get(colguid);
                    /* System.out.printf("Expression: %s/%s. Candidate column: %s/%s\n",
                            tve.getColumnAlias(), tve.getTableName(),
                            plancol.originColumnName(), plancol.originTableName()); */
                    if (tve.getColumnName().equals(plancol.originColumnName()) &&
                        tve.getTableName().equals(plancol.originTableName()))
                    {
                        tve.setColumnIndex(offset);
                        found = true;
                        break;
                    }
                    ++offset;
                }
                if (!found) {
                    // rtb: would like to throw here but doing so breaks sqlcoverage suite.
                    // for now - make this error obvious at least.
                    LOG.error("PLANNER ERROR: could not match tve column alias");
                    LOG.error(getSQLText());
                    throw new RuntimeException("Could not match TVE column alias.");
                }
            }

            // save rhs. process lhs. when lhs is leaf, process a rhs.
            if (currExp.getRight() != null) {
                stack.push(currExp.getRight());
            }
            currExp = currExp.getLeft();
            if (currExp == null) {
                if (!stack.empty())
                    currExp = stack.pop();
            }
        }
View Full Code Here

            if (column == null) {
                String columnName = obj.getString(Members.NAME.name());
                SortOrder sortOrder = SortOrder.get(obj.getString(Members.SORT_ORDER.name()));
                Storage storage = Storage.get(obj.getString(Members.STORAGE.name()));
   
                AbstractExpression expression = null;
                if (!obj.getString(Members.EXPRESSION.name()).isEmpty()) {
                    JSONObject jsonExpression = obj.getJSONObject(Members.EXPRESSION.name());
                    expression = AbstractExpression.fromJSONObject(jsonExpression, db);
                }
                column = new PlanColumn(guid, expression, columnName, sortOrder, storage);
View Full Code Here

            assert (orig_pc != null);

            // Fix all of the offsets in the ExpressionTree
            // We have to clone it so that we don't mess up anybody else that
            // may be referencing the same PlanColumn
            AbstractExpression new_exp = null;
            try {
                new_exp = (AbstractExpression) orig_pc.getExpression().clone();
            } catch (Exception ex) {
                throw new RuntimeException("Unable to clone " + orig_pc, ex);
            }
View Full Code Here

TOP

Related Classes of org.voltdb.expressions.AbstractExpression

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.