private List<Constant> convertValuesToConstants(List<?> values, List<ElementSymbol> elements) { ArrayList<Constant> constants = new ArrayList<Constant>(values.size()); for(int i=0; i<elements.size(); i++) { ElementSymbol es = elements.get(i); Class<?> type = es.getType(); constants.add(new Constant(values.get(i),type)); } return constants; }
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; }
@Override public void visit(UriResourceLambdaAll all) { accept(all.getExpression()); if (this.ctxLambda != null) { org.teiid.query.sql.symbol.Expression predicate = this.stack.pop(); predicate = new SubqueryCompareCriteria(new Constant(true), buildSubquery( this.ctxLambda, predicate), CompareCriteria.EQ, SubqueryCompareCriteria.ALL); this.stack.push(predicate); } this.ctxLambda = null; }
/** * Return a shallow copy of this object - value is NOT cloned! * @return Shallow copy of object */ public Object clone() { Constant copy = new Constant(getValue(), getType()); copy.multiValued = multiValued; copy.bindEligible = bindEligible; return copy; }
/** * Return a shallow copy of this object - value is NOT cloned! * @return Shallow copy of object */ public Object clone() { Constant copy = new Constant(getValue(), getType()); copy.multiValued = multiValued; copy.bindEligible = bindEligible; return copy; }
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); }
@Test public void testLOBTypes() throws Exception { Function convert = new Function("convert", new Expression[] {new Constant(null), new Constant("blob")}); //$NON-NLS-1$ //$NON-NLS-2$ Function convert1 = new Function("convert", new Expression[] {new Constant(null), new Constant("clob")}); //$NON-NLS-1$ //$NON-NLS-2$ Function convert2 = new Function("convert", new Expression[] {new Constant(null), new Constant("xml")}); //$NON-NLS-1$ //$NON-NLS-2$ Select select = new Select(Arrays.asList(convert, convert1, convert2)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ Query query = new Query(); query.setSelect(select); helpTest("select convert(null, blob), convert(null, clob), convert(null, xml)", "SELECT convert(null, blob), convert(null, clob), convert(null, xml)", query); //$NON-NLS-1$ //$NON-NLS-2$ }
public static AggregateFunction example(String functionName, boolean distinct, int value) throws Exception { AggregateSymbol symbol = new AggregateSymbol(functionName, distinct, new Constant(new Integer(value))); return TstLanguageBridgeFactory.factory.translate(symbol); }
/** * Supports functions in group by is misleading. It should actually * be called supports expression in group by. Thus the example below * is not supported. */ @Test public void testSupportsFunctionInGroupBy() throws Exception { Function f = new Function("concat", new Expression[] { new Constant("a"), new Constant("b") }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ExpressionSymbol expr = new ExpressionSymbol("e", f); //$NON-NLS-1$ List cols = new ArrayList(); cols.add(expr); helpTestSupportsAggregates(false, false, cols); }
@Test public void testArrayParsing() throws Exception { TestParser.helpTestExpression("()", "()", new Array(new ArrayList<Expression>())); TestParser.helpTestExpression("(,)", "()", new Array(new ArrayList<Expression>())); TestParser.helpTestExpression("(1,)", "(1,)", new Array(Arrays.asList((Expression)new Constant(1)))); TestParser.helpTestExpression("(1,2)", "(1, 2)", new Array(Arrays.asList((Expression)new Constant(1), (Expression)new Constant(2)))); TestParser.helpTestExpression("(1,2,)", "(1, 2)", new Array(Arrays.asList((Expression)new Constant(1), (Expression)new Constant(2)))); }
private static Expression evaluateIfPossible(Expression newExpr) { if (EvaluatableVisitor.isFullyEvaluatable(newExpr, true)) { try { return new Constant(Evaluator.evaluate(newExpr), newExpr.getType()); } catch (TeiidException e) { throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30269, e, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30269)); } } return newExpr; }
private void appendDefault(BaseColumn column) { if (column.getDefaultValue() != null) { append(SPACE).append(DEFAULT).append(SPACE); if (BaseColumn.EXPRESSION_DEFAULT.equalsIgnoreCase(column.getProperty(BaseColumn.DEFAULT_HANDLING, false))) { append(column.getDefaultValue()); } else { append(new Constant(column.getDefaultValue())); } } }
private void appendDefault(BaseColumn column) { if (column.getDefaultValue() != null) { append(SPACE).append(DEFAULT).append(SPACE); if (BaseColumn.EXPRESSION_DEFAULT.equalsIgnoreCase(column.getProperty(BaseColumn.DEFAULT_HANDLING, false))) { append(column.getDefaultValue()); } else { append(new Constant(column.getDefaultValue())); } } }
@Test public void testLimit() { Query query = new Query(); Select select = new Select(Arrays.asList(new MultipleElementSymbol())); From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$ query.setSelect(select); query.setFrom(from); query.setLimit(new Limit(null, new Constant(new Integer(100)))); helpTest("Select * from a limit 100", "SELECT * FROM a LIMIT 100", query); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testLimitWithReferences1() { Query query = new Query(); Select select = new Select(Arrays.asList(new MultipleElementSymbol())); From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$ query.setSelect(select); query.setFrom(from); query.setLimit(new Limit(new Reference(0), new Constant(new Integer(100)))); helpTest("Select * from a limit ?,100", "SELECT * FROM a LIMIT ?, 100", query); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testErrorStatement() throws Exception { ExceptionExpression ee = new ExceptionExpression(); ee.setMessage(new Constant("Test only")); RaiseStatement errStmt = new RaiseStatement(ee); helpStmtTest("ERROR 'Test only';", "RAISE SQLEXCEPTION 'Test only';", //$NON-NLS-1$ //$NON-NLS-2$ errStmt); }
@Test public void testFetchFirstRow() { Query query = new Query(); Select select = new Select(Arrays.asList(new MultipleElementSymbol())); From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a")))); //$NON-NLS-1$ query.setSelect(select); query.setFrom(from); query.setLimit(new Limit(null, new Constant(1))); helpTest("Select * from a fetch first row only", "SELECT * FROM a LIMIT 1", query); //$NON-NLS-1$ //$NON-NLS-2$ }
@Test public void testStoredQuery2SanityCheck(){ StoredProcedure storedQuery = new StoredProcedure(); storedQuery.setProcedureName("proc1"); //$NON-NLS-1$ SPParameter parameter = new SPParameter(1, new Constant("param1")); //$NON-NLS-1$ storedQuery.setParameter(parameter); From from = new From(); SubqueryFromClause sfc = new SubqueryFromClause("x", storedQuery); //$NON-NLS-1$ from.addClause(sfc); Select select = new Select(); select.addSymbol(new ElementSymbol("x.a")); //$NON-NLS-1$ helpTest("exec proc1('param1')", "EXEC proc1('param1')", 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 testNationCharString() throws Exception { Query query = (Query) QueryParser.getQueryParser().parseCommand("SELECT N'blah' FROM m.g"); //$NON-NLS-1$ Select select = query.getSelect(); Constant c = (Constant) SymbolMap.getExpression(select.getSymbol(0)); assertEquals(c, new Constant("blah")); //$NON-NLS-1$ }