public AssignmentStatement(ElementSymbol variable, QueryCommand value) { this.variable = variable; this.value = new ScalarSubquery(value); }
public AssignmentStatement(ElementSymbol variable, QueryCommand value) { this.variable = variable; this.value = new ScalarSubquery(value); }
public AssignmentStatement(ElementSymbol variable, QueryCommand value) { this.variable = variable; this.value = new ScalarSubquery(value); }
@Deprecated public AssignmentStatement(ElementSymbol variable, Command value) { this.variable = variable; if (value instanceof QueryCommand) { this.value = new ScalarSubquery((QueryCommand)value); } else { this.command = value; } }
@Deprecated public AssignmentStatement(ElementSymbol variable, Command value) { this.variable = variable; if (value instanceof QueryCommand) { this.value = new ScalarSubquery((QueryCommand)value); } else { this.command = value; } }
@Deprecated public AssignmentStatement(ElementSymbol variable, Command value) { this.variable = variable; if (value instanceof QueryCommand) { this.value = new ScalarSubquery((QueryCommand)value); } else { this.command = value; } }
@Test public void testDeclareStatementWithAssignment1() throws Exception { ElementSymbol a = new ElementSymbol("a"); //$NON-NLS-1$ String type = new String("string"); //$NON-NLS-1$ DeclareStatement stmt = new DeclareStatement(a, type, new ScalarSubquery(sampleQuery())); helpStmtTest("DECLARE string a = SELECT a1 FROM g WHERE a2 = 5;","DECLARE string a = (SELECT a1 FROM g WHERE a2 = 5);", stmt); //$NON-NLS-1$ //$NON-NLS-2$ }
/** * Returns a safe clone * @see java.lang.Object#clone() */ public Object clone() { QueryCommand copyCommand = null; if(getCommand() != null) { copyCommand = (QueryCommand) getCommand().clone(); } ScalarSubquery clone = new ScalarSubquery(copyCommand); //Don't invoke the lazy-loading getType() clone.setType(this.type); clone.shouldEvaluate = this.shouldEvaluate; if (this.subqueryHint != null) { clone.subqueryHint = subqueryHint.clone(); } return clone; }
@Test public void testScalarSubquery() throws Exception{ ScalarSubquery expr = new ScalarSubquery(new Query()); ArrayList values = new ArrayList(1); values.add("a"); //$NON-NLS-1$ Object expected = "a"; //$NON-NLS-1$ helpTestWithValueIterator(expr, values, expected); }
/** * Returns a safe clone * @see java.lang.Object#clone() */ public Object clone() { QueryCommand copyCommand = null; if(getCommand() != null) { copyCommand = (QueryCommand) getCommand().clone(); } ScalarSubquery clone = new ScalarSubquery(copyCommand); //Don't invoke the lazy-loading getType() clone.setType(this.type); clone.shouldEvaluate = this.shouldEvaluate; if (this.subqueryHint != null) { clone.subqueryHint = subqueryHint.clone(); } return clone; }
/** * Returns a safe clone * @see java.lang.Object#clone() */ public Object clone() { QueryCommand copyCommand = null; if(getCommand() != null) { copyCommand = (QueryCommand) getCommand().clone(); } ScalarSubquery clone = new ScalarSubquery(copyCommand); //Don't invoke the lazy-loading getType() clone.setType(this.type); clone.shouldEvaluate = this.shouldEvaluate; if (this.subqueryHint != null) { clone.subqueryHint = subqueryHint.clone(); } return clone; }
@Override public void visit(UriResourcePrimitiveProperty info) { if (this.root) { this.stack.add(new ScalarSubquery(buildRootSubQuery(info.getProperty().getName(), this.ctxExpression))); root = false; } else { this.stack.add(new ElementSymbol(info.getProperty().getName(), this.ctxExpression.getGroupSymbol())); } // hack to resolve the property type. Column c = this.ctxExpression.getColumnByName(info.getProperty().getName()); this.lastProperty = c; //revert back to the query context this.ctxExpression = this.ctxQuery; }
@Test public void testScalarSubquery2() throws Exception{ ScalarSubquery expr = new ScalarSubquery(new Query()); ArrayList values = new ArrayList(1); values.add(null); helpTestWithValueIterator(expr, values, null); }
@Test public void testScalarSubquery3() throws Exception{ ScalarSubquery expr = new ScalarSubquery(new Query()); helpTestWithValueIterator(expr, Collections.emptyList(), null); }
public static org.teiid.query.sql.symbol.ScalarSubquery helpExample() { Query query = TestQueryImpl.helpExample(true); org.teiid.query.sql.symbol.ScalarSubquery ss = new org.teiid.query.sql.symbol.ScalarSubquery(query); ss.setType(((Expression)query.getProjectedSymbols().get(0)).getType()); return ss; }
@Test public void testScalarSubqueryFails() throws Exception{ ScalarSubquery expr = new ScalarSubquery((QueryCommand) QueryParser.getQueryParser().parseCommand("select x from y")); ArrayList values = new ArrayList(2); values.add("a"); //$NON-NLS-1$ values.add("b"); //$NON-NLS-1$ try { helpTestWithValueIterator(expr, values, null); fail("Expected ExpressionEvaluationException but got none"); //$NON-NLS-1$ } catch (ExpressionEvaluationException e) { assertEquals("TEIID30328 Unable to evaluate (SELECT x FROM y): TEIID30345 The command of this scalar subquery returned more than one value: SELECT x FROM y", e.getMessage()); //$NON-NLS-1$ } }
@Override public void visit(UriResourceNavigation info) { try { DocumentNode navigationResource = DocumentNode.build( (EdmEntityType) info.getType(), info.getKeyPredicates(), this.metadata, this.odata, this.nameGenerator, true, getUriInfo(), this.parseService); Query query = new Query(); query.setSelect(new Select(Arrays.asList(new AggregateSymbol(AggregateSymbol.Type.COUNT.name(), false, null)))); query.setFrom(new From(Arrays.asList(navigationResource.getFromClause()))); Criteria criteria = this.ctxQuery.buildJoinCriteria(navigationResource, info.getProperty()); if (criteria == null) { throw new TeiidException(ODataPlugin.Event.TEIID16037, ODataPlugin.Util.gs(ODataPlugin.Event.TEIID16037)); } query.setCriteria(criteria); this.stack.add(new ScalarSubquery(query)); } catch (TeiidException e) { throw new TeiidRuntimeException(e); } }
private void buildAggregateQuery(DocumentNode node, Query outerQuery, ExpandDocumentNode expandResource, OrderBy expandOrder, Query query, EdmNavigationProperty navigationProperty) throws TeiidException { Select select = query.getSelect(); Array array = new Array(Object.class, new ArrayList<Expression>(select.getSymbols())); select.getSymbols().clear(); AggregateSymbol symbol = new AggregateSymbol(AggregateSymbol.Type.ARRAY_AGG.name(), false, array); select.addSymbol(symbol); symbol.setOrderBy(expandOrder); Criteria crit = node.buildJoinCriteria(expandResource, navigationProperty); if (crit != null) { query.setCriteria(Criteria.combineCriteria(crit, query.getCriteria())); } // else assertion error? expandResource.setColumnIndex(outerQuery.getSelect().getCount() + 1); ScalarSubquery agg = new ScalarSubquery(query); SubqueryHint subqueryHint = new SubqueryHint(); subqueryHint.setMergeJoin(true); agg.setSubqueryHint(subqueryHint); outerQuery.getSelect().addSymbol(agg); }
@Test public void testScalarSubquery() { Select s1 = new Select(); s1.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$ From f1 = new From(); f1.addGroup(new GroupSymbol("m.g1")); //$NON-NLS-1$ Query q1 = new Query(); q1.setSelect(s1); q1.setFrom(f1); ScalarSubquery obj = new ScalarSubquery(q1); helpTest(obj, "(SELECT e1 FROM m.g1)"); //$NON-NLS-1$ }
@Test public void testScalarSubqueryWithHint() { Select s1 = new Select(); s1.addSymbol(new ElementSymbol("e1")); //$NON-NLS-1$ From f1 = new From(); f1.addGroup(new GroupSymbol("m.g1")); //$NON-NLS-1$ Query q1 = new Query(); q1.setSelect(s1); q1.setFrom(f1); ScalarSubquery obj = new ScalarSubquery(q1); SubqueryHint subqueryHint = new SubqueryHint(); subqueryHint.setMergeJoin(true); obj.setSubqueryHint(subqueryHint); helpTest(obj, " /*+ MJ */ (SELECT e1 FROM m.g1)"); //$NON-NLS-1$ }