You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by ke...@apache.org on 2012/05/08 18:45:36 UTC

svn commit: r1335630 - in /hive/trunk: data/files/json.txt ql/src/java/org/apache/hadoop/hive/ql/udf/UDFJson.java ql/src/test/queries/clientpositive/udf_get_json_object.q ql/src/test/results/clientpositive/udf_get_json_object.q.out

Author: kevinwilfong
Date: Tue May  8 16:45:35 2012
New Revision: 1335630

URL: http://svn.apache.org/viewvc?rev=1335630&view=rev
Log:
HIVE-2971 GET_JSON_OBJECT fails on some valid JSON keys (gangtimliu via kevinwilfong)

Modified:
    hive/trunk/data/files/json.txt
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFJson.java
    hive/trunk/ql/src/test/queries/clientpositive/udf_get_json_object.q
    hive/trunk/ql/src/test/results/clientpositive/udf_get_json_object.q.out

Modified: hive/trunk/data/files/json.txt
URL: http://svn.apache.org/viewvc/hive/trunk/data/files/json.txt?rev=1335630&r1=1335629&r2=1335630&view=diff
==============================================================================
--- hive/trunk/data/files/json.txt (original)
+++ hive/trunk/data/files/json.txt Tue May  8 16:45:35 2012
@@ -1 +1 @@
-{"store":{"fruit":[{"weight":8,"type":"apple"},{"weight":9,"type":"pear"}],"basket":[[1,2,{"b":"y","a":"x"}],[3,4],[5,6]],"book":[{"author":"Nigel Rees","title":"Sayings of the Century","category":"reference","price":8.95},{"author":"Herman Melville","title":"Moby Dick","category":"fiction","price":8.99,"isbn":"0-553-21311-3"},{"author":"J. R. R. Tolkien","title":"The Lord of the Rings","category":"fiction","reader":[{"age":25,"name":"bob"},{"age":26,"name":"jack"}],"price":22.99,"isbn":"0-395-19395-8"}],"bicycle":{"price":19.95,"color":"red"}},"email":"amy@only_for_json_udf_test.net","owner":"amy"}
+{"store":{"fruit":[{"weight":8,"type":"apple"},{"weight":9,"type":"pear"}],"basket":[[1,2,{"b":"y","a":"x"}],[3,4],[5,6]],"book":[{"author":"Nigel Rees","title":"Sayings of the Century","category":"reference","price":8.95},{"author":"Herman Melville","title":"Moby Dick","category":"fiction","price":8.99,"isbn":"0-553-21311-3"},{"author":"J. R. R. Tolkien","title":"The Lord of the Rings","category":"fiction","reader":[{"age":25,"name":"bob"},{"age":26,"name":"jack"}],"price":22.99,"isbn":"0-395-19395-8"}],"bicycle":{"price":19.95,"color":"red"}},"email":"amy@only_for_json_udf_test.net","owner":"amy","zip code":"94025","fb:testid":"1234"}

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFJson.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFJson.java?rev=1335630&r1=1335629&r2=1335630&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFJson.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/udf/UDFJson.java Tue May  8 16:45:35 2012
@@ -55,7 +55,7 @@ import org.json.JSONObject;
     + "  [,] : Union operator\n"
     + "  [start:end:step] : array slice operator\n")
 public class UDFJson extends UDF {
-  private final Pattern patternKey = Pattern.compile("^([a-zA-Z0-9_\\-]+).*");
+  private final Pattern patternKey = Pattern.compile("^([a-zA-Z0-9_\\-\\:\\s]+).*");
   private final Pattern patternIndex = Pattern.compile("\\[([0-9]+|\\*)\\]");
 
   // An LRU cache using a linked hash map
@@ -93,15 +93,15 @@ public class UDFJson extends UDF {
    * Extract json object from a json string based on json path specified, and
    * return json string of the extracted json object. It will return null if the
    * input json string is invalid.
-   * 
+   *
    * A limited version of JSONPath supported: $ : Root object . : Child operator
    * [] : Subscript operator for array * : Wildcard for []
-   * 
+   *
    * Syntax not supported that's worth noticing: '' : Zero length string as key
    * .. : Recursive descent @ : Current object/element () : Script
    * expression ?() : Filter (script) expression. [,] : Union operator
    * [start:end:step] : array slice operator
-   * 
+   *
    * @param jsonString
    *          the json string.
    * @param pathString

Modified: hive/trunk/ql/src/test/queries/clientpositive/udf_get_json_object.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientpositive/udf_get_json_object.q?rev=1335630&r1=1335629&r2=1335630&view=diff
==============================================================================
--- hive/trunk/ql/src/test/queries/clientpositive/udf_get_json_object.q (original)
+++ hive/trunk/ql/src/test/queries/clientpositive/udf_get_json_object.q Tue May  8 16:45:35 2012
@@ -23,3 +23,7 @@ SELECT get_json_object(src_json.json, '$
 SELECT get_json_object(src_json.json, '$.store.basket[0][1]'), get_json_object(src_json.json, '$.store.basket[*]'), get_json_object(src_json.json, '$.store.basket[*][0]'), get_json_object(src_json.json, '$.store.basket[0][*]'), get_json_object(src_json.json, '$.store.basket[*][*]'), get_json_object(src_json.json, '$.store.basket[0][2].b'), get_json_object(src_json.json, '$.store.basket[0][*].b') FROM src_json;
 
 SELECT get_json_object(src_json.json, '$.non_exist_key'),  get_json_object(src_json.json, '$..no_recursive'), get_json_object(src_json.json, '$.store.book[10]'), get_json_object(src_json.json, '$.store.book[0].non_exist_key'), get_json_object(src_json.json, '$.store.basket[*].non_exist_key'), get_json_object(src_json.json, '$.store.basket[0][*].non_exist_key') FROM src_json;
+
+SELECT get_json_object(src_json.json, '$.zip code') FROM src_json;
+
+SELECT get_json_object(src_json.json, '$.fb:testid') FROM src_json;
\ No newline at end of file

Modified: hive/trunk/ql/src/test/results/clientpositive/udf_get_json_object.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientpositive/udf_get_json_object.q.out?rev=1335630&r1=1335629&r2=1335630&view=diff
==============================================================================
--- hive/trunk/ql/src/test/results/clientpositive/udf_get_json_object.q.out (original)
+++ hive/trunk/ql/src/test/results/clientpositive/udf_get_json_object.q.out Tue May  8 16:45:35 2012
@@ -153,3 +153,23 @@ POSTHOOK: Input: default@src_json
 #### A masked pattern was here ####
 POSTHOOK: Lineage: dest1.c1 SIMPLE []
 NULL	NULL	NULL	NULL	NULL	NULL
+PREHOOK: query: SELECT get_json_object(src_json.json, '$.zip code') FROM src_json
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src_json
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT get_json_object(src_json.json, '$.zip code') FROM src_json
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src_json
+#### A masked pattern was here ####
+POSTHOOK: Lineage: dest1.c1 SIMPLE []
+94025
+PREHOOK: query: SELECT get_json_object(src_json.json, '$.fb:testid') FROM src_json
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src_json
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT get_json_object(src_json.json, '$.fb:testid') FROM src_json
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src_json
+#### A masked pattern was here ####
+POSTHOOK: Lineage: dest1.c1 SIMPLE []
+1234