mirror of
https://github.com/apache/impala.git
synced 2026-01-22 09:01:58 -05:00
Impala allows non-string types, for example numbers, to be keys in maps.
We print maps as json objects, but json objects only allow string keys.
If the Impala map has for example an INT key, the printed json is
invalid.
For example, in Impala the following two maps are not the same:
{1: "a", 2: "b"}
{"1": "a", "2": "b"}
The first map has INT keys, the second has STRING keys. Only the second
one is valid json.
Hive has the same behaviour as Impala, i.e. it produces invalid json if
the map keys have a non-string type.
This change introduces the STRINGIFY_MAP_KEYS query option that, when
set to true, converts non-string keys to strings. The default value of
the new query option is false because
- conversion to string causes loss of information and
- setting it to true would be a breaking change.
Testing:
- Added tests in nested-map-in-select-list.test and map_null_keys.test
that check the behaviour when STRINGIFY_MAP_KEYS is set to true.
Change-Id: I1820036a1c614c34ae5d70ac4fe79a992c9bce3a
Reviewed-on: http://gerrit.cloudera.org:8080/19364
Reviewed-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
49 lines
1.7 KiB
Plaintext
49 lines
1.7 KiB
Plaintext
=====
|
|
---- QUERY
|
|
-- Test that NULL map keys are printed correctly.
|
|
set CONVERT_LEGACY_HIVE_PARQUET_UTC_TIMESTAMPS=1;
|
|
select
|
|
id,
|
|
map_bool_key,
|
|
map_tinyint_key,
|
|
map_smallint_key,
|
|
map_bigint_key,
|
|
map_float_key,
|
|
map_double_key,
|
|
map_decimal_key,
|
|
map_string_key,
|
|
map_char_key,
|
|
map_varchar_key,
|
|
map_timestamp_key,
|
|
map_date_key
|
|
from map_null_keys;
|
|
---- RESULTS
|
|
1,'{true:"true",null:"null"}','{-1:"one",null:"null"}','{-1:"one",null:"null"}','{-1:"one",null:"null"}','{-1.75:"a",null:"null"}','{-1.75:"a",null:"null"}','{-1.8:"a",null:"null"}','{"one":1,null:null}','{"Mon":1,null:null}','{"a":"A",null:null}','{"2022-12-10 08:15:12":"Saturday morning",null:"null"}','{"2022-12-10":"Saturday",null:"null"}'
|
|
---- TYPES
|
|
INT,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING
|
|
=====
|
|
---- QUERY
|
|
-- Test that NULL map keys are printed correctly with STRINGIFY_MAP_KEYS=true.
|
|
set CONVERT_LEGACY_HIVE_PARQUET_UTC_TIMESTAMPS=1;
|
|
set STRINGIFY_MAP_KEYS=1;
|
|
select
|
|
id,
|
|
map_bool_key,
|
|
map_tinyint_key,
|
|
map_smallint_key,
|
|
map_bigint_key,
|
|
map_float_key,
|
|
map_double_key,
|
|
map_decimal_key,
|
|
map_string_key,
|
|
map_char_key,
|
|
map_varchar_key,
|
|
map_timestamp_key,
|
|
map_date_key
|
|
from map_null_keys;
|
|
---- RESULTS
|
|
1,'{"true":"true","null":"null"}','{"-1":"one","null":"null"}','{"-1":"one","null":"null"}','{"-1":"one","null":"null"}','{"-1.75":"a","null":"null"}','{"-1.75":"a","null":"null"}','{"-1.8":"a","null":"null"}','{"one":1,"null":null}','{"Mon":1,"null":null}','{"a":"A","null":null}','{"2022-12-10 08:15:12":"Saturday morning","null":"null"}','{"2022-12-10":"Saturday","null":"null"}'
|
|
---- TYPES
|
|
INT,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING,STRING
|
|
=====
|