private void addEmptyFilter(Collection<AggregateSymbol> aggregates, PlanNode stageGroup, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, Object modelId) throws QueryMetadataException, TeiidComponentException { PlanNode selectNode = NodeFactory.getNewNode(NodeConstants.Types.SELECT); AggregateSymbol count = new AggregateSymbol(NonReserved.COUNT, false, null); aggregates.add(count); //consider the count aggregate for the push down call below Criteria crit = new CompareCriteria(count, CompareCriteria.GT, new Constant(new Integer(0))); selectNode.setProperty(NodeConstants.Info.SELECT_CRITERIA, crit); selectNode.setProperty(NodeConstants.Info.IS_HAVING, Boolean.TRUE); stageGroup.addAsParent(selectNode); }
private void addEmptyFilter(Collection<AggregateSymbol> aggregates, PlanNode stageGroup, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, Object modelId) throws QueryMetadataException, TeiidComponentException { PlanNode selectNode = NodeFactory.getNewNode(NodeConstants.Types.SELECT); AggregateSymbol count = new AggregateSymbol(NonReserved.COUNT, false, null); aggregates.add(count); //consider the count aggregate for the push down call below Criteria crit = new CompareCriteria(count, CompareCriteria.GT, new Constant(new Integer(0))); selectNode.setProperty(NodeConstants.Info.SELECT_CRITERIA, crit); selectNode.setProperty(NodeConstants.Info.IS_HAVING, Boolean.TRUE); stageGroup.addAsParent(selectNode); }
private org.teiid.query.sql.symbol.Expression addOne( org.teiid.query.sql.symbol.Expression expr) { org.teiid.query.sql.symbol.Expression when = new CompareCriteria(expr, CompareCriteria.LT, new Constant(0)); SearchedCaseExpression caseExpr = new SearchedCaseExpression(Arrays.asList(when), Arrays.asList(expr)); caseExpr.setElseExpression(new Function("+", new org.teiid.query.sql.symbol.Expression[] { expr, new Constant(1) })); return caseExpr; }
public static List getWhenCriteria(int criteria) { ArrayList list = new ArrayList(); ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$ for (int i = 0; i < criteria; i++) { list.add(new CompareCriteria(x, CompareCriteria.EQ, new Constant(new Integer(i)))); } return list; }
public static List getAlphaWhenCriteria(int criteria) { ArrayList list = new ArrayList(); ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$ for (int i = 0; i < criteria; i++) { list.add(new CompareCriteria(x, CompareCriteria.EQ, new Constant(String.valueOf((char)('a' + i))))); } return list; }
@Test public void testCompareCriteria7() { CompareCriteria cc = new CompareCriteria( null, CompareCriteria.EQ, null ); helpTest(cc, "<undefined> = <undefined>"); //$NON-NLS-1$ }
@Test public void testCompareCriteria2() { ElementSymbol e1 = new ElementSymbol("e1"); //$NON-NLS-1$ Function f = new Function("+", new Expression[] { new Constant(new Integer(2)), new Constant(new Integer(5)) }); //$NON-NLS-1$ Map<Expression, Expression> map = new HashMap<Expression, Expression>(); map.put(e1, f); CompareCriteria before = new CompareCriteria(new Constant("xyz"), CompareCriteria.EQ, e1); //$NON-NLS-1$ CompareCriteria after = new CompareCriteria(new Constant("xyz"), CompareCriteria.EQ, f); //$NON-NLS-1$ helpTest(before, map, after); }
@Test public void testCompareCriteria1() { ElementSymbol e1 = new ElementSymbol("e1"); //$NON-NLS-1$ Function f = new Function("+", new Expression[] { new Constant(new Integer(2)), new Constant(new Integer(5)) }); //$NON-NLS-1$ Map<Expression, Expression> map = new HashMap<Expression, Expression>(); map.put(e1, f); CompareCriteria before = new CompareCriteria(e1, CompareCriteria.EQ, new Constant("xyz")); //$NON-NLS-1$ CompareCriteria after = new CompareCriteria(f, CompareCriteria.EQ, new Constant("xyz")); //$NON-NLS-1$ helpTest(before, map, after); }
@Test public void testCompoundCriteria4() { CompareCriteria cc1 = new CompareCriteria( new ElementSymbol("m.g.c1"), //$NON-NLS-1$ CompareCriteria.EQ, new Constant("abc") ); //$NON-NLS-1$ List<Criteria> crits = new ArrayList<Criteria>(); crits.add(cc1); crits.add(null); CompoundCriteria comp = new CompoundCriteria(CompoundCriteria.OR, crits); helpTest(comp, "(m.g.c1 = 'abc') OR (<undefined>)"); //$NON-NLS-1$ }
@Test public void testCompoundCriteria5() { CompareCriteria cc1 = new CompareCriteria( new ElementSymbol("m.g.c1"), //$NON-NLS-1$ CompareCriteria.EQ, new Constant("abc") ); //$NON-NLS-1$ List<Criteria> crits = new ArrayList<Criteria>(); crits.add(null); crits.add(cc1); CompoundCriteria comp = new CompoundCriteria(CompoundCriteria.OR, crits); helpTest(comp, "(<undefined>) OR (m.g.c1 = 'abc')"); //$NON-NLS-1$ }
public static JoinPredicate helpExample(JoinType type) { ElementSymbol e1 = TestElementImpl.helpExample("vm1.g1", "e1"); //$NON-NLS-1$ //$NON-NLS-2$ ElementSymbol e2 = TestElementImpl.helpExample("vm1.g2", "e1"); //$NON-NLS-1$ //$NON-NLS-2$ ArrayList criteria = new ArrayList(); criteria.add(new CompareCriteria(e1, CompareCriteria.EQ, e2)); return new JoinPredicate(new UnaryFromClause(e1.getGroupSymbol()), new UnaryFromClause(e2.getGroupSymbol()), type, criteria); }
public void testClone2() { ElementSymbol e1 = new ElementSymbol("e1"); //$NON-NLS-1$ CompareCriteria ccrit1 = new CompareCriteria(e1, CompareCriteria.EQ, new Constant("abc")); //$NON-NLS-1$ CompoundCriteria comp = new CompoundCriteria(CompoundCriteria.AND, ccrit1, null); UnitTestUtil.helpTestEquivalence(0, comp, comp.clone()); }
@Test public void testCompareCriteria1() { CompareCriteria cc = new CompareCriteria( new ElementSymbol("m.g.c1"), //$NON-NLS-1$ CompareCriteria.EQ, new Constant("abc") ); //$NON-NLS-1$ helpTest(cc, "m.g.c1 = 'abc'"); //$NON-NLS-1$ }
@Test public void testCompareCriteria4() { CompareCriteria cc = new CompareCriteria( new ElementSymbol("m.g.c1"), //$NON-NLS-1$ CompareCriteria.GE, new Constant("abc") ); //$NON-NLS-1$ helpTest(cc, "m.g.c1 >= 'abc'"); //$NON-NLS-1$ }
@Test public void testCompareCriteria5() { CompareCriteria cc = new CompareCriteria( new ElementSymbol("m.g.c1"), //$NON-NLS-1$ CompareCriteria.LT, new Constant("abc") ); //$NON-NLS-1$ helpTest(cc, "m.g.c1 < 'abc'"); //$NON-NLS-1$ }
@Test public void testCase3281QuotedNamedVariableFails2() { StoredProcedure storedQuery = new StoredProcedure(); storedQuery.setProcedureName("proc1"); //$NON-NLS-1$ SPParameter param1 = new SPParameter(1, new CompareCriteria(new Constant("a"), CompareCriteria.EQ, new Constant("b"))); //$NON-NLS-1$ param1.setParameterType(ParameterInfo.IN); storedQuery.setParameter(param1); helpTest("Exec proc1('a' = 'b')", "EXEC proc1(('a' = 'b'))", storedQuery); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testUnionJoin() { String sql = "select * from pm1.g1 union join pm1.g2 where g1.e1 = 1"; //$NON-NLS-1$ String expected = "SELECT * FROM pm1.g1 UNION JOIN pm1.g2 WHERE g1.e1 = 1"; //$NON-NLS-1$ Select select = new Select(); select.addSymbol(new MultipleElementSymbol()); From from = new From(); from.addClause(new JoinPredicate(new UnaryFromClause(new GroupSymbol("pm1.g1")), new UnaryFromClause(new GroupSymbol("pm1.g2")), JoinType.JOIN_UNION)); //$NON-NLS-1$ //$NON-NLS-2$ Criteria crit = new CompareCriteria(new ElementSymbol("g1.e1"), CompareCriteria.EQ, new Constant(new Integer(1))); //$NON-NLS-1$ Query command = new Query(select, from, crit, null, null); helpTest(sql, expected, command); }
@Test public void testCriteria1() { CompareCriteria expected = new CompareCriteria(); ElementSymbol es = new ElementSymbol("pm1.g1.e1"); //$NON-NLS-1$ GroupSymbol gs = new GroupSymbol("pm1.g1"); //$NON-NLS-1$ es.setGroupSymbol(gs); expected.setLeftExpression(es); expected.setOperator(CompareCriteria.EQ); expected.setRightExpression(new Constant("abc")); //$NON-NLS-1$ Criteria actual = helpResolveCriteria("pm1.g1.e1 = 'abc'"); //$NON-NLS-1$ assertEquals("Did not match expected criteria", expected, actual); //$NON-NLS-1$ }
@Test public void testSetCriteria() throws Exception { DependentAccessNode dan = new DependentAccessNode(0); SetCriteria sc = new SetCriteria(new ElementSymbol("e1"), Arrays.asList(new Constant(1), new Constant(2))); //$NON-NLS-1$ sc.setAllConstants(true); DependentCriteriaProcessor dcp = new DependentCriteriaProcessor(1, -1, dan, sc); Criteria result = dcp.prepareCriteria(); assertEquals(new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(1)), result); //$NON-NLS-1$ assertTrue(dcp.hasNextCommand()); }
public void testVisitUpdate2() { Update update = new Update(); update.setGroup(exampleGroup(true, 0)); update.addChange(exampleElement(true, 0), new Constant("abc")); //$NON-NLS-1$ update.addChange(exampleElement(true, 1), new Constant("abc")); //$NON-NLS-1$ update.setCriteria(new CompareCriteria(exampleElement(true, 2), CompareCriteria.LT, new Constant("xyz"))); //$NON-NLS-1$ helpTest(update, getSymbolMap()); }