IMPALA-4036: invalid SQL generated for partitioned table with comment For a table that has both a table comment and a partition specified, "show create table" incorrectly outputs the comment before the partition. This is not the correct order, and it results in an invalid SQL.
This transaction fixes the ordering (partition comes before comment) and adds tests for this case. Change-Id: I29a33cfd142b473997fdc3acfe3f0966bc7ed784 Reviewed-on: http://gerrit.cloudera.org:8080/5648 Tested-by: Impala Public Jenkins Reviewed-by: Henry Robinson <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/57552619 Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/57552619 Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/57552619 Branch: refs/heads/master Commit: 5755261954d71b05b5e56c8659edd17de88b2d93 Parents: 8b7f876 Author: Joe McDonnell <[email protected]> Authored: Mon Jan 9 13:46:22 2017 -0800 Committer: Henry Robinson <[email protected]> Committed: Thu Jan 12 20:41:35 2017 +0000 ---------------------------------------------------------------------- fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java | 3 ++- fe/src/test/java/org/apache/impala/analysis/ToSqlTest.java | 6 ++++-- .../functional-query/queries/QueryTest/show-create-table.test | 2 ++ 3 files changed, 8 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/57552619/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java ---------------------------------------------------------------------- diff --git a/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java b/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java index 35f7e79..a922c8b 100644 --- a/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java +++ b/fe/src/main/java/org/apache/impala/analysis/ToSqlUtils.java @@ -264,7 +264,6 @@ public class ToSqlUtils { sb.append("\n)"); } sb.append("\n"); - if (tableComment != null) sb.append(" COMMENT '" + tableComment + "'\n"); if (partitionColumnsSql != null && partitionColumnsSql.size() > 0) { sb.append(String.format("PARTITIONED BY (\n %s\n)\n", @@ -275,6 +274,8 @@ public class ToSqlUtils { sb.append("PARTITION BY " + kuduPartitionByParams + "\n"); } + if (tableComment != null) sb.append(" COMMENT '" + tableComment + "'\n"); + if (rowFormat != null && !rowFormat.isDefault()) { sb.append("ROW FORMAT DELIMITED"); if (rowFormat.getFieldDelimiter() != null) { http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/57552619/fe/src/test/java/org/apache/impala/analysis/ToSqlTest.java ---------------------------------------------------------------------- diff --git a/fe/src/test/java/org/apache/impala/analysis/ToSqlTest.java b/fe/src/test/java/org/apache/impala/analysis/ToSqlTest.java index 9514cc6..2b52a68 100644 --- a/fe/src/test/java/org/apache/impala/analysis/ToSqlTest.java +++ b/fe/src/test/java/org/apache/impala/analysis/ToSqlTest.java @@ -296,9 +296,11 @@ public class ToSqlTest extends FrontendTestBase { @Test public void TestCreateTable() throws AnalysisException { - testToSql("create table p (a int)", + testToSql("create table p (a int) partitioned by (day string) " + + "comment 'This is a test'", "default", - "CREATE TABLE default.p ( a INT ) STORED AS TEXTFILE", true); + "CREATE TABLE default.p ( a INT ) PARTITIONED BY ( day STRING ) " + + "COMMENT 'This is a test' STORED AS TEXTFILE", true); } @Test http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/57552619/testdata/workloads/functional-query/queries/QueryTest/show-create-table.test ---------------------------------------------------------------------- diff --git a/testdata/workloads/functional-query/queries/QueryTest/show-create-table.test b/testdata/workloads/functional-query/queries/QueryTest/show-create-table.test index 252cd96..946d229 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/show-create-table.test +++ b/testdata/workloads/functional-query/queries/QueryTest/show-create-table.test @@ -71,6 +71,7 @@ PARTITIONED BY ( y INT, a BOOLEAN ) +COMMENT 'This is a test' STORED AS TEXTFILE ---- RESULTS CREATE TABLE show_create_table_test_db.test3 ( @@ -93,6 +94,7 @@ PARTITIONED BY ( y INT, a BOOLEAN ) +COMMENT 'This is a test' STORED AS TEXTFILE LOCATION '$$location_uri$$' ====
