vvysotskyi commented on a change in pull request #1608: DRILL-6960: Auto Limit
Wrapping should not apply to non-select query
URL: https://github.com/apache/drill/pull/1608#discussion_r253866957
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
##########
@@ -183,4 +183,20 @@ private static PhysicalPlan getQueryPlan(QueryContext
context, String sql, Point
return handler.getPlan(sqlNode);
}
+
+ //Wrap with Auto Limit
+ private static SqlNode wrapWithAutoLimit(SqlConverter parser, QueryContext
context, String sql) {
+ SqlNode sqlNode = parser.parse(sql);
Review comment:
Please replace this code with the following to avoid parsing the query
several times.
```suggestion
SqlNode sqlNode = parser.parse(sql);
int fetch = context.getAutoLimitRowCount();
if (sqlNode.getKind().belongsTo(SqlKind.QUERY)) {
if (sqlNode.getKind() == SqlKind.ORDER_BY) {
// merge SqlOrderBy
SqlOrderBy orderBy = (SqlOrderBy) sqlNode;
if (orderBy.fetch != null) {
fetch = Math.min(Integer.valueOf(orderBy.fetch.toString()), fetch);
}
sqlNode = new SqlOrderBy(orderBy.getParserPosition(), orderBy.query,
orderBy.orderList, orderBy.offset,
SqlLiteral.createExactNumeric(Integer.toString(fetch),
SqlParserPos.ZERO));
} else {
sqlNode = new SqlOrderBy(SqlParserPos.ZERO, sqlNode,
SqlNodeList.EMPTY, null,
SqlLiteral.createExactNumeric(Integer.toString(fetch),
SqlParserPos.ZERO));
}
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services