Search in sources :

Example 66 with Constant

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

the class TestResolver method testStringConversion3.

// special test for both sides are String
@Test
public void testStringConversion3() {
    // Expected left expression
    // $NON-NLS-1$
    ElementSymbol e1 = new ElementSymbol("pm3.g1.e1");
    e1.setType(DataTypeManager.DefaultDataClasses.STRING);
    // Expected right expression
    // $NON-NLS-1$
    Constant e2 = new Constant("2003-02-27");
    // Expected criteria
    CompareCriteria expected = new CompareCriteria();
    expected.setLeftExpression(e1);
    expected.setOperator(CompareCriteria.EQ);
    expected.setRightExpression(e2);
    // Resolve the query and check against expected objects
    // $NON-NLS-1$
    CompareCriteria actual = (CompareCriteria) helpResolveCriteria("pm3.g1.e1='2003-02-27'");
    // if (! actual.getLeftExpression().equals(expected.getLeftExpression())) {
    // System.out.println("left exprs not equal");
    // } else if (!actual.getRightExpression().equals(expected.getRightExpression())) {
    // System.out.println("right exprs not equal");
    // }
    // $NON-NLS-1$
    assertEquals("Did not match expected criteria", expected, actual);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) Test(org.junit.Test)

Example 67 with Constant

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

the class TestAccessNode method testShouldExecuteUpdate.

@Test
public void testShouldExecuteUpdate() throws Exception {
    Update update = new Update();
    // $NON-NLS-1$
    update.setGroup(new GroupSymbol("test"));
    // $NON-NLS-1$ //$NON-NLS-2$
    update.addChange(new ElementSymbol("e1"), new Constant("1"));
    assertTrue(RelationalNodeUtil.shouldExecute(update, false));
    update.setChangeList(new SetClauseList());
    assertFalse(RelationalNodeUtil.shouldExecute(update, false));
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) SetClauseList(org.teiid.query.sql.lang.SetClauseList) Update(org.teiid.query.sql.lang.Update) Test(org.junit.Test)

Example 68 with Constant

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

the class TestAccessNode method testOpen_Defect16059.

@Test
public void testOpen_Defect16059() throws Exception {
    // $NON-NLS-1$
    Query query = (Query) TestResolver.helpResolve("SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5 AND ? IS NULL", RealMetadataFactory.example1Cached());
    IsNullCriteria nullCrit = (IsNullCriteria) ((CompoundCriteria) query.getCriteria()).getCriteria(1);
    nullCrit.setExpression(new Constant(null));
    // $NON-NLS-1$
    helpTestOpen(query, "SELECT e1, e2 FROM pm1.g1 WHERE e2 = 5", true);
}
Also used : Query(org.teiid.query.sql.lang.Query) Constant(org.teiid.query.sql.symbol.Constant) IsNullCriteria(org.teiid.query.sql.lang.IsNullCriteria) Test(org.junit.Test)

Example 69 with Constant

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

the class TestDependentCriteriaProcessor method testNegatedSetCriteria.

@Test
public void testNegatedSetCriteria() throws Exception {
    DependentAccessNode dan = new DependentAccessNode(0);
    // $NON-NLS-1$
    SetCriteria sc = new SetCriteria(new ElementSymbol("e1"), Arrays.asList(new Constant(1), new Constant(2)));
    sc.setAllConstants(true);
    sc.negate();
    DependentCriteriaProcessor dcp = new DependentCriteriaProcessor(1, -1, dan, sc);
    Criteria result = dcp.prepareCriteria();
    assertEquals(sc, result);
    assertFalse(dcp.hasNextCommand());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) SetCriteria(org.teiid.query.sql.lang.SetCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) SetCriteria(org.teiid.query.sql.lang.SetCriteria) Criteria(org.teiid.query.sql.lang.Criteria) Test(org.junit.Test)

Example 70 with Constant

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

the class TestDependentCriteriaProcessor method testSetCriteria.

@Test
public void testSetCriteria() throws Exception {
    DependentAccessNode dan = new DependentAccessNode(0);
    // $NON-NLS-1$
    SetCriteria sc = new SetCriteria(new ElementSymbol("e1"), Arrays.asList(new Constant(1), new Constant(2)));
    sc.setAllConstants(true);
    DependentCriteriaProcessor dcp = new DependentCriteriaProcessor(1, -1, dan, sc);
    Criteria result = dcp.prepareCriteria();
    // $NON-NLS-1$
    assertEquals(new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(1)), result);
    assertTrue(dcp.hasNextCommand());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) SetCriteria(org.teiid.query.sql.lang.SetCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) SetCriteria(org.teiid.query.sql.lang.SetCriteria) Criteria(org.teiid.query.sql.lang.Criteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria) 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