You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2020/08/25 22:31:49 UTC

[impala] branch master updated: IMPALA-8547: get_json_object fails to get value for numeric key

This is an automated email from the ASF dual-hosted git repository.

tarmstrong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/impala.git


The following commit(s) were added to refs/heads/master by this push:
     new adf2c46  IMPALA-8547: get_json_object fails to get value for numeric key
adf2c46 is described below

commit adf2c464aed5d35c976c1439982e0a927f76b609
Author: Eugene Zimichev <un...@gmail.com>
AuthorDate: Fri Dec 13 20:51:10 2019 +0300

    IMPALA-8547: get_json_object fails to get value for numeric key
    
    Allows numeric keys for JSON objects in get_json_object. This patch
    makes Impala consistent with Hive and Postgres behavior for
    get_json_object.
    
    Queries such as "select get_json_object('{"1": 5}', '$.1');"
    would fail before this patch. Now the query will return '5'.
    
    Testing:
    * Added tests to expr-test
    
    Change-Id: I7df037ccf2c79da0ba86a46df1dd28ab0e9a45f4
    Reviewed-on: http://gerrit.cloudera.org:8080/14905
    Reviewed-by: Impala Public Jenkins <im...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 be/src/exprs/expr-test.cc  | 1 +
 be/src/util/string-util.cc | 3 ++-
 be/src/util/string-util.h  | 6 +++---
 3 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/be/src/exprs/expr-test.cc b/be/src/exprs/expr-test.cc
index aaf8e30..779aaeb 100644
--- a/be/src/exprs/expr-test.cc
+++ b/be/src/exprs/expr-test.cc
@@ -9999,6 +9999,7 @@ TEST_P(ExprTest, JsonTest) {
   TestStringValue(
       "get_json_object('{\"a\": {\"aa\": 1}, \"b\": {\"bb\": 2}}', '$.*.*')",
       "[1,2]");
+  TestStringValue("get_json_object('{\"a\":1, \"1\":2, \"c\":3}', '$.1')", "2");
 
   // Tests about NULL
   TestIsNull("get_json_object('{\"a\": 1}', '$.b')", TYPE_STRING);
diff --git a/be/src/util/string-util.cc b/be/src/util/string-util.cc
index 1995048..d945539 100644
--- a/be/src/util/string-util.cc
+++ b/be/src/util/string-util.cc
@@ -76,7 +76,8 @@ bool EndsWith(const std::string& full_string, const std::string& end) {
 const uint8_t* FindEndOfIdentifier(const uint8_t* start, const uint8_t* end) {
   if (start == end) return nullptr;
   uint8_t ch = *start++;
-  if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || ch == '_')) {
+  if (!((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') ||
+      (ch >= '0' && ch <= '9') || ch == '_')) {
     return nullptr;
   }
   while (start != end) {
diff --git a/be/src/util/string-util.h b/be/src/util/string-util.h
index 3528e73..2644b54 100644
--- a/be/src/util/string-util.h
+++ b/be/src/util/string-util.h
@@ -45,10 +45,10 @@ bool CommaSeparatedContains(const std::string& cs_list, const std::string& item)
 /// 'end' string
 bool EndsWith(const std::string& full_string, const std::string& end);
 
-/// This function returns a pointer past the end of the longest C-style identifier
+/// This function returns a pointer past the end of the longest identifier
 /// that is a prefix of given string or NULL if the given string does not start with
-/// one.  A C-style identifier begins with an ASCII letter or underscore
-/// and continues with ASCII letters, digits, or underscores.  start and end means
+/// one. The identifier must begin with an ASCII letter, underscore, or digit
+/// and continues with ASCII letters, digits, or underscores. start and end means
 /// the given string is located at [start, end)
 const uint8_t* FindEndOfIdentifier(const uint8_t* start, const uint8_t* end);