JiajunBernoulli commented on a change in pull request #2679:
URL: https://github.com/apache/calcite/pull/2679#discussion_r806392978
##########
File path: core/src/test/java/org/apache/calcite/test/JdbcTest.java
##########
@@ -5898,17 +5965,32 @@ private void checkMapSchemaDirectConnection(String s)
throws SQLException {
+ "order by \"empid\" limit 2", null);
with
.query("select \"name\" from \"adhoc\".V order by \"name\"")
+ .withHook(Hook.SQL2REL_CONVERTER_CONFIG_BUILDER,
+ (Consumer<Holder<Config>>) configHolder ->
+
configHolder.set(configHolder.get().withRemoveSortInSubQuery(false)))
.returns("name=Bill\n"
+ "name=Theodore\n");
// Now a sub-query with ORDER BY and LIMIT clauses. (Same net effect, but
// ORDER BY and LIMIT in sub-query were not standard SQL until SQL:2008.)
+ with
+ .query("select \"name\" from (\n"
+ + "select * from \"adhoc\".\"EMPLOYEES\" where \"deptno\" = 10\n"
+ + "order by \"empid\" limit 2)\n"
+ + "order by \"name\"")
+ .withHook(Hook.SQL2REL_CONVERTER_CONFIG_BUILDER,
+ (Consumer<Holder<SqlToRelConverter.Config>>) configHolder ->
+
configHolder.set(configHolder.get().withRemoveSortInSubQuery(false)))
+ .returns("name=Bill\n"
+ + "name=Theodore\n");
+
with
.query("select \"name\" from (\n"
+ "select * from \"adhoc\".\"EMPLOYEES\" where \"deptno\" = 10\n"
+ "order by \"empid\" limit 2)\n"
+ "order by \"name\"")
.returns("name=Bill\n"
+ + "name=Sebastian\n"
+ "name=Theodore\n");
Review comment:
You are right, I modified the code to preserve the previous behavior.
##########
File path: core/src/test/java/org/apache/calcite/test/JdbcTest.java
##########
@@ -5898,17 +5965,32 @@ private void checkMapSchemaDirectConnection(String s)
throws SQLException {
+ "order by \"empid\" limit 2", null);
with
.query("select \"name\" from \"adhoc\".V order by \"name\"")
+ .withHook(Hook.SQL2REL_CONVERTER_CONFIG_BUILDER,
+ (Consumer<Holder<Config>>) configHolder ->
+
configHolder.set(configHolder.get().withRemoveSortInSubQuery(false)))
Review comment:
The new code doesn't need a hook.
##########
File path: core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
##########
@@ -683,6 +683,13 @@ protected void convertSelectImpl(
convertFrom(
bb,
select.getFrom());
+ if (RelOptUtil.isOrder(bb.root)
Review comment:
I rewritten and added some comments to explain the code.
##########
File path: core/src/test/java/org/apache/calcite/test/JdbcTest.java
##########
@@ -5898,17 +5965,32 @@ private void checkMapSchemaDirectConnection(String s)
throws SQLException {
+ "order by \"empid\" limit 2", null);
with
.query("select \"name\" from \"adhoc\".V order by \"name\"")
+ .withHook(Hook.SQL2REL_CONVERTER_CONFIG_BUILDER,
+ (Consumer<Holder<Config>>) configHolder ->
+
configHolder.set(configHolder.get().withRemoveSortInSubQuery(false)))
.returns("name=Bill\n"
+ "name=Theodore\n");
// Now a sub-query with ORDER BY and LIMIT clauses. (Same net effect, but
// ORDER BY and LIMIT in sub-query were not standard SQL until SQL:2008.)
+ with
+ .query("select \"name\" from (\n"
+ + "select * from \"adhoc\".\"EMPLOYEES\" where \"deptno\" = 10\n"
+ + "order by \"empid\" limit 2)\n"
+ + "order by \"name\"")
+ .withHook(Hook.SQL2REL_CONVERTER_CONFIG_BUILDER,
+ (Consumer<Holder<SqlToRelConverter.Config>>) configHolder ->
+
configHolder.set(configHolder.get().withRemoveSortInSubQuery(false)))
+ .returns("name=Bill\n"
Review comment:
Also revised, Would you please review this request again?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]