本文整理了Java中org.teiid.query.sql.lang.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:org.teiid.query.sql.lang.Query
类名称:Query
[英]A representation of a data query. A query consists of various parts, referred to as clauses. The following list the types of clauses that a query can hold, and their purpose:
CLAUSE PURPOSE
========= ==============================================
Select Defines the variables data to be retrieved for
From Defines the groups to retrieve data from
Criteria Defines constraints on data retrieval ("where")
GroupBy Defines how rows being returned should be grouped
Having Defines how groups should be filtered, also a criteria
OrderBy Defines how the results should be sorted
Option Defines any extra options on the query
[中]数据查询的一种表示形式。查询由多个部分组成,称为子句。下面列出了查询可以包含的子句类型及其用途:
CLAUSE PURPOSE
========= ==============================================
Select Defines the variables data to be retrieved for
From Defines the groups to retrieve data from
Criteria Defines constraints on data retrieval ("where")
GroupBy Defines how rows being returned should be grouped
Having Defines how groups should be filtered, also a criteria
OrderBy Defines how the results should be sorted
Option Defines any extra options on the query
代码示例来源:origin: org.teiid/teiid-olingo
private Query buildSubquery(DocumentNode eResource,
org.teiid.query.sql.symbol.Expression projected) {
Select s1 = new Select();
s1.addSymbol(projected);
Query q = new Query();
From from = new From();
from.addGroup(eResource.getGroupSymbol());
q.setFrom(from);
q.setCriteria(DocumentNode.buildJoinCriteria(eResource, this.ctxQuery));
q.setSelect(s1);
return q;
}
代码示例来源:origin: org.teiid/teiid-engine
public void visit(Query obj) {
preVisitVisitor(obj);
visitNodes(obj.getWith());
visitNode(obj.getSelect());
visitNode(obj.getInto());
visitNode(obj.getFrom());
visitNode(obj.getCriteria());
visitNode(obj.getGroupBy());
visitNode(obj.getHaving());
visitNode(obj.getOrderBy());
visitNode(obj.getLimit());
visitNode(obj.getOption());
postVisitVisitor(obj);
}
public void visit(RaiseStatement obj) {
代码示例来源:origin: org.teiid/teiid-engine
/**
* Constructs an instance of this class given all the clauses
* @param select SELECT clause
* @param from FROM clause
* @param criteria WHERE clause
* @param groupBy GROUP BY clause
* @param having HAVING clause
* @param orderBy ORDER BY clause
* @param option OPTION clause
*/
public Query( Select select, From from, Criteria criteria, GroupBy groupBy, Criteria having, OrderBy orderBy, Option option ) {
super();
setSelect( select );
setFrom( from );
setCriteria( criteria );
setGroupBy( groupBy );
setHaving( having );
setOrderBy( orderBy );
setOption( option );
}
代码示例来源:origin: org.teiid/teiid-engine
/**
* Constructs an instance of this class given the specified clauses
* @param select SELECT clause
* @param from FROM clause
* @param criteria WHERE clause
* @param orderBy ORDER BY clause
* @param option OPTION clause
*/
public Query( Select select, From from, Criteria criteria, OrderBy orderBy, Option option ) {
super();
setSelect( select );
setFrom( from );
setCriteria( criteria );
setOrderBy( orderBy );
setOption( option );
}
代码示例来源:origin: org.jboss.teiid/teiid-engine
public boolean hasAggregates() {
return getGroupBy() != null
|| getHaving() != null
|| !AggregateSymbolCollectorVisitor.getAggregates(getSelect(), false).isEmpty();
}
代码示例来源:origin: teiid/teiid
@Test public void testQuery4() {
Select select = new Select();
select.addSymbol(new MultipleElementSymbol());
From from = new From();
from.addGroup(new GroupSymbol("m.g")); //$NON-NLS-1$
CompareCriteria cc = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.EQ, new Constant(new Integer(5))); //$NON-NLS-1$
CompareCriteria having = new CompareCriteria(new ElementSymbol("e1"), CompareCriteria.GT, new Constant(new Integer(0))); //$NON-NLS-1$
OrderBy orderBy = new OrderBy();
orderBy.addVariable(new ElementSymbol("e1")); //$NON-NLS-1$
Query query = new Query();
query.setSelect(select);
query.setFrom(from);
query.setCriteria(cc);
query.setHaving(having);
query.setOrderBy(orderBy);
helpTest(query, "SELECT * FROM m.g WHERE e1 = 5 HAVING e1 > 0 ORDER BY e1"); //$NON-NLS-1$
}
代码示例来源:origin: teiid/teiid
@Test public void testLimitWithOffset() {
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 Constant(new Integer(50)), new Constant(new Integer(100))));
helpTest(query, "SELECT * FROM a LIMIT 50, 100"); //$NON-NLS-1$
}
代码示例来源:origin: org.teiid/teiid-engine
public static Query createMatViewQuery(Object matMetadataId, String matTableName, List<? extends Expression> select, boolean isGlobal) {
Query query = new Query();
query.setSelect(new Select(select));
GroupSymbol gs = new GroupSymbol(matTableName);
gs.setGlobalTable(isGlobal);
gs.setMetadataID(matMetadataId);
query.setFrom(new From(Arrays.asList(new UnaryFromClause(gs))));
return query;
}
代码示例来源:origin: teiid/teiid
@Test public void testCacheMultipleComments() {
String sql = "/* hello */ /*+ cache */ /* world */ SELECT * FROM t1"; //$NON-NLS-1$
Query query = new Query();
Select select = new Select();
select.addSymbol(new MultipleElementSymbol());
query.setSelect(select);
From from = new From();
UnaryFromClause ufc = new UnaryFromClause();
from.addClause(ufc);
ufc.setGroup(new GroupSymbol("t1")); //$NON-NLS-1$
query.setFrom(from);
query.setCacheHint(new CacheHint());
TestParser.helpTest(sql, "/*+ cache */ SELECT * FROM t1", query); //$NON-NLS-1$
}
代码示例来源:origin: teiid/teiid
/** SELECT y FROM h ORDER BY x */
public static final Query sample1() {
Query q2 = new Query();
Select select = new Select();
select.addSymbol(new ElementSymbol("y")); //$NON-NLS-1$
q2.setSelect(select);
From from = new From();
from.addGroup(new GroupSymbol("h")); //$NON-NLS-1$
q2.setFrom(from);
OrderBy orderBy = new OrderBy();
orderBy.addVariable(new ElementSymbol("x")); //$NON-NLS-1$
q2.setOrderBy(orderBy);
return q2;
}
代码示例来源:origin: org.jboss.teiid/teiid-engine
private boolean canRaiseInputset(Command command, Collection<ElementSymbol> bindings) {
// check to see if this is query.
if (!(command instanceof Query)) {
return false;
}
Query query = (Query)command;
Criteria crit = query.getCriteria();
if (crit != null && (query.getGroupBy() != null || query.getHaving() != null || query.getLimit() != null)) {
return false;
}
//temporarily remove the criteria
query.setCriteria(null);
//just throw away order by
query.setOrderBy(null);
List<ElementSymbol> references = QueryUtil.getBindingsReferences(query, bindings);
query.setCriteria(crit);
//if there are any input set bindings in the rest of the command, don't convert
return references.isEmpty();
}
代码示例来源:origin: org.teiid/teiid-engine
public static Query rowConstructor(List<Expression> select) {
Query query = new Query();
query.setSelect(new Select());
query.getSelect().addSymbols(select);
query.setRowConstructor(true);
return query;
}
代码示例来源:origin: org.jboss.teiid/teiid-engine
private Query rewriteGroupBy(Query query) throws TeiidComponentException, TeiidProcessingException {
if (query.getGroupBy() == null) {
rewriteAggs = false;
return query;
}
if (isDistinctWithGroupBy(query)) {
query.getSelect().setDistinct(false);
}
rewriteExpressions(query.getGroupBy());
List<Expression> expr = query.getGroupBy().getSymbols();
for (Iterator<Expression> iter = expr.iterator(); iter.hasNext();) {
if (EvaluatableVisitor.willBecomeConstant(iter.next())) {
iter.remove();
}
}
if (expr.isEmpty()) {
query.setGroupBy(null);
}
return query;
}
代码示例来源:origin: org.teiid/teiid-engine
public TupleSource processQuery(Query query, final VDBMetaData vdb, final TransformationMetadata metadata, final CommandContext cc) throws QueryMetadataException, TeiidComponentException {
return new ExtractionTupleSource(query.getCriteria(), createIterator(vdb, metadata, cc), cc, vdb, metadata, this);
}
代码示例来源:origin: org.teiid/teiid-olingo
public Query selectQuery() throws TeiidException {
if (!this.exceptions.isEmpty()) {
throw this.exceptions.get(0);
}
Query query = this.context.buildQuery();
if (this.countQuery) {
AggregateSymbol aggregateSymbol = new AggregateSymbol(AggregateSymbol.Type.COUNT.name(), false, null);
Select select = new Select(Arrays.asList(aggregateSymbol));
query.setSelect(select);
} else if (this.orderBy != null) {
if (this.context.getIterator() != null) {
//currently this doesn't matter as the ordering can only be based upon the parent entity
((AggregateSymbol)((AliasSymbol)query.getSelect().getSymbol(query.getSelect().getProjectedSymbols().size() - 1)).getSymbol()).setOrderBy(this.orderBy);
} else {
query.setOrderBy(this.orderBy);
}
}
if (this.expandOption != null) {
processExpandOption(this.expandOption, this.context, query, 1, null);
}
return query;
}
代码示例来源:origin: org.jboss.teiid/teiid-engine
/**
* Validates SELECT INTO queries.
* @param query
* @since 4.2
*/
protected void validateSelectInto(Query query) {
List<Expression> symbols = query.getSelect().getProjectedSymbols();
GroupSymbol intoGroup = query.getInto().getGroup();
validateInto(query, symbols, intoGroup);
}
代码示例来源:origin: org.jboss.teiid/teiid-engine
@Override
protected TupleSource createTupleSource()
throws TeiidComponentException, TeiidProcessingException {
TempTableStore tts = contextStore;
TempTable tt = tts.getOrCreateTempTable(tableName, query, bufferManager, true, false, context, group);
if (context.getDataObjects() != null) {
Object id = RelationalPlanner.getTrackableGroup(group, context.getMetadata());
if (id != null) {
context.accessedDataObject(id);
}
}
return tt.createTupleSource(query.getProjectedSymbols(), query.getCriteria(), query.getOrderBy());
}
};
代码示例来源:origin: org.jboss.teiid/teiid-engine
private void correctProjectedTypes(List actualSymbolTypes, Query query) {
List symbols = query.getSelect().getProjectedSymbols();
List newSymbols = SetQuery.getTypedProjectedSymbols(symbols, actualSymbolTypes, this.metadata);
query.getSelect().setSymbols(newSymbols);
}
代码示例来源:origin: teiid/teiid
public void testHasNoCriteria2() {
Query query = new Query();
CompareCriteria crit = new CompareCriteria(new Constant("a"), CompareCriteria.EQ, new Constant("b")); //$NON-NLS-1$ //$NON-NLS-2$
query.setCriteria(crit);
assertEquals("Got incorrect answer checking for no criteria", false, RuleValidateWhereAll.hasNoCriteria(query)); //$NON-NLS-1$
}
代码示例来源:origin: teiid/teiid
@Test public void testElementSymbolForms() {
String sql = "SELECT pm1.g1.e1, e2, pm1.g1.e3 AS a, e4 AS b FROM pm1.g1"; //$NON-NLS-1$
Query resolvedQuery = (Query) helpResolve(sql);
helpCheckFrom(resolvedQuery, new String[] { "pm1.g1" }); //$NON-NLS-1$
helpCheckSelect(resolvedQuery, new String[] { "pm1.g1.e1", "pm1.g1.e2", "a", "b" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
helpCheckElements(resolvedQuery.getSelect(),
new String[] { "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4" }, //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
new String[] { "pm1.g1.e1", "pm1.g1.e2", "pm1.g1.e3", "pm1.g1.e4" } ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
assertEquals("Resolved string form was incorrect ", sql, resolvedQuery.toString()); //$NON-NLS-1$
}
内容来源于网络,如有侵权,请联系作者删除!