Search in sources :

Example 56 with Constant

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

the class TestCriteriaEvaluator method helpTestIsNull.

private void helpTestIsNull(String value, boolean negated, boolean expectedMatch) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
    IsNullCriteria criteria = new IsNullCriteria(new Constant(value));
    criteria.setNegated(negated);
    boolean result = Evaluator.evaluate(criteria);
    // $NON-NLS-1$
    assertEquals("Result did not match expected value", expectedMatch, result);
}
Also used : Constant(org.teiid.query.sql.symbol.Constant)

Example 57 with Constant

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

the class TestCriteriaEvaluator method testCompareSubqueryCriteriaNoRows1.

/**
 * The check for empty rows should happen before the check for a null left expression
 * @throws Exception
 */
@Test
public void testCompareSubqueryCriteriaNoRows1() throws Exception {
    SubqueryCompareCriteria crit = helpGetCompareSubqueryCriteria(SubqueryCompareCriteria.EQ, SubqueryCompareCriteria.ANY);
    crit.setLeftExpression(new Constant(null));
    crit.negate();
    helpTestCompareSubqueryCriteria(crit, true, Collections.emptyList());
}
Also used : Constant(org.teiid.query.sql.symbol.Constant) Test(org.junit.Test)

Example 58 with Constant

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

the class TestCriteriaEvaluator method helpTestSetCriteria.

private void helpTestSetCriteria(Integer value, boolean negated, boolean expectedMatch) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
    Collection constants = new ArrayList(2);
    constants.add(new Constant(new Integer(1000)));
    constants.add(new Constant(new Integer(5000)));
    SetCriteria crit = new SetCriteria(new Constant(value), constants);
    crit.setNegated(negated);
    boolean result = Evaluator.evaluate(crit);
    // $NON-NLS-1$
    assertEquals("Result did not match expected value", expectedMatch, result);
}
Also used : Constant(org.teiid.query.sql.symbol.Constant) ArrayList(java.util.ArrayList) Collection(java.util.Collection)

Example 59 with Constant

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

the class TestResolver method testUser.

/**
 * test jdbc USER method
 */
@Test
public void testUser() {
    // String sql = "select intkey from SmallA where user() = 'bqt2'";
    // Expected left expression
    FunctionLibrary library = RealMetadataFactory.SFM.getSystemFunctionLibrary();
    FunctionDescriptor fd = library.findFunction(FunctionLibrary.USER, new Class[] {});
    Function user = new Function(fd.getName(), new Expression[] {});
    user.setFunctionDescriptor(fd);
    // Expected criteria
    CompareCriteria expected = new CompareCriteria();
    // Expected right expression
    // $NON-NLS-1$
    Expression e1 = new Constant("bqt2", String.class);
    // Expected left expression
    expected.setLeftExpression(user);
    expected.setOperator(CompareCriteria.EQ);
    expected.setRightExpression(e1);
    // Resolve the query and check against expected objects
    // $NON-NLS-1$
    CompareCriteria actual = (CompareCriteria) helpResolveCriteria("user()='bqt2'");
    // $NON-NLS-1$
    assertEquals("Did not match expected criteria", expected, actual);
}
Also used : Function(org.teiid.query.sql.symbol.Function) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) FunctionLibrary(org.teiid.query.function.FunctionLibrary) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) Test(org.junit.Test)

Example 60 with Constant

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

the class TestResolver method testStringConversion2.

@Test
public void testStringConversion2() {
    // Expected left expression
    // $NON-NLS-1$
    ElementSymbol e1 = new ElementSymbol("pm3.g1.e2");
    e1.setType(DataTypeManager.DefaultDataClasses.DATE);
    // Expected right expression
    Class srcType = DataTypeManager.DefaultDataClasses.STRING;
    String tgtTypeName = DataTypeManager.DefaultDataTypes.DATE;
    // $NON-NLS-1$
    Expression expression = new Constant("2003-02-27");
    FunctionLibrary library = RealMetadataFactory.SFM.getSystemFunctionLibrary();
    FunctionDescriptor fd = library.findFunction(FunctionLibrary.CONVERT, new Class[] { srcType, DataTypeManager.DefaultDataClasses.STRING });
    Function conversion = new Function(fd.getName(), new Expression[] { expression, new Constant(tgtTypeName) });
    conversion.setType(DataTypeManager.getDataTypeClass(tgtTypeName));
    conversion.setFunctionDescriptor(fd);
    conversion.makeImplicit();
    // Expected criteria
    CompareCriteria expected = new CompareCriteria();
    expected.setLeftExpression(conversion);
    expected.setOperator(CompareCriteria.EQ);
    expected.setRightExpression(e1);
    // Resolve the query and check against expected objects
    // $NON-NLS-1$
    CompareCriteria actual = (CompareCriteria) helpResolveCriteria("'2003-02-27'=pm3.g1.e2");
    // if (! actual.getLeftExpression().equals(expected.getLeftExpression())) {
    // fail("Left expressions not equal");
    // } else if (!actual.getRightExpression().equals(expected.getRightExpression())) {
    // fail("Right expressions not equal");
    // }
    // $NON-NLS-1$
    assertEquals("Did not match expected criteria", expected, actual);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Function(org.teiid.query.sql.symbol.Function) Expression(org.teiid.query.sql.symbol.Expression) Constant(org.teiid.query.sql.symbol.Constant) FunctionLibrary(org.teiid.query.function.FunctionLibrary) FunctionDescriptor(org.teiid.query.function.FunctionDescriptor) 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