use of org.teiid.query.sql.lang.Limit in project teiid by teiid.
the class TestSetQueryParsing method testUnionWithLimit.
@Test
public void testUnionWithLimit() {
SetQuery setQuery = exampleSetQuery(Operation.UNION);
setQuery.setLimit(new Limit(null, new Constant(1)));
// $NON-NLS-1$
TestParser.helpTest(// $NON-NLS-1$
"SELECT a FROM g UNION select b from h LIMIT 1", // $NON-NLS-1$
"SELECT a FROM g UNION SELECT b FROM h LIMIT 1", setQuery);
}
use of org.teiid.query.sql.lang.Limit in project teiid by teiid.
the class Request method generatePlan.
/**
* state side effects:
* creates the analysis record
* creates the command context
* sets the pre-rewrite command on the request
* adds a limit clause if the row limit is specified
* sets the processor plan
*
* @throws TeiidComponentException
* @throws TeiidProcessingException
*/
protected void generatePlan(boolean prepared) throws TeiidComponentException, TeiidProcessingException {
createCommandContext();
Command command = parseCommand();
List<Reference> references = ReferenceCollectorVisitor.getReferences(command);
getAnalysisRecord();
resolveCommand(command);
checkReferences(references);
validateAccess(requestMsg.getCommands(), command, CommandType.USER);
this.userCommand = (Command) command.clone();
Collection<GroupSymbol> groups = GroupCollectorVisitor.getGroups(command, true);
for (GroupSymbol groupSymbol : groups) {
if (groupSymbol.isTempTable()) {
this.context.setDeterminismLevel(Determinism.SESSION_DETERMINISTIC);
break;
}
}
validateQuery(command);
command = QueryRewriter.rewrite(command, metadata, context);
/*
* Adds a row limit to a query if Statement.setMaxRows has been called and the command
* doesn't already have a limit clause.
*/
if (!prepared && requestMsg.getRowLimit() > 0 && command instanceof QueryCommand) {
QueryCommand query = (QueryCommand) command;
if (query.getLimit() == null) {
query.setLimit(new Limit(null, new Constant(new Integer(requestMsg.getRowLimit()), DataTypeManager.DefaultDataClasses.INTEGER)));
this.addedLimit = true;
}
}
boolean debug = analysisRecord.recordDebug();
if (debug) {
// $NON-NLS-1$
analysisRecord.println("\n============================================================================");
// $NON-NLS-1$
analysisRecord.println("USER COMMAND:\n" + command);
}
// Run the optimizer
try {
CommandContext.pushThreadLocalContext(context);
processPlan = QueryOptimizer.optimizePlan(command, metadata, idGenerator, capabilitiesFinder, analysisRecord, context);
} finally {
CommandContext.popThreadLocalContext();
String debugLog = analysisRecord.getDebugLog();
if (debugLog != null && debugLog.length() > 0) {
LogManager.log(requestMsg.getShowPlan() == ShowPlan.DEBUG ? MessageLevel.INFO : MessageLevel.TRACE, LogConstants.CTX_QUERY_PLANNER, debugLog);
}
if (analysisRecord.recordAnnotations() && analysisRecord.getAnnotations() != null && !analysisRecord.getAnnotations().isEmpty()) {
LogManager.logDetail(LogConstants.CTX_QUERY_PLANNER, analysisRecord.getAnnotations());
}
}
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_DQP, new Object[] { QueryPlugin.Util.getString("BasicInterceptor.ProcessTree_for__4"), requestId, processPlan });
}
use of org.teiid.query.sql.lang.Limit in project teiid by teiid.
the class TestLimitParsing method testSetQueryLimit.
@Test
public void testSetQueryLimit() {
Query query = new Query();
Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
// $NON-NLS-1$
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a"))));
query.setSelect(select);
query.setFrom(from);
SetQuery setQuery = new SetQuery(Operation.UNION, true, query, query);
setQuery.setLimit(new Limit(new Reference(0), new Reference(1)));
// $NON-NLS-1$ //$NON-NLS-2$
helpTest("Select * from a union all Select * from a limit ?,?", "SELECT * FROM a UNION ALL SELECT * FROM a LIMIT ?, ?", setQuery);
}
use of org.teiid.query.sql.lang.Limit in project teiid by teiid.
the class TestLimitParsing method testLimit.
@Test
public void testLimit() {
Query query = new Query();
Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
// $NON-NLS-1$
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a"))));
query.setSelect(select);
query.setFrom(from);
query.setLimit(new Limit(null, new Constant(new Integer(100))));
// $NON-NLS-1$ //$NON-NLS-2$
helpTest("Select * from a limit 100", "SELECT * FROM a LIMIT 100", query);
}
use of org.teiid.query.sql.lang.Limit in project teiid by teiid.
the class TestLimitParsing method testOffset.
@Test
public void testOffset() {
Query query = new Query();
Select select = new Select(Arrays.asList(new MultipleElementSymbol()));
// $NON-NLS-1$
From from = new From(Arrays.asList(new UnaryFromClause(new GroupSymbol("a"))));
query.setSelect(select);
query.setFrom(from);
query.setLimit(new Limit(new Reference(0), null));
// $NON-NLS-1$ //$NON-NLS-2$
helpTest("Select * from a offset ? rows", "SELECT * FROM a OFFSET ? ROWS", query);
}
Aggregations