Search in sources :

Example 71 with Constant

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

the class TestJoinNode method helpCreateJoin.

protected void helpCreateJoin() {
    // $NON-NLS-1$
    ElementSymbol es1 = new ElementSymbol("e1");
    es1.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    // $NON-NLS-1$
    ElementSymbol es2 = new ElementSymbol("e2");
    es2.setType(DataTypeManager.DefaultDataClasses.INTEGER);
    List leftElements = new ArrayList();
    leftElements.add(es1);
    leftNode = new BlockingFakeRelationalNode(1, leftTuples);
    leftNode.setElements(leftElements);
    List rightElements = new ArrayList();
    rightElements.add(es2);
    rightNode = new BlockingFakeRelationalNode(2, rightTuples) {

        @Override
        public boolean hasBuffer() {
            return false;
        }

        @Override
        public TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
            fail();
            throw new AssertionError();
        }
    };
    rightNode.setElements(rightElements);
    List joinElements = new ArrayList();
    joinElements.add(es1);
    joinElements.add(es2);
    join = new JoinNode(3);
    joinStrategy = new NestedLoopJoinStrategy();
    join.setJoinStrategy(joinStrategy);
    join.setElements(joinElements);
    join.setJoinType(joinType);
    switch(criteriaType) {
        case NO_CRITERIA:
            break;
        case EQUAL_CRITERIA:
            join.setJoinExpressions(Arrays.asList(es1), Arrays.asList(es2));
            joinStrategy = new MergeJoinStrategy(SortOption.SORT, SortOption.SORT, false);
            join.setJoinStrategy(joinStrategy);
            break;
        case FUNCTION_CRITERIA:
            // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
            Function func = new Function("lookup", new Expression[] { new Constant("pm1.g1"), new Constant("e2"), new Constant("e1"), es1 });
            // $NON-NLS-1$
            FunctionDescriptor desc = RealMetadataFactory.SFM.getSystemFunctionLibrary().findFunction("lookup", new Class[] { String.class, String.class, String.class, Integer.class });
            func.setFunctionDescriptor(desc);
            func.setType(DataTypeManager.DefaultDataClasses.INTEGER);
            CompareCriteria joinCriteria = new CompareCriteria(es2, CompareCriteria.EQ, func);
            join.setJoinCriteria(joinCriteria);
            break;
    }
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) TupleBuffer(org.teiid.common.buffer.TupleBuffer) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) BlockedException(org.teiid.common.buffer.BlockedException) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Function(org.teiid.query.sql.symbol.Function) ArrayList(java.util.ArrayList) List(java.util.List) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 72 with Constant

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

the class TestLimitNode method getLimitNode.

private static LimitNode getLimitNode(int limit, RelationalNode child) throws Exception {
    LimitNode node = new LimitNode(1, new Constant(new Integer(limit)), new Constant(new Integer(0)));
    node.addChild(child);
    node.open();
    return node;
}
Also used : Constant(org.teiid.query.sql.symbol.Constant)

Example 73 with Constant

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

the class TestLimitNode method testClone.

@Test
public void testClone() {
    LimitNode node = new LimitNode(1, new Constant(new Integer(-1)), null);
    LimitNode clone = (LimitNode) node.clone();
    assertEquals(node.getLimitExpr(), clone.getLimitExpr());
    assertNull(clone.getOffsetExpr());
    node = new LimitNode(1, null, new Constant(new Integer(-1)));
    clone = (LimitNode) node.clone();
    assertNull(clone.getLimitExpr());
}
Also used : Constant(org.teiid.query.sql.symbol.Constant) Test(org.junit.Test)

Example 74 with Constant

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

the class TestFunctionResolving method testResolveConvertReference.

@Test
public void testResolveConvertReference() throws Exception {
    // $NON-NLS-1$
    Function function = new Function("convert", new Expression[] { new Reference(0), new Constant(DataTypeManager.DefaultDataTypes.BOOLEAN) });
    ResolverVisitor.resolveLanguageObject(function, RealMetadataFactory.example1Cached());
    assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getType());
    assertEquals(DataTypeManager.DefaultDataClasses.BOOLEAN, function.getArgs()[0].getType());
}
Also used : Function(org.teiid.query.sql.symbol.Function) Reference(org.teiid.query.sql.symbol.Reference) Constant(org.teiid.query.sql.symbol.Constant) Test(org.junit.Test)

Example 75 with Constant

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

the class TestProcedureResolving method testVarArgs.

@Test
public void testVarArgs() throws Exception {
    String ddl = "create foreign procedure proc (x integer, VARIADIC z integer) returns (x string);\n";
    TransformationMetadata tm = createMetadata(ddl);
    // $NON-NLS-1$
    String sql = "call proc (1, 2, 3)";
    StoredProcedure sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
    assertEquals("EXEC proc(1, 2, 3)", sp.toString());
    assertEquals(new Constant(1), sp.getParameter(1).getExpression());
    assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))), sp.getParameter(2).getExpression());
    assertEquals(SPParameter.RESULT_SET, sp.getParameter(3).getParameterType());
    // $NON-NLS-1$
    sql = "call proc (1)";
    sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
    assertEquals("EXEC proc(1)", sp.toString());
    assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, new ArrayList<Expression>(0)), sp.getParameter(2).getExpression());
    sp = (StoredProcedure) QueryRewriter.evaluateAndRewrite(sp, new Evaluator(null, null, null), null, tm);
    LanguageBridgeFactory lbf = new LanguageBridgeFactory(tm);
    Call call = (Call) lbf.translate(sp);
    assertEquals("EXEC proc(1)", call.toString());
    // $NON-NLS-1$
    sql = "call proc (1, (2, 3))";
    sp = (StoredProcedure) TestResolver.helpResolve(sql, tm);
    assertEquals("EXEC proc(1, (2, 3))", sp.toString());
    assertEquals(new Constant(1), sp.getParameter(1).getExpression());
    assertEquals(new Array(DataTypeManager.DefaultDataClasses.INTEGER, Arrays.asList((Expression) new Constant(2), new Constant(3))), sp.getParameter(2).getExpression());
    assertEquals(SPParameter.RESULT_SET, sp.getParameter(3).getParameterType());
}
Also used : Array(org.teiid.query.sql.symbol.Array) Call(org.teiid.language.Call) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) Evaluator(org.teiid.query.eval.Evaluator) LanguageBridgeFactory(org.teiid.dqp.internal.datamgr.LanguageBridgeFactory) 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