use of org.teiid.language.Comparison in project teiid by teiid.
the class TestCompareCriteriaImpl method testGetRightExpression.
public void testGetRightExpression() throws Exception {
Comparison impl = example(AbstractCompareCriteria.GE, 200, 100);
assertNotNull(impl.getRightExpression());
assertTrue(impl.getRightExpression() instanceof Literal);
assertEquals(new Integer(100), ((Literal) impl.getRightExpression()).getValue());
}
use of org.teiid.language.Comparison in project teiid by teiid.
the class TestJoinImpl method testGetCriteria.
public void testGetCriteria() throws Exception {
Join join = example(JoinType.JOIN_INNER);
assertTrue(join.getCondition() instanceof Comparison);
}
use of org.teiid.language.Comparison in project teiid by teiid.
the class SubstringFunctionModifier method translate.
@Override
public List<?> translate(Function function) {
this.modify(function);
if (function.getParameters().size() != 3) {
return null;
}
// case when length > LENGTH(string) - start + 1 then LENGTH(string) - start + 1 case when length > 0 then length end
Expression forLength = function.getParameters().get(2);
List<SearchedWhenClause> clauses = new ArrayList<SearchedWhenClause>(2);
Boolean isNegative = null;
if (forLength instanceof Literal) {
Literal l = (Literal) forLength;
int value = (Integer) l.getValue();
isNegative = value < 0;
}
Function length = new Function(SourceSystemFunctions.LENGTH, Arrays.asList(function.getParameters().get(0)), TypeFacility.RUNTIME_TYPES.INTEGER);
Expression from = function.getParameters().get(1);
SearchedCase adjustedFrom = new SearchedCase(Arrays.asList(new SearchedWhenClause(new Comparison(from, length, Operator.GT), new Function(SourceSystemFunctions.ADD_OP, Arrays.asList(length, new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER)), TypeFacility.RUNTIME_TYPES.INTEGER))), from, TypeFacility.RUNTIME_TYPES.INTEGER);
function.getParameters().set(1, adjustedFrom);
Expression maxLength = new Function(SourceSystemFunctions.SUBTRACT_OP, Arrays.asList(length, new Function(SourceSystemFunctions.SUBTRACT_OP, Arrays.asList(adjustedFrom, new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER)), TypeFacility.RUNTIME_TYPES.INTEGER)), TypeFacility.RUNTIME_TYPES.INTEGER);
clauses.add(new SearchedWhenClause(new Comparison(forLength, maxLength, Operator.GT), maxLength));
Expression defaultExpr = null;
if (isNegative == null) {
clauses.add(new SearchedWhenClause(new Comparison(forLength, new Literal(0, TypeFacility.RUNTIME_TYPES.INTEGER), Operator.GT), forLength));
} else if (isNegative) {
// TODO: could be done in the rewriter
return Arrays.asList(new Literal(null, TypeFacility.RUNTIME_TYPES.STRING));
} else {
defaultExpr = forLength;
}
SearchedCase sc = new SearchedCase(clauses, defaultExpr, TypeFacility.RUNTIME_TYPES.INTEGER);
function.getParameters().set(2, sc);
return null;
}
use of org.teiid.language.Comparison in project teiid by teiid.
the class TestDependentJoins method testBindings.
@Test
public void testBindings() throws Exception {
BasicSourceCapabilities caps = TestOptimizer.getTypicalCapabilities();
caps.setCapabilitySupport(Capability.DEPENDENT_JOIN_BINDINGS, true);
ProcessorPlan plan = // $NON-NLS-1$
TestOptimizer.helpPlan(// $NON-NLS-1$
"select pm1.g1.e1, pm1.g1.e2, pm2.g1.e2 FROM pm1.g1, /*+ makedep */ pm2.g1 where (pm1.g1.e1 = pm2.g1.e1)", // $NON-NLS-1$
TestOptimizer.example1(), new String[] { "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 ORDER BY c_0", "SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM pm2.g1 AS g_0 WHERE g_0.e1 IN (<dependent values>) ORDER BY c_0" }, new DefaultCapabilitiesFinder(caps), // $NON-NLS-1$ //$NON-NLS-2$
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
List<?>[] expected = new List<?>[] { // $NON-NLS-1$
Arrays.asList(new Object[] { "a", 1, 2 }) };
HardcodedDataManager dataManager = new HardcodedDataManager(RealMetadataFactory.example1Cached());
dataManager.addData("SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM g1 AS g_0 ORDER BY c_0", new List<?>[] { Arrays.asList("a", 1) });
dataManager.addData("SELECT g_0.e1 AS c_0, g_0.e2 AS c_1 FROM g1 AS g_0 WHERE g_0.e1 = 'a' ORDER BY c_0", new List<?>[] { Arrays.asList("a", 2) });
TestProcessor.helpProcess(plan, dataManager, expected);
Select select = (Select) dataManager.getPushdownCommands().get(1);
assertTrue(((Literal) ((Comparison) select.getWhere()).getRightExpression()).isBindEligible());
}
use of org.teiid.language.Comparison in project teiid by teiid.
the class TestCollectorVisitor method test2.
@Test
public void test2() {
// $NON-NLS-1$
NamedTable g1 = new NamedTable("g1", null, null);
// $NON-NLS-1$
ColumnReference e1 = new ColumnReference(g1, "e1", null, String.class);
// $NON-NLS-1$
ColumnReference e2 = new ColumnReference(g1, "e2", null, String.class);
Comparison cc = new Comparison(e1, e2, Operator.EQ);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
helpTestElementsUsedByGroups(cc, new String[] { "g1.e1", "g1.e2" }, new String[] { "g1" });
}
Aggregations