You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ad...@apache.org on 2018/08/02 17:35:08 UTC

kudu git commit: KUDU-2459: add placeholder names to some CREATE TABLE statements

Repository: kudu
Updated Branches:
  refs/heads/master c5a93d030 -> a7a850278


KUDU-2459: add placeholder names to some CREATE TABLE statements

Under the Tables section of Kudu Web UI, for a selected table, the table
metrics display a CREATE TABLE statement that can be run to make Impala
cognizant of that table. However, in generation of this statement, the
tablename tries to match the original Kudu tablename which may not
always be acceptable as a tablename for Impala. For example, Kudu
accepts dot in tablename, Impala does not. The CREATE TABLE statement
thus throws an invalid tablename error in Impala.

We considered trying to derive an Impala-conforming name from the Kudu-
supplied tablename but that could result in surprising/unintuitive
results. We also want to leverage the current functionality of auto-
generated statement where the name is valid. Therefore with this update,
invalid tablenames have been identified and updated by a placeholder
tablename for end user to replace with a valid tablename. The rules to
check Impala conformity are below --

- The minimum length of an identifier is 1 character.

- The maximum length of an identifier is currently 128 characters.

- An identifier must start with an alphabetic character.
The remainder can contain any combination of alphanumeric characters and
underscores. Quoting the identifier with backticks has no effect on the
allowed characters in the name.

- An identifier can contain only ASCII characters.

Change-Id: If9e5242318589452a0507d3973b9be3e6a186a69
Reviewed-on: http://gerrit.cloudera.org:8080/10656
Reviewed-by: Adar Dembo <ad...@cloudera.com>
Tested-by: Kudu Jenkins


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/a7a85027
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/a7a85027
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/a7a85027

Branch: refs/heads/master
Commit: a7a85027824c1fb6b3af37130d86ccf1e4ffeb02
Parents: c5a93d0
Author: Shriya Gupta <sh...@gmail.com>
Authored: Fri Jun 8 14:58:41 2018 -0400
Committer: Adar Dembo <ad...@cloudera.com>
Committed: Thu Aug 2 17:34:51 2018 +0000

----------------------------------------------------------------------
 src/kudu/master/master_path_handlers.cc | 27 +++++++++++++++++++++++++++
 www/table.mustache                      |  2 +-
 2 files changed, 28 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/a7a85027/src/kudu/master/master_path_handlers.cc
----------------------------------------------------------------------
diff --git a/src/kudu/master/master_path_handlers.cc b/src/kudu/master/master_path_handlers.cc
index eda548b..75433af 100644
--- a/src/kudu/master/master_path_handlers.cc
+++ b/src/kudu/master/master_path_handlers.cc
@@ -45,6 +45,7 @@
 #include "kudu/gutil/port.h"
 #include "kudu/gutil/ref_counted.h"
 #include "kudu/gutil/stringprintf.h"
+#include "kudu/gutil/strings/ascii_ctype.h"
 #include "kudu/gutil/strings/join.h"
 #include "kudu/gutil/strings/numbers.h"
 #include "kudu/gutil/strings/substitute.h"
@@ -261,6 +262,32 @@ void MasterPathHandlers::HandleTablePage(const Webserver::WebRequest& req,
   {
     TableMetadataLock l(table.get(), LockMode::READ);
     (*output)["name"] = l.data().name();
+
+    // Not all Kudu tablenames are also valid Impala identifiers. We need to
+    // replace such names with a placeholder when they are used as Impala
+    // identifiers, like when used for Impala tablename in the Kudu Web UI.
+    // Valid Impala identifiers conform to the following rules:
+    // 1. Must not be empty.
+    // 2. Length must not exceed 128 characters.
+    // 3. First character must be alphabetic.
+    // 4. Every character must be alphanumeric or an underscore.
+    // 5. If it matches any Impala-reserved keyword, it must be surrounded
+    // by backticks.
+    // The last rule is not tested for in the code segment below as the backticks
+    // can be added at the time of usage, as is the case for Web UI where it's
+    // currently being passed to.
+    string impala_name = "<placeholder>";
+    string orig_name = l.data().name();
+    if (!orig_name.empty() &&
+      orig_name.length() <= 128 &&
+      ascii_isalpha(orig_name[0]) &&
+      find_if(orig_name.begin(), orig_name.end(), [](char c) {
+        return !(ascii_isalnum(c) || (c == '_'));
+        }) == orig_name.end()) {
+      impala_name = orig_name;
+    }
+
+    (*output)["impala_table_name"] = impala_name;
     (*output)["id"] = table_id;
     (*output)["version"] = l.data().pb.version();
 

http://git-wip-us.apache.org/repos/asf/kudu/blob/a7a85027/www/table.mustache
----------------------------------------------------------------------
diff --git a/www/table.mustache b/www/table.mustache
index 8de206b..92093ed 100644
--- a/www/table.mustache
+++ b/www/table.mustache
@@ -151,7 +151,7 @@ under the License.
 
   <h3>Impala CREATE TABLE statement</h3>
   {{! Unusual formatting below because <pre> preserves whitespace in the output. }}
-  <pre><code>CREATE EXTERNAL TABLE `{{name}}` STORED AS KUDU
+  <pre><code>CREATE EXTERNAL TABLE `{{impala_table_name}}` STORED AS KUDU
 TBLPROPERTIES(
     'kudu.table_name' = '{{name}}',
     'kudu.master_addresses' = '{{master_addresses}}')</code></pre>