Prev Source
Next Source

ÞÿJSON Tiles: Fast Analytics on Semi-Structured Data

original source

Here, have some highlights:

Highlights

Relational database systems store each JSON object as a string or use a per-object binary representation [52]. Both approaches are inefficient for analytical queries in comparison with relational column stores.


Sinew [57] therefore extracts com- plete columns to speed up accesses. However, it can only produce good columnar extracts if the data mostly consists ofthe same static document structure. Sinew does not handle changing or heteroge- neous data well and updates are expensive because new document structures change the global frequency of common keys.


Reassem- bling shredded documents with different structures at a record level, as performed with Dremel [42] and implemented in Apache Par- quet [6], results in additional work during query execution: many different optional fields have to be handled while evaluating the access automata.


Processing Parquet files is CPU-bound even for purely relational files without optional fields


This paper presents JSON tiles, a collection of algorithms and techniques that enable high-performance analytics on JSON data.


The key idea behind JSON tiles is to automatically detect the im- plicit common structure across a collection of objects. Using this structural information, we infer types, materialize frequently oc- curring keys as relational columns, and collect query optimizer statistics — enabling performance close to that of native relational column stores.


However, in prac- tice, JSON data is often machine-generated and has a fairly rigid and predictable structure. The key idea of our approach is to detect and leverage this implicit structure to speed up query processing.


Accessing attributes of JSON documents requires document traversal. This traversal introduces a large over- head as every tuple requires a new lookup and all values are un- typed. Accesses of relational columns, on the other hand, are cheap — in particular in column stores. This creates a big performance gap between JSON and relational attribute accesses. JSON tiles gains insights during data loading such that data can be stored in a columnar representation. This enables fast scans of JSON data.


The convenience of putting arbitrary documents into the database is often the primary reason for choosing semi-structured formats. Although the struc- ture of objects is not arbitrary in practice, many data sets contain heterogeneous document types. Consequently, the storage engine needs to adapt to heterogeneous documents, changes of fields, and previously unseen data.


JSON tiles handles different document types and copes with outliers through local computations. Further reordering helps in randomized insertions of heterogeneous documents.


As the example illustrates, the JSON documents in a collection often have the same set of keys and, therefore, have a similar implicit schema. Furthermore, the values for a key have matching types as well.


These observations lead to the insight that real-world semi-structured databases often effectively contain relational information.


Consequently, using the key structure and observed values, we can materialize the common structures as typed relational columns.


Because data is materialized into a colum- nar format, no semi-structured access computations are necessary. The cost of accessing a column chunk is amortized by the number of tuples scanned. Therefore, our approach achieves high analytical columnar scan performance while being robust to heterogeneous data objects or combined log data documents from different sources.


Previous work by Tahara et al. [57] observed that documents in real-world data sets often have similar structure and they therefore propose extracting a single schema globally. However, such a global approach is not robust with respect to heterogeneous or changing data. Depending on the chosen extraction threshold, many keys will either fall below the threshold or the resulting relation will have many attributes with mostly null values. In both cases, performance will not be optimal for heterogeneous data sets.


We therefore propose to detect the implicit document structure at a fine granularity (hundreds or thousands of documents rather than globally).


For many applications, the inser- tion order already provides strong spatial locality and therefore high-quality JSON tiles.


However, workloads like the one shown in Figure 3, where each document is of a different type, have little spatial locality. Even fine-granular tiles would result in poor scan performance. In the following, we describe an approach that solves this issue by reordering tuples between neighboring tiles.
The goal of the reordering algorithm is to find frequent itemsets across multiple tiles. The tuples are then reordered such that the same frequent itemsets are clustered in a single tile.


We split the input data into disjunct JSONtiles, for each of which we detect a local schema. This approach naturally exploits the spatial locality contained in many data sets and finds a sweet spot between fast scan performance and the reduction of uncommon patterns. Our experiments show that a tile size of 210-212 tuples works well across many workloads.


Unfortunately, the complexity of the result is a major problem of itemset mining. Since in the worst case the number of frequent itemsets is equal to the cardinality ofthe powerset offrequent items, we need to restrict the number of computed itemsets. Otherwise, itemset mining would be prohibitively expensive for tile creation.


To compute frequent itemsets, we rely on an efficient implemen- tation of the FPGrowth algorithm


Another interesting challenge arises from heavily nested arrays. Ifthe number ofelements in an array is similar in all documents ofa tile, JSON tiles is able to materialize all frequent elements. However, if the number varies, JSON tiles materializes only the leading ele- ments that are frequent across all documents. For example, if every document contains an array with 𝑥 elements but some documents have 𝑥 + 𝑐 array elements, only the first 𝑥 elements are extracted.


Accessing nested column extracts require some care. For ex- ample, the access to ’key’→’nestedKey’ could first extract the object key and then use a regular JSON lookup or access nestedKey directly if available. Usually, a direct access to nestedKey is pre- ferred.


To overcome this issue, JSON tiles recognizes during the scan operation whether the other levels of the key path are needed. We count how often each key is used as multiple expressions are able to share the same paths. If the path is used exclusively by one expres- sion and the nestedKey is materialized, the intermediate access is removed.


We measured the size needed to store JSON tiles in Table 6 to analyze the stor- age requirements. In our current implementation, JSON tiles are materialized in addition to the original JSONB data.
All benefits of JSON tiles come with only a moderate size overhead.


Process finished with exit code 0


Date
June 27, 2024