Package org.voltdb.expressions

Examples of org.voltdb.expressions.AbstractExpression


        assertNotNull(scan_node);
       
        Collection<AbstractExpression> exps = PlanNodeUtil.getExpressionsForPlanNode(scan_node);
        assertNotNull(exps);
        assertFalse(exps.isEmpty());
        AbstractExpression exp = CollectionUtil.first(exps);
        assertNotNull(exp);
       
        // Clone the mofo and make sure equals() returns true!
        String json = exp.toJSONString();
        assertFalse(json.isEmpty());
        AbstractExpression clone = AbstractExpression.fromJSONObject(new JSONObject(json), catalog_db);
        assertNotNull(clone);
        assert(ExpressionUtil.equals(exp, clone));

        // Change one of the branches. This should now return false!
        clone.setRight(new NullValueExpression());
        assertFalse(ExpressionUtil.equals(exp, clone));
       
        // Remove both the branch on both sids. This should return true!
        exp.setRight(null);
        clone.setRight(null);
        assert(ExpressionUtil.equals(exp, clone));
    }
View Full Code Here


        assertNotNull(root);
        //System.err.println(PlanNodeUtil.debug(root));
        IndexScanPlanNode scan_node = CollectionUtil.first(PlanNodeUtil.getPlanNodes(root, IndexScanPlanNode.class));
        assertNotNull(scan_node);
       
        AbstractExpression exp = scan_node.getEndExpression();
        assertNotNull(exp);
        String debug = ExpressionUtil.debug(exp);
        assertNotNull(debug);
        assertFalse(debug.isEmpty());
    }
View Full Code Here

        IndexScanPlanNode clone = (IndexScanPlanNode)super.clone(clone_children, clone_inline);
       
        clone.m_searchkeyExpressions = new ArrayList<AbstractExpression>();
        clone.m_endExpression = (AbstractExpression)this.m_endExpression.clone();
        for (AbstractExpression exp : this.m_searchkeyExpressions) {
            AbstractExpression clone_exp = (AbstractExpression)exp.clone();
            clone.m_searchkeyExpressions.add(clone_exp);
        }
        return (clone);
    }
View Full Code Here

        super.validate();

        // Validate Expression Trees
        for (int ctr = 0; ctr < m_outputColumns.size(); ctr++) {
            PlanColumn column = m_context.get(m_outputColumns.get(ctr));
            AbstractExpression exp = column.getExpression();
            if (exp == null) {
                throw new Exception("ERROR: The Output Column Expression at position '" + ctr + "' is NULL");
            }
            exp.validate();
        }
    }
View Full Code Here

        new TestExpressionTreeWalker() {
            @Override
            public void callback(AbstractExpression exp) {
                assertFalse(orig_list.isEmpty());
                AbstractExpression pop_exp = orig_list.remove(0);
                TestExpressionUtil.compareExpressions(pop_exp, exp);
            }
        }.traverse(in_exp);
    }
View Full Code Here

    /**
     *  Clone Sub-Tree
     */
    public void testClone() {
        AbstractExpression cloned_exp = null;
        try {
            cloned_exp = ExpressionUtil.clone(ROOT_EXP);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        assertNotNull(cloned_exp);

        //
        // First build our lists of information about each node in the orignal tree
        // It is assumed that the tree will be traversed in the same order
        //
        final ArrayList<AbstractExpression> orig_exps = new ArrayList<AbstractExpression>();
        new TestExpressionTreeWalker() {
            @Override
            public void callback(AbstractExpression exp) {
                orig_exps.add(exp);
            }
        }.traverse(ROOT_EXP);
        //
        // Then walk through the cloned tree and make sure the objects are different
        // but the information is the same
        //
        new TestExpressionTreeWalker() {
            @Override
            public void callback(AbstractExpression exp) {
                assertFalse(orig_exps.isEmpty());
                AbstractExpression orig_exp = orig_exps.remove(0);
                //
                // We want to make sure that the cloned Expression doesn't
                // have the its ID set to its hashCode
                //
                assertTrue(orig_exp.hashCode() != exp.hashCode());
                //assertFalse(orig_exp.getId().equals(Integer.toString(exp.hashCode())));
                //
                // Use our general comparison method to check other things
                //
                TestExpressionUtil.compareExpressions(orig_exp, exp);
View Full Code Here

        int num_of_subtrees = 5;
        final List<AbstractExpression> combine_exps = new ArrayList<AbstractExpression>();
        final Map<AbstractExpression, AbstractExpression> combine_exps_left = new HashMap<AbstractExpression, AbstractExpression>();
        final Map<AbstractExpression, AbstractExpression> combine_exps_right = new HashMap<AbstractExpression, AbstractExpression>();
        for (int ctr = 0; ctr < num_of_subtrees; ctr++) {
            AbstractExpression exps[] = { new ComparisonExpression(ExpressionType.COMPARE_EQUAL),
                                          new ParameterValueExpression(),
                                          new TupleValueExpression()
            };
            exps[0].setLeft(exps[1]);
            exps[0].setRight(exps[2]);
            //ExpressionUtil.generateIds(exps[0]);
            combine_exps.add(exps[0]);
            combine_exps_left.put(exps[0], exps[1]);
            combine_exps_right.put(exps[0], exps[2]);
        } // FOR

        AbstractExpression combined_exp = null;
        try {
            combined_exp = ExpressionUtil.combine(combine_exps);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        assertNotNull(combined_exp);
        assertEquals(combined_exp.getExpressionType(), ExpressionType.CONJUNCTION_AND);
        //System.err.println(combined_exp.toString(true));

        //
        // Checking whether this worked is a bit tricky because the ordering of the may
        // be different if the implementation changges. So we just need to check to make
View Full Code Here

    // VoltTypeUtil.determineImplicitCasting() push up through the aggregate
    // expression properly.  We'll just do a few of the corner cases and
    // call it good.
    public void testAssignOutputValueTypesRecursivelyForAggregateAvg()
    {
        AbstractExpression root =
            new AggregateExpression(ExpressionType.AGGREGATE_AVG);

        AbstractExpression op = new TupleValueExpression();
        root.setLeft(op);

        // Simple tuple value type gets pushed through
        op.setValueType(VoltType.FLOAT);
        ExpressionUtil.assignOutputValueTypesRecursively(root);
        assertEquals(VoltType.FLOAT, root.getValueType());

        op.setValueType(VoltType.INTEGER);
        ExpressionUtil.assignOutputValueTypesRecursively(root);
        assertEquals(VoltType.INTEGER, root.getValueType());

        op.setValueType(VoltType.DECIMAL);
        ExpressionUtil.assignOutputValueTypesRecursively(root);
        assertEquals(VoltType.DECIMAL, root.getValueType());

        op = new OperatorExpression();
        root.setLeft(op);

        AbstractExpression left = new TupleValueExpression();
        AbstractExpression right = new TupleValueExpression();

        op.setLeft(left);
        op.setRight(right);

        // FLOAT + int type gets promoted to FLOAT
        left.setValueType(VoltType.FLOAT);
        right.setValueType(VoltType.INTEGER);
        ExpressionUtil.assignOutputValueTypesRecursively(root);
        assertEquals(VoltType.FLOAT, root.getValueType());

        // random INT types get promoted to BIGINT
        left.setValueType(VoltType.TINYINT);
        right.setValueType(VoltType.INTEGER);
        ExpressionUtil.assignOutputValueTypesRecursively(root);
        assertEquals(VoltType.BIGINT, root.getValueType());

        // DECIMAL works, at least
        left.setValueType(VoltType.DECIMAL);
        right.setValueType(VoltType.DECIMAL);
        ExpressionUtil.assignOutputValueTypesRecursively(root);
        assertEquals(VoltType.DECIMAL, root.getValueType());
    }
View Full Code Here

    }

    /** Base case test of NUMERIC literal processing */
    public void testAssignLiteralConstantTypes()
    {
        AbstractExpression lit_dec;
        AbstractExpression dec_lit;
        AbstractExpression lit;
        AbstractExpression dec;
        AbstractExpression bint;

        // convert NUMERIC to DECIMAL right/left
        lit = new ConstantValueExpression();
        lit.m_valueType = VoltType.NUMERIC;
        lit.m_valueSize = VoltType.NUMERIC.getLengthInBytesForFixedTypes();
        dec = new ConstantValueExpression();
        dec.m_valueType = VoltType.DECIMAL;
        dec.m_valueSize = VoltType.DECIMAL.getLengthInBytesForFixedTypes();
        lit_dec = new OperatorExpression(ExpressionType.OPERATOR_PLUS, lit, dec);

        ExpressionUtil.assignLiteralConstantTypesRecursively(lit_dec, VoltType.STRING);
        assertEquals(lit.m_valueType, VoltType.DECIMAL);
        assertEquals(lit.m_valueSize, VoltType.DECIMAL.getLengthInBytesForFixedTypes());
        assertEquals(dec.m_valueType, VoltType.DECIMAL);
        assertEquals(dec.m_valueSize, VoltType.DECIMAL.getLengthInBytesForFixedTypes());

        // convert NUMERIC to DECIMAL (left/right)
        lit = new ConstantValueExpression();
        lit.m_valueType = VoltType.NUMERIC;
        lit.m_valueSize = VoltType.NUMERIC.getLengthInBytesForFixedTypes();
        dec = new ConstantValueExpression();
        dec.m_valueType = VoltType.DECIMAL;
        dec.m_valueSize = VoltType.DECIMAL.getLengthInBytesForFixedTypes();
        dec_lit = new OperatorExpression(ExpressionType.OPERATOR_DIVIDE, dec, lit);

        ExpressionUtil.assignLiteralConstantTypesRecursively(dec_lit, VoltType.STRING);
        assertEquals(lit.m_valueType, VoltType.DECIMAL);
        assertEquals(lit.m_valueSize, VoltType.DECIMAL.getLengthInBytesForFixedTypes());
        assertEquals(dec.m_valueType, VoltType.DECIMAL);
        assertEquals(dec.m_valueSize, VoltType.DECIMAL.getLengthInBytesForFixedTypes());


        // convert numeric to float
        lit = new ConstantValueExpression();
        lit.m_valueType = VoltType.NUMERIC;
        lit.m_valueSize = VoltType.NUMERIC.getLengthInBytesForFixedTypes();
        bint = new ConstantValueExpression();
        bint.m_valueType = VoltType.BIGINT;
        bint.m_valueSize = VoltType.BIGINT.getLengthInBytesForFixedTypes();
        AbstractExpression lit_bint =
            new OperatorExpression(ExpressionType.OPERATOR_MINUS, lit, bint);

        ExpressionUtil.assignLiteralConstantTypesRecursively(lit_bint, VoltType.STRING);
        assertEquals(lit.m_valueType, VoltType.FLOAT);
        assertEquals(lit.m_valueSize, VoltType.FLOAT.getLengthInBytesForFixedTypes());
        assertEquals(bint.m_valueType, VoltType.BIGINT);
        assertEquals(bint.m_valueSize, VoltType.BIGINT.getLengthInBytesForFixedTypes());

        // test a larger tree
        lit = new ConstantValueExpression();
        lit.m_valueType = VoltType.NUMERIC;
        lit.m_valueSize = VoltType.NUMERIC.getLengthInBytesForFixedTypes();
        bint = new ConstantValueExpression();
        bint.m_valueType = VoltType.DECIMAL;
        bint.m_valueSize = VoltType.DECIMAL.getLengthInBytesForFixedTypes();
        lit_bint = new OperatorExpression(ExpressionType.OPERATOR_MINUS, lit, bint);

        AbstractExpression root = new OperatorExpression(ExpressionType.OPERATOR_MULTIPLY,
                lit_bint, new TupleValueExpression());
        ExpressionUtil.assignLiteralConstantTypesRecursively(root);
        assertEquals(lit.m_valueType, VoltType.DECIMAL);
        assertEquals(lit.m_valueSize, VoltType.DECIMAL.getLengthInBytesForFixedTypes());
        assertEquals(bint.m_valueType, VoltType.DECIMAL);
View Full Code Here

                traverse(exp.getLeft());
            }
            if (exp.getRight() != null) {
                traverse(exp.getRight());
            }
            AbstractExpression check_exp = m_stack.pop();
            assert(exp.equals(check_exp));
            callback(exp);
            m_depth--;
        }
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.