mirror of
https://github.com/apache/impala.git
synced 2026-02-01 12:00:22 -05:00
Prototype of HdfsJsonScanner implemented based on rapidjson, which supports scanning data from splitting json files. The scanning of JSON data is mainly completed by two parts working together. The first part is the JsonParser responsible for parsing the JSON object, which is implemented based on the SAX-style API of rapidjson. It reads data from the char stream, parses it, and calls the corresponding callback function when encountering the corresponding JSON element. See the comments of the JsonParser class for more details. The other part is the HdfsJsonScanner, which inherits from HdfsScanner and provides callback functions for the JsonParser. The callback functions are responsible for providing data buffers to the Parser and converting and materializing the Parser's parsing results into RowBatch. It should be noted that the parser returns numeric values as strings to the scanner. The scanner uses the TextConverter class to convert the strings to the desired types, similar to how the HdfsTextScanner works. This is an advantage compared to using number value provided by rapidjson directly, as it eliminates concerns about inconsistencies in converting decimals (e.g. losing precision). Added a startup flag, enable_json_scanner, to be able to disable this feature if we hit critical bugs in production. Limitations - Multiline json objects are not fully supported yet. It is ok when each file has only one scan range. However, when a file has multiple scan ranges, there is a small probability of incomplete scanning of multiline JSON objects that span ScanRange boundaries (in such cases, parsing errors may be reported). For more details, please refer to the comments in the 'multiline_json.test'. - Compressed JSON files are not supported yet. - Complex types are not supported yet. Tests - Most of the existing end-to-end tests can run on JSON format. - Add TestQueriesJsonTables in test_queries.py for testing multiline, malformed, and overflow in JSON. Change-Id: I31309cb8f2d04722a0508b3f9b8f1532ad49a569 Reviewed-on: http://gerrit.cloudera.org:8080/19699 Reviewed-by: Quanlong Huang <huangquanlong@gmail.com> Tested-by: Impala Public Jenkins <impala-public-jenkins@cloudera.com>
27 lines
1.3 KiB
Plaintext
27 lines
1.3 KiB
Plaintext
====
|
|
---- QUERY
|
|
# Testing scanning of multi-line JSON, rapidjson can handle cases where line breaks appear
|
|
# in JSON (except for those that appear in numbers and strings), so in most cases it can
|
|
# scan multi-line JSON. However, line breaks in strings and numbers are treated as invalid
|
|
# values, and the scanner returns null. Additionally, it should be noted that if the line
|
|
# break in the multi-line JSON is near the beginning of the scan range, it may cause the
|
|
# parser to misjudge the starting position of the first complete JSON (because it always
|
|
# starts parsing from the position after the first line break). This usually has no
|
|
# effect (except report a error), but if there happens to be a sub-object immediately
|
|
# after the line break, itwill cause an extra line of data to be scanned. If the line
|
|
# break in the multi-line JSONis also at the beginning of the scan range, it will cause
|
|
# the last line of data from the previous scan range to be incomplete.
|
|
select id, key, value from multiline_json
|
|
---- TYPES
|
|
int, string, string
|
|
---- RESULTS
|
|
1,'normal object','abcdefg'
|
|
2,'multiline string','NULL'
|
|
3,'multiline number','1234'
|
|
4,'multiline object1','abcdefg'
|
|
5,'multiline object2','abcdefg'
|
|
6,'multiline object3','abcdefg'
|
|
7,'multiline object4','abcdefg'
|
|
8,'one line multiple objects','obj1'
|
|
9,'one line multiple objects','obj2'
|
|
==== |