You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Kevin Risden (JIRA)" <ji...@apache.org> on 2019/02/27 20:05:00 UTC
[jira] [Updated] (CALCITE-1962) SqlOrderBy unparse ignores dialect.
[ https://issues.apache.org/jira/browse/CALCITE-1962?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Kevin Risden updated CALCITE-1962:
----------------------------------
Labels: pull-request-available (was: )
> SqlOrderBy unparse ignores dialect.
> -----------------------------------
>
> Key: CALCITE-1962
> URL: https://issues.apache.org/jira/browse/CALCITE-1962
> Project: Calcite
> Issue Type: Bug
> Reporter: Paul O'Riordan
> Priority: Major
> Labels: pull-request-available
>
> Given the following code:
> {noformat}
> final SqlParser.ConfigBuilder configBuilder = SqlParser.configBuilder();
> configBuilder.setLex(Lex.MYSQL);
> final SqlParser.Config config = configBuilder.build();
> final SqlParser parser = SqlParser.create(str, config);
> final SqlNode parsedStatement = parser.parseQuery("select id from Test limit 1");
> final SqlDialect mysqlDialect = new SqlDialect(DatabaseProduct.MYSQL, "mysql", "`", NullCollation.LAST);
> final SqlPrettyWriter spw1 = new SqlPrettyWriter(mysqlDialect);
> System.out.println(spw1.format(parsedStatement));
> {noformat}
> The output is:
> {noformat}
> SELECT `id`
> FROM `Test`
> FETCH NEXT 1 ROWS ONLY
> {noformat}
> Expected output:
> {noformat}
> SELECT `id`
> FROM `Test`
> LIMIT 1
> {noformat}
> Suggested fix:
> {noformat}
> diff --git a/core/src/main/java/org/apache/calcite/sql/SqlOrderBy.java b/core/src/main/java/org/apache/calcite/sql/SqlOrderBy.java
> index 421b9e21d..b26ffd67b 100644
> --- a/core/src/main/java/org/apache/calcite/sql/SqlOrderBy.java
> +++ b/core/src/main/java/org/apache/calcite/sql/SqlOrderBy.java
> @@ -95,26 +95,7 @@ public void unparse(
> unparseListClause(writer, orderBy.orderList);
> writer.endList(listFrame);
> }
> - if (orderBy.offset != null) {
> - final SqlWriter.Frame frame2 =
> - writer.startList(SqlWriter.FrameTypeEnum.OFFSET);
> - writer.newlineAndIndent();
> - writer.keyword("OFFSET");
> - orderBy.offset.unparse(writer, -1, -1);
> - writer.keyword("ROWS");
> - writer.endList(frame2);
> - }
> - if (orderBy.fetch != null) {
> - final SqlWriter.Frame frame3 =
> - writer.startList(SqlWriter.FrameTypeEnum.FETCH);
> - writer.newlineAndIndent();
> - writer.keyword("FETCH");
> - writer.keyword("NEXT");
> - orderBy.fetch.unparse(writer, -1, -1);
> - writer.keyword("ROWS");
> - writer.keyword("ONLY");
> - writer.endList(frame3);
> - }
> + writer.fetchOffset(orderBy.fetch, orderBy.offset);
> writer.endList(frame);
> }
> }
> {noformat}
> See PR: https://github.com/apache/calcite/pull/525
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)