diff --git a/fe/src/main/java/com/cloudera/impala/analysis/ToSqlUtils.java b/fe/src/main/java/com/cloudera/impala/analysis/ToSqlUtils.java index 938fe2eb6..3dcdd1e93 100644 --- a/fe/src/main/java/com/cloudera/impala/analysis/ToSqlUtils.java +++ b/fe/src/main/java/com/cloudera/impala/analysis/ToSqlUtils.java @@ -77,7 +77,19 @@ public class ToSqlUtils { // Ignore exception and just quote the identifier to be safe. } boolean isImpalaKeyword = SqlScanner.isKeyword(ident.toUpperCase()); - if (hiveNeedsQuotes || isImpalaKeyword) return "`" + ident + "`"; + // Impala's scanner recognizes the ".123" portion of "db.123_tbl" as a decimal, + // so while the quoting is not necessary for the given identifier itself, the quotes + // are needed if this identifier will be preceded by a ".". + boolean startsWithNumber = false; + if (!hiveNeedsQuotes && !isImpalaKeyword) { + try { + Integer.parseInt(ident.substring(0, 1)); + startsWithNumber = true; + } catch (NumberFormatException e) { + // Ignore exception, identifier does not start with number. + } + } + if (hiveNeedsQuotes || isImpalaKeyword || startsWithNumber) return "`" + ident + "`"; return ident; } diff --git a/testdata/workloads/functional-query/queries/QueryTest/compute-stats.test b/testdata/workloads/functional-query/queries/QueryTest/compute-stats.test index c148e14dd..cb9824d37 100644 --- a/testdata/workloads/functional-query/queries/QueryTest/compute-stats.test +++ b/testdata/workloads/functional-query/queries/QueryTest/compute-stats.test @@ -908,3 +908,23 @@ show table stats compute_stats_db.empty_partitioned ---- TYPES STRING, BIGINT, BIGINT, STRING, STRING, STRING, STRING, STRING ==== +---- QUERY +# IMPALA-1614 Verify that COMPUTE STATS works on a table whose name starts with numbers. +create table compute_stats_db.`123_table` (i int, 1p int) partitioned by (2j int); +alter table compute_stats_db.`123_table` add partition (2j=1); +==== +---- QUERY +compute stats compute_stats_db.`123_table` +---- RESULTS +'Updated 1 partition(s) and 2 column(s).' +---- TYPES +STRING +==== +---- QUERY +show table stats compute_stats_db.`123_table` +---- RESULTS +'1',0,0,'0B','NOT CACHED','NOT CACHED','TEXT','false' +'Total',0,0,'0B','0B','','','' +---- TYPES +STRING, BIGINT, BIGINT, STRING, STRING, STRING, STRING, STRING +====