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);
}
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());
}
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);
}
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);
}
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);
}
Aggregations