Search in sources :

Example 26 with Constant

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

the class TestQueryRewriter method testRewriteInNotHashable.

@Test
public void testRewriteInNotHashable() throws Exception {
    Constant c = new Constant(new FakeObject(0));
    // $NON-NLS-1$
    SetCriteria crit = new SetCriteria(c, new ArrayList<Constant>());
    crit.getValues().add(new Constant(new FakeObject(1)));
    crit.getValues().add(new Constant(new FakeObject(2)));
    Criteria actual = QueryRewriter.rewriteCriteria(crit, null, null);
    assertEquals(QueryRewriter.TRUE_CRITERIA, actual);
}
Also used : Constant(org.teiid.query.sql.symbol.Constant) Test(org.junit.Test)

Example 27 with Constant

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

the class TestQueryRewriter method testRewriteCrit_formatDouble.

@Ignore(value = "Cannot deterime if the format is narrowing")
@Test
public void testRewriteCrit_formatDouble() throws Exception {
    // $NON-NLS-1$
    String original = "formatDouble(convert(pm1.g1.e4, double), '$#,##0.00') = '$1,234.50'";
    // $NON-NLS-1$
    String expected = "pm1.g1.e4 = '1234.5'";
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    Criteria origCrit = parseCriteria(original, metadata);
    Criteria expectedCrit = parseCriteria(expected, metadata);
    ((CompareCriteria) expectedCrit).setRightExpression(new Constant(new Double(1234.5)));
    // rewrite
    Criteria actual = QueryRewriter.rewriteCriteria(origCrit, null, null);
    // $NON-NLS-1$
    assertEquals("Did not rewrite correctly: ", expectedCrit, actual);
}
Also used : Constant(org.teiid.query.sql.symbol.Constant) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 28 with Constant

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

the class TestQueryRewriter method testStoredProcedure_9822.

// defect 9822
@Test
public void testStoredProcedure_9822() throws Exception {
    QueryParser parser = new QueryParser();
    // $NON-NLS-1$
    Command command = parser.parseCommand("exec pm1.sp4(5)");
    // resolve
    QueryMetadataInterface metadata = RealMetadataFactory.example1Cached();
    QueryResolver.resolveCommand(command, metadata);
    // rewrite
    Command rewriteCommand = QueryRewriter.rewrite(command, metadata, null);
    Collection<SPParameter> parameters = ((StoredProcedure) rewriteCommand).getParameters();
    for (SPParameter param : parameters) {
        if (param.getParameterType() == ParameterInfo.IN || param.getParameterType() == ParameterInfo.INOUT) {
            assertTrue(param.getExpression() instanceof Constant);
        }
    }
}
Also used : QueryParser(org.teiid.query.parser.QueryParser) Constant(org.teiid.query.sql.symbol.Constant) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 29 with Constant

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

the class TestAliasSymbol method testClone.

@Test
public void testClone() {
    // $NON-NLS-1$ //$NON-NLS-2$
    AliasSymbol a1 = new AliasSymbol("X", new ExpressionSymbol("x", new Constant(1)));
    // $NON-NLS-1$
    a1.setOutputName("foo");
    AliasSymbol clone = (AliasSymbol) a1.clone();
    assertEquals(a1, clone);
    assertEquals(a1.getOutputName(), clone.getOutputName());
}
Also used : AliasSymbol(org.teiid.query.sql.symbol.AliasSymbol) Constant(org.teiid.query.sql.symbol.Constant) ExpressionSymbol(org.teiid.query.sql.symbol.ExpressionSymbol) Test(org.junit.Test)

Example 30 with Constant

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

the class TestCompoundCriteria method testClone2.

public void testClone2() {
    // $NON-NLS-1$
    ElementSymbol e1 = new ElementSymbol("e1");
    // $NON-NLS-1$
    CompareCriteria ccrit1 = new CompareCriteria(e1, CompareCriteria.EQ, new Constant("abc"));
    CompoundCriteria comp = new CompoundCriteria(CompoundCriteria.AND, ccrit1, null);
    UnitTestUtil.helpTestEquivalence(0, comp, comp.clone());
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) CompoundCriteria(org.teiid.query.sql.lang.CompoundCriteria) CompareCriteria(org.teiid.query.sql.lang.CompareCriteria)

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