Search in sources :

Example 81 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestProjectNode method testProjectExpressionFunctionFails.

@Test
public void testProjectExpressionFunctionFails() throws Exception {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.STRING);
    List elements = new ArrayList();
    elements.add(es1);
    // $NON-NLS-1$ //$NON-NLS-2$
    Function func = new Function("convert", new Expression[] { es1, new Constant("integer") });
    // $NON-NLS-1$
    FunctionDescriptor fd = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("convert", new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING });
    func.setFunctionDescriptor(fd);
    func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    // $NON-NLS-1$
    ExpressionSymbol expr = new ExpressionSymbol("expr", func);
    List projectElements = new ArrayList();
    projectElements.add(expr);
    List[] data = new List[] { // $NON-NLS-1$
    Arrays.asList(new Object[] { "1" }), // $NON-NLS-1$
    Arrays.asList(new Object[] { "2x" }) };
    // $NON-NLS-1$
    String expectedMessage = "TEIID30328 UNABLE TO EVALUATE CONVERT(E1, INTEGER): TEIID30384 ERROR WHILE EVALUATING FUNCTION CONVERT";
    helpTestProjectFails(projectElements, data, elements, expectedMessage);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Function(org.teiid.query.sql.symbol.Function) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) ExpressionSymbol(org.teiid.query.sql.symbol.ExpressionSymbol) Test(org.junit.Test)

Example 82 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestSelectNode method testTimeslicing.

@Test
public void testTimeslicing() throws TeiidComponentException, TeiidProcessingException {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List elements = new ArrayList();
    elements.add(es1);
    CompareCriteria crit = new CompareCriteria(es1, CompareCriteria.EQ, new Constant(new Integer(1)));
    List[] data = new List[] { Arrays.asList(1), Arrays.asList(1), Arrays.asList(1) };
    List childElements = new ArrayList();
    childElements.add(es1);
    helpTestSelect(elements, crit, childElements, null, data, new FakeRelationalNode(2, data), new SelectNode(3) {

        int i = 0;

        @Override
        protected Evaluator getEvaluator(Map elementMap) {
            return new Evaluator(elementMap, getDataManager(), getContext()) {

                @Override
                public Boolean evaluateTVL(Criteria criteria, List<?> tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
                    if (i++ == 1) {
                        throw new QueryProcessor.ExpiredTimeSliceException();
                    }
                    return super.evaluateTVL(criteria, tuple);
                }
            };
        }
    });
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) ExpressionEvaluationException(org.teiid.api.exception.query.ExpressionEvaluationException) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) Criteria(org.teiid.query.sql.lang.Criteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) Evaluator(org.teiid.query.eval.Evaluator) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) BlockedException(org.teiid.common.buffer.BlockedException) QueryProcessor(org.teiid.query.processor.QueryProcessor) ArrayList(java.util.ArrayList) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 83 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestFrameUtil method getExamplePlan.

/**
 * <pre>
 * Join(groups=[3, 2, 1])
 *   Null(groups=[1])
 *   Select(groups=[2])
 *     Join(groups=[3, 2])
 *       Source(groups=[3])
 *       Access(groups=[2])
 * </pre>
 */
public static PlanNode getExamplePlan() {
    PlanNode joinNode = NodeFactory.getNewNode(NodeConstants.Types.JOIN);
    joinNode.setProperty(NodeConstants.Info.JOIN_TYPE, JoinType.JOIN_CROSS);
    joinNode.addGroup(getGroup(1));
    joinNode.addGroup(getGroup(2));
    joinNode.addGroup(getGroup(3));
    PlanNode nullNode = NodeFactory.getNewNode(NodeConstants.Types.NULL);
    nullNode.addGroup(getGroup(1));
    joinNode.addFirstChild(nullNode);
    PlanNode childCriteria = NodeFactory.getNewNode(NodeConstants.Types.SELECT);
    childCriteria.setProperty(Info.SELECT_CRITERIA, new IsNullCriteria(new Constant(1)));
    childCriteria.addGroup(getGroup(2));
    joinNode.addLastChild(childCriteria);
    PlanNode childJoinNode = NodeFactory.getNewNode(NodeConstants.Types.JOIN);
    childJoinNode.setProperty(NodeConstants.Info.JOIN_TYPE, JoinType.JOIN_CROSS);
    childJoinNode.addGroup(getGroup(2));
    childJoinNode.addGroup(getGroup(3));
    childCriteria.addFirstChild(childJoinNode);
    PlanNode accessNode = NodeFactory.getNewNode(NodeConstants.Types.ACCESS);
    accessNode.addGroup(getGroup(2));
    childJoinNode.addFirstChild(accessNode);
    PlanNode sourceNode = NodeFactory.getNewNode(NodeConstants.Types.SOURCE);
    sourceNode.addGroup(getGroup(3));
    childJoinNode.addFirstChild(sourceNode);
    return joinNode;
}
Also used : PlanNode(org.teiid.query.optimizer.relational.plantree.PlanNode) Constant(org.teiid.query.sql.symbol.Constant) IsNullCriteria(org.teiid.query.sql.lang.IsNullCriteria)

Example 84 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestRuleChooseDependent method testCardinalityWithKeyMatchCrit.

/**
 * Tests SetCriteria in the atomic criteria
 */
@Test
public void testCardinalityWithKeyMatchCrit() throws Exception {
    // override default metadata
    this.metadata = RealMetadataFactory.example4();
    GroupSymbol group1 = getPhysicalGroup(1, 2);
    ElementSymbol g1e2 = getElementSymbol(1, 2, 2);
    GroupSymbol group2 = getPhysicalGroup(3, 3);
    ElementSymbol g2e1 = getElementSymbol(3, 3, 1);
    ElementSymbol g2e2 = getElementSymbol(3, 3, 2);
    // Join criteria
    ArrayList crits = new ArrayList(1);
    CompareCriteria crit2 = new CompareCriteria(g1e2, CompareCriteria.EQ, g2e2);
    crits.add(crit2);
    Criteria atomicCrit1 = null;
    // $NON-NLS-1$
    Criteria atomicCrit2 = new MatchCriteria(g2e1, new Constant(new String("ab%")));
    int expected = RIGHT_SIDE;
    helpTestChooseSiblingAndMarkDependent(group1, atomicCrit1, group2, atomicCrit2, crits, expected);
    expected = LEFT_SIDE;
    helpTestChooseSiblingAndMarkDependent(group2, atomicCrit2, group1, atomicCrit1, crits, expected);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 85 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestRuleChooseDependent method testCardinalityWithKeyCompoundCritAND.

/**
 * Tests that join side with larger cardinality will still have a lower
 * cost computed because it has a criteria including a primary key
 */
@Test
public void testCardinalityWithKeyCompoundCritAND() throws Exception {
    // override default metadata
    this.metadata = RealMetadataFactory.example4();
    GroupSymbol group1 = getPhysicalGroup(1, 2);
    ElementSymbol g1e2 = getElementSymbol(1, 2, 2);
    GroupSymbol group2 = getPhysicalGroup(3, 3);
    ElementSymbol g2e1 = getElementSymbol(3, 3, 1);
    ElementSymbol g2e2 = getElementSymbol(3, 3, 2);
    // Join criteria
    ArrayList crits = new ArrayList(1);
    crits.add(new CompareCriteria(g1e2, CompareCriteria.EQ, g2e2));
    Criteria atomicCrit1 = null;
    Criteria crit1 = new CompareCriteria(g2e1, CompareCriteria.EQ, new Constant(new Integer(5)));
    Criteria crit2 = new CompareCriteria(g2e1, CompareCriteria.EQ, new Constant(new Integer(7)));
    CompoundCriteria atomicCrit2 = new CompoundCriteria(CompoundCriteria.AND, crit1, crit2);
    int expected = LEFT_SIDE;
    helpTestChooseSiblingAndMarkDependent(group1, atomicCrit1, group2, atomicCrit2, crits, expected);
    expected = RIGHT_SIDE;
    helpTestChooseSiblingAndMarkDependent(group2, atomicCrit2, group1, atomicCrit1, crits, expected);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Constant (org.teiid.query.sql.symbol.Constant)203 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)94 Test (org.junit.Test)88 ArrayList (java.util.ArrayList)61 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)48 List (java.util.List)38 Expression (org.teiid.query.sql.symbol.Expression)38 Function (org.teiid.query.sql.symbol.Function)31 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)25 Query (org.teiid.query.sql.lang.Query)22 Select (org.teiid.query.sql.lang.Select)15 Reference (org.teiid.query.sql.symbol.Reference)14 From (org.teiid.query.sql.lang.From)12 HashMap (java.util.HashMap)11 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)11 Criteria (org.teiid.query.sql.lang.Criteria)11 SetQuery (org.teiid.query.sql.lang.SetQuery)11 LinkedList (java.util.LinkedList)10 Limit (org.teiid.query.sql.lang.Limit)10 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)9