The present disclosure relates to a scalable interactive database platform and more specifically to a scalable interactive database platform for semi-structured data that incorporates storage and computation.
The background description provided herein is for the purpose of generally presenting the context of the disclosure. Work of the presently named inventors, to the extent it is described in this background section, as well as aspects of the background description that may not otherwise qualify as prior art at the time of filing, are neither expressly nor impliedly admitted as prior art against the present disclosure.
Traditional database systems feature a query execution engine that is tightly integrated with the underlying storage back-end, which typically consists of block-addressable persistent storage devices with no compute capabilities. These devices (hard disk drives and/or solid state drives) are characterized by (a) access times that differ significantly depending on whether the data is accessed sequentially or randomly, (b) access units that have a fixed minimum size, set at the granularity of a block, and (c) significantly slower (orders of magnitude) access time than main memory. These characteristics, along with the assumption that the storage back-end does not have any non-trivial compute capabilities have had an important impact on the design of database systems, from storage management to query execution to query optimization.
Databases originally served as operational stores managing the day-to-day activities of businesses. As database technology improved both in performance and cost, businesses saw a need to keep an increasing amount of operational history and business state for later analysis. Such analyses help businesses gain insight into their processes and optimize them, thereby providing a competitive advantage and increasing profit.
Data warehousing arose out of this need. Business data is often well-structured, fitting easily into relational tables. Data warehouses are essentially scalable relational database systems offering a structured query language (SQL) for offline analysis of this business data, and optimized for read-mostly workloads. For example, data warehouses include traditional systems like Teradata and newer vendors such as Vertica, Greenplum, and Aster Data. They provide a SQL interface, indexes, and fast columnar access.
Typically, data warehouses are loaded periodically, e.g., nightly or weekly, with data ingested from various sources and operational systems. The process of cleaning, curating, and unifying this data into a single schema and loading it into a warehouse is known as extract-transform-load (ETL). As the variety of sources and data increases, the complexity of the ETL process also increases. Successfully implementing ETL, including defining appropriate schemas and matching input data to the predetermined schemas, can take professionals weeks to months, and changes can be hard or impossible to implement. There are a number of tools, such as Abinitio, Informatica, and Pentaho, in the market to assist with the ETL process. However, the ETL process generally remains cumbersome, brittle, and expensive.
The data analytics market has exploded with a number of business intelligence and visualization tools that make it easy for business users to perform ad hoc, iterative analyses of data in warehouses. Business intelligence tools build multidimensional aggregates of warehouse data and allow users to navigate through and view various slices and projections of this data. For example, a business user might want to see total monthly sales by product category, region, and store. Then, they might want to dig deeper to weekly sales for specific categories or roll-up to see sales for the entire country. Multidimensional aggregates may also be referred to as online analytical processing (OLAP) cubes. A number of business intelligence (BI) tools, such as Business Objects and Cognos, enable such analyses, and support a language called Multidimensional Expressions (MDX) for querying cubes. There are also a number of visualization tools, such as MicroStrategy, Tableau, and Spotfire, that allow business users to intuitively navigate these cubes and data warehouses.
More recently, the type of data that businesses want to analyze has changed. As traditional brick and mortar businesses go online and new online businesses form, these businesses need to analyze the types of data that leading companies, such as Google and Yahoo, are inundated with. These include data types such as web pages, logs of page views, click streams, RSS (Rich Site Summary) feeds, application logs, application server logs, system logs, transaction logs, sensor data, social network feeds, news feeds, and blog posts.
These semi-structured data do not fit well into traditional warehouses. They have some inherent structure, but the structure may be inconsistent. The structure can change quickly over time and may vary across different sources. They are not naturally tabular, and the analyses that users want to run over these data—clustering, classification, prediction, and so on—are not easily expressed with SQL. The existing tools for making effective use of these data are cumbersome and insufficient.
As a result, a new highly scalable storage and analysis platform arose, Hadoop, inspired by the technologies implemented at Google for managing web crawls and searches. At its core, Hadoop offers a clustered file system for reliably storing its data, HDFS (Hadoop Distributed File System), and a rudimentary parallel analysis engine, MapReduce, to support more complex analyses. Starting with these pieces, the Hadoop ecosystem has grown to include an indexed, operational store, HBase, and new query interfaces, Pig and Hive, that rely on MapReduce.
Hive is an Apache project that adds a query layer on top of Hadoop, without any of the optimizations found in traditional warehouses for query optimization, caching, and indexing. Instead, Hive simply turns queries in a SQL-like language (called Hive-QL) into MapReduce jobs to be run against the Hadoop cluster. There are three main problems with Hive for traditional business users. Hive does not support standard SQL, and does not have a dynamic schema. Further, Hive is not fast enough to allow interactive queries, since each Hive query requires a MapReduce job that re-parses all the source data, and often requires multiple passes through the source data.
Impala is a real-time engine for Hive-QL queries on Cloudera's Hadoop implementation. It provides analysis over Hive's sequence files and may eventually support nested models. However, it does not have a dynamic schema, instead requiring that a user still provide a schema upfront for the data to be queried.
Pig is another Apache project and offers a schema-free scripting language for processing log files in Hadoop. Pig, like Hive, translates everything into map-reduce jobs. Likewise, it doesn't leverage any indexes, and is not fast enough for interactivity.
Jaql is a schema-free declarative language (in contrast to declarative languages, like SQL) for analyzing JavaScript Object Notation (JSON) logs. Like Pig, it compiles into map-reduce programs on Hadoop, and shares many of the same drawbacks, including a non-interactive speed.
Hadoop itself is catching on fairly quickly, and is readily available in the cloud. Amazon offers elastic map-reduce, which may be effectively equivalent to Hadoop's MapReduce implementation running in the cloud. It works on data stored in Amazon's cloud-based S3 (Simple Storage Service) and outputs results to S3.
The advantages of the Hadoop ecosystem are three fold. First, the system scales to extreme sizes and can store any data type. Second, it is extremely low cost compared to traditional warehouses (as much as twenty times less expensive). Third, it is open-source, which avoids lock-in with a single vendor. Users want the ability to pick the right tool for the right job and avoid moving data between systems to get their job done. Although Hadoop is more flexible, using Hadoop requires specially skilled administrators and programmers with deep knowledge, who are usually hard to find. Moreover, Hadoop is too slow to be interactive. Even the simplest queries take minutes to hours to execute.
Dremmel is a tool developed internally at Google, which provides SQL-based analysis queries over nested-relational or semi-structured data. The original version handled data in ProtoBuf format. Dremmel requires users to define the schema upfront for all records. BigQuery is a cloud-based commercialization of Dremmel and is extended to handle CSV and JSON formats. Drill is an open-source version of Dremmel.
Asterix is a system for managing and analyzing semi-structured data using an abstract data model (ADM), which is a generalization of JSON, and annotation query language (AQL). Asterix does not support standard SQL, nor does it have fast access afforded by the present disclosure.
A method of operating a data analysis system includes retrieving objects from a data source. Each of the retrieved objects includes (i) data and (ii) metadata describing the data. The method further includes dynamically creating a cumulative schema by, for each object of the retrieved objects: (i) inferring a schema from the object based on the metadata of the object and inferred data types of elements of the data of the object, (ii) creating a unified schema, wherein the unified schema describes both a) the object described by the inferred schema and (b) a cumulative set of objects described by the cumulative schema, and (iii) storing the unified schema as the cumulative schema. The method further includes exporting the data of each of the retrieved objects to a data warehouse.
The present disclosure will become more fully understood from the detailed description and the accompanying drawings, wherein:
In the drawings, reference numbers may be reused to identify similar and/or identical elements.
The present disclosure describes an analysis platform capable of offering a SQL (structured query language)-compliant interface for querying semi-structured data. For purposes of illustration only, semi-structured data is represented in JSON (JavaScript Object Notation) format. Other self-describing, semi-structured formats can be used according to the principles of the present disclosure. Source data does not need to be self-describing. The description can be separated from the data, as would be the case with something like protocol buffers. As long as there are rules, heuristics, or wrapper functions to apply tags to the data, any input data can be turned into objects similar to a JSON format.
In various implementations of the analysis platform according to the present disclosure, some or all of the following advantages are realized:
Speed
The analysis platform provides fast query response times to support ad-hoc, exploratory, and interactive analysis. Users can use this system to quickly discover hidden insights in the data, without having to submit a query and return later in the day or the next day to view the results. The analysis platform relies on an index store, storing all ingested data in indexes, which allows for fast response times.
Two primary indexes are used, a BigIndex (BI) and an ArrayIndex (AI), which are described in more detail below. These are a cross between path indexes and column-oriented stores. Like column-oriented stores, they allow queries to retrieve data only in the relevant fields, thereby reducing I/O (input/output) demands and improving performance. Unlike column stores, however, these indexes are suitable for complex nested objects and collections with numerous fields. For other access patterns, the analysis platform engine maintains auxiliary indexes, described in more detail below, including a ValueIndex (VI). Like traditional database indexes, the ValueIndex provides fast logarithmic access for specific field values or ranges of values. These indexes significantly reduce the data necessary to retrieve to satisfy a query, thereby improving response times.
Dynamic Schema
The analysis platform infers the schema from the data itself, so that users do not have to know an expected schema a priori, and pre-declare the schema before data can be loaded. Semi-structured data may have varying structure, both over time and across different sources. So, the engine computes and updates the schema (or structure) from the data dynamically as data arrives. A relational schema based on this computed schema is presented to users, which they can use to compose queries.
Unlike previous analysis engines that require programmers to specify the schema of data collections before querying them, the present platform computes (or, infers) the underlying schema amongst all the ingested objects. Because of the dynamic schema property, there is a great deal of flexibility. Applications that generate source data can change the structure as the application evolves. Analysts can aggregate and query data from various periods without needing to specify how the schema varies from period to period. Moreover, there is no need to design and enforce a global schema, which can take months, and often requires excluding data that does not fit the schema.
Other analysis systems like MapReduce or Pig that are sometimes described as “schema-free” have two main drawbacks. First, they require users to know the schema in order to query the data, instead of automatically presenting an inferred schema to the user. Second, they parse and interpret objects and their structure on every query, while the analysis platform parses and indexes objects at load time. These indexes allow subsequent queries to run much faster, as mentioned above. Previous engines do not provide automatic inference of a precise and concise schema from the underlying data.
SQL
The analysis platform exposes a standard SQL query interface (for example, an interface compliant with ANSI SQL 2003) so that users can leverage existing SQL tools (e.g., reporting, visualization, and BI tools) and expertise. As a result, business users familiar with SQL or SQL tools can directly access and query semi-structured data without the need to load a data warehouse. Since traditional SQL-based tools do not handle JSON or other semi-structured data formats, the analysis platform presents a relational view of the computed schema of JSON objects. It presents a normalized view and incorporates optimizations to keep the view manageable in size. Although the relational views may present several tables in the schema, these tables are not necessarily materialized.
In order to better accommodate representing semi-structured data in tabular form, the analysis platform can automatically identify “map” objects. Maps are objects (or nested objects) in which both the field name and value can be searched and queried. For example, an object may contain dates as field names and statistics like page views for the values. In the relational view, maps are extracted into separate tables and the data is pivoted such that keys are in a key column and values are in a value column.
Scale and Elasticity
The analysis platform scales to handle large dataset sizes. The analysis platform can automatically and dynamically distribute internal data structures and processing across independent nodes.
The analysis platform is designed and built for virtualized “cloud” environments, including public clouds such as Amazon Web Services and private clouds, such as virtualized server environments administered by the user's organization or offered by third parties, such as Rackspace. Various components of Amazon Web Services, including S3 (Simple Storage Service), EC2 (Elastic Compute Cloud), and Elastic Block Storage (EBS), can be leveraged. The analysis platform is elastic, meaning it can scale up and down to arbitrary sizes on demand, and can hibernate by storing its internal data structures on long-term stores, such as Amazon S3. The analysis platform also has multi-tenancy and multi-user support.
The analysis platform uses a service-based architecture that has four components: the proxy, the metadata service, the query executor, and the storage service. To scale the analysis platform engine to support larger datasets, provide faster responses, and support more users, the execution engine is parallelized and the storage service is partitioned across independent, low-cost server nodes. These nodes can be real servers or virtualized servers in a hosted environment. Since the executor and storage service are de-coupled, they can be scaled independently. This de-coupled, scale-out architecture allows the user to leverage the on-demand elasticity for storage and computing that a cloud environment like AWS provides.
The storage service is configurable with various partitioning strategies. Moreover, the underlying data structures (indexes and metadata) can be migrated to long-term storage like Amazon S3, to hibernate the system when not in use, thereby decreasing costs.
Synchronization
The analysis platform can be configured to automatically synchronize its contents with, and thereby replicate, the source data from repositories like HDFS (Hadoop Distributed File System), Amazon S3 (Simple Storage Service), and noSQL stores, such as MongoDB. These sources can be continuously monitored for changes, additions, and updates, so that the analysis platform can ingest the changed data. This allows query results to be relatively up-to-date.
The analysis platform takes the following actions in response to data appearing in a source: (1) infer unified semi-structured (such as JSON) schema from the data, (2) create a relational view for the schema, (3) populate physical indexes with data, and (4) execute queries that leverage the indexes. Parts or all of actions 1, 2, and 3 may be pipelined to allow only a single pass through the data from the data source.
The first action, schema inference, is described first.
Introduction to Semi-Structured Data
JSON is an increasingly popular self-describing, semi-structured data format, and is very commonly used for data exchange on the internet. Again, while JSON is described here for illustration, and to provide context for later examples using the JSON format, the present disclosure is not limited to JSON.
Briefly, a JSON object consists of string fields (or columns) and corresponding values of potentially different types: numbers, strings, arrays, objects, etc. JSON objects can be nested and the fields can be multi-valued, e.g., arrays, nested arrays, etc. A specification can be found at: http://JSON.org. Additional details are can be found in “A JSON Media Type for Describing the Structure and Meaning of JSON Documents,” IETF (Internet Engineering Task Force) draft-zyp-json-schema-03, Nov. 22, 2010, available at http://tools.ietf.org/html/draft-zyp-json-schema-03, the entire disclosure of which is hereby incorporated by reference. There are generalizations of JSON to include more types, e.g., BSON (Binary JSON). Moreover, other semi-structured formats like XML, Protobuf, Thrift, etc. can all be converted to JSON. When using XML, queries may conform to XQuery instead of SQL.
Below is an example JSON object:
The structure of semi-structured objects can vary from object to object. So, in the same baseball data, the following object may be found:
A schema describes the possible structures and data types found in a data collection. This schema includes the names of the fields, the types for the corresponding values, and the nesting relationships. Thus, the schema for the above two objects would be:
Although the above is the notation used throughout the document for illustrating schemas, a more complete specification is JSON-schema, available at http://JSON-schema.org. For example, types in the JSON-schema are generally included in quotes, as in string or “int.” For conciseness and readability in this disclosure, the quotes will be omitted.
Semi-structured objects can alternatively be viewed as trees with fields as nodes and leaves as atomic values. A path in the object or schema is a path in this tree, e.g., “player.fname”, “teams[].name”.
Iterative Schema Inference
Before a user can ask questions of a data set, they need to know the schema—i.e., what fields or dimensions are available for querying. In many cases, the analyst is not responsible for generating the data, so they are unaware of what has been recorded and available. For example, in the baseball example above, an analyst may not know that the “ERA” field was available if only hitters had been observed in the collection. So, the analysis platform computes (or, infers) a unified schema from the ingested data and presents a relational view of the schema to assist the analyst in formulating queries.
The analysis platform aims to produce a schema aimed at optimizing the precision and conciseness of the schema. Generally, precise means that the schema represents all the structures in the observed or ingested data and does not allow for structures not yet seen. Concise means that the schema is small enough that it can be read and interpreted by a human.
The general approach to dynamically creating the schema is to start with a “current” schema inferred from past objects and grow the schema as new objects are ingested. We simply merge the current schema (S_curr) with the schema (type) of a new object (0_new) to arrive at the new schema (S_new):
S_new=merge(S_curr, type(O_new))
Roughly speaking, the merging process takes the union of the two schemas, collapsing common fields, sub-objects, and arrays, and adding new ones when they appear. This is discussed in more detail below.
Objects
Some of the following examples use data that resembles the output of a data stream from Twitter, referred to as the firehose. The Twitter firehose gives a stream (unending sequence) of JSON objects that represent the tweets “tweeted” and metadata about those tweets: e.g., user, location, topics, etc.). These tweets are analogous to many other types of event log data, such as that generated by modern web frameworks (e.g., Ruby on Rails), mobile applications, sensors and devices (energy meters, thermostats), etc. Although similar to Twitter data, the following examples diverge from actual Twitter data for purposes of explanation.
Basic JSON objects are straightforward to deal with; we simply infer the types seen in the object. For instance, consider the following object:
The schema inferred from that object would be:
As new objects arrive, new fields can be added by performing a union on the set of fields. Sometimes, a field will be repeated, but its type varies, a condition called type polymorphism. The schema uses multiple attributes with the same key to represent type polymorphism.
Log formats often change and developers may add new fields, or change the field type. As a concrete example, consider the “id” field identifying the tweet, which was originally a number. However, as the number of tweets grew, certain programming languages could not handle such large numbers, and so the “id” field has been changed to a string. So, suppose we saw a new record of the form
Since a string “id” has now been seen, and a new field “retweet_count” has appeared, the schema is augmented as follows:
Notice that “id” appears twice, once as a string and once as a number. Sometimes, the structure of nested objects vary. For example, suppose we added more profile information for the user:
In that case, the platform recursively merges the “user” nested schema to get the following schema:
Null Fields and Empty Objects
Empty objects or null fields can be present in JSON records. For example, the record for a person's coordinates (latitude and longitude) might be:
Similarly, the following object
If a subsequent record has a value for the object, the empty object is filled in by applying the merge. For instance, the records:
will produce the schema
A null type is similarly replaced by an observed type. For example, the records
will produce the schema:
Tweets often contain items such as hashtags (highlighted topic words), urls, and mentions of other Twitter users. The Twitter firehose, for example, may parse and extract these items automatically for inclusion in the tweet's JSON object. In the following examples, hashtag metadata is used to illustrate how the schema for arrays is inferred.
First, let's consider extracting and recording a list of starting offsets for hashtags in the following tweet (or string):
An array in the source data is represented in the schema as an array containing the types of the elements found in the source array, in no particular order. Thus, the schema for the above object is:
One may want to include the hashtag along with the offset for later processing. In that case, the tweet object may enumerate both the hashtag and offset in the array as follows:
Alternatively, the tags and offsets could be reversed as follows:
In fact, tag text and tag offsets can be included in adjacent objects:
There are now two schemas for “tags”:
Also, note that the following schemas are identical:
This is because the list of types is treated as a set. Types for array elements are merged where possible, and merging is further performed for objects and arrays inside arrays. In various other implementations, the order of types and dependencies among types (in both arrays and objects) could be preserved. However, this may make the schema much less concise.
Nested Objects
To illustrate nested objects, suppose both beginning and ending offsets are recorded as follows:
The resulting schema is:
As shown, the objects types are merged instead of typing the array elements separately.
Similarly, in a case where the tag string and offsets are in nested arrays:
The schema further reduces to:
Empty objects and empty arrays are treated as follows. Because empty objects are filled in as described above, the following example schema reduction is possible:
Similarly, using the merging rules for arrays, the following schema reductions are made:
Merge Procedure
To create a new schema from a previous schema and a new object, the analysis platform first types (i.e., computes the schema for) the new object. This procedure is intended to specify the canonical semantics for typing, not describe any particular implementation. In the following description, the variables v, w, v_i, w_j range over any valid JSON value, while j, k, j_m, k_n range over valid strings. The base rules for typing are:
The first rule simply states that for a scalar, such as 3 or “a”, the corresponding type is inferred directly from the value itself (number for 3 or string for “a”). The second and third rules recursively type objects and arrays using the collapse function.
The collapse function repeatedly merges types of the same field in objects, and merges objects, arrays, and common types inside arrays. It continues recursively until the scalar types are reached. For objects, the collapse function is:
For arrays, the collapse function is:
The merge function describes how to pairwise combine values to remove duplicates and combine arrays/maps. For objects, merge simply calls collapse recursively to collapse common fields:
Similarly for arrays:
Nulls are preserved, such as shown here:
A JSON null is a value, just as the number 9 is a value. In a relation, NULL indicates that there was no value specified. In SQL, nulls are presented as tags<null>: boolean, where the Boolean value is True if the null exists, and NULL otherwise. To simplify the schema for a SQL user, the coordinates<null> column can be omitted if the user does not need to differentiate JSON nulls from SQL nulls.
Cumulative Example
With the above simple rules, it is possible to type deeply nested JSON records. For instance, consider a complex hypothetical record that represents page view statistics for a web page:
The following schema would be produced:
In various implementations, the JSON Schema format can be used to encode the inferred schema. This format is standardized, and can easily be extended to incorporate additional metadata (e.g., whether an object is a map). However, it is quite verbose and space-inefficient, so it is not used for the examples in this disclosure. For instance, in JSON-Schema format, the above schema is represented as follows:
Developers and analysts can use JSON objects and arrays for many different purposes. In particular, JSON objects are frequently used both as objects and as “maps.” For example, a developer might create an object, where the fields are dates and values are collected statistics like page views. Another example is when fields are user ids and values are profiles. In these cases, the object is more like a map data structure rather than a static object. A user does not always know the possible fields names because there are so many of them, and the field names are dynamically created. As a result, users may want to query fields in the same way they query values.
To support this use, the analysis platform is able to identify maps. The analysis platform incorporates heuristics to identify maps, and also allows users to specify which nested objects should and should not be treated as maps. Tagging objects as maps is called adornment.
Generally, adornment is performed after the initial load—that is, it is not necessary to identify maps on the initial ingest. Adornment can be performed later on a second pass, or after more data has been ingested. In addition, maps can be reverted back to simply objects, if needed.
By default, JSON objects are treated as objects (or, structs, in C nomenclature). This can be explicitly indicated in the JSON Schema by annotating an object with “obj_type”: object. The shorthand notation used in examples below is O{}.
To flag maps, the heuristic looks for fields that as a group occur relatively infrequently compared to their containing object (container). For maps, the shorthand M{} is used.
While computing the schema on the first pass, the frequency that fields occur is tracked. Consider an object (or nested-object) which occurs with frequency F in the data set. Let v_i be the frequency of field i in the object, and N be the number of unique fields of the object (irrespective of its type). The ratio (sum(v_i)/N)/F is the ratio of the average field frequency to the frequency of the container. If this ratio is below a threshold, such as 0.01, which may be user-configurable, then the containing object is designated as a map. In various implementations, empty objects in the JSON Schema are treated as maps.
After the schema of the JSON objects in the source data set is inferred, the analysis platform produces a relational schema that can be exposed to SQL users and SQL-based tools. The goal is to create a concise schema that represents the containment relationships in the JSON schema, while giving the users the power of standard SQL. This relational schema is produced from the adorned JSON schema, and is a view over the underlying semi-structured data set. A few examples of how a JSON schema is converted to a relational view are presented here, before discussing a generalized procedure for performing the conversion.
Objects
The simplest example is an object with simple scalar types, such as the following schema:
In this case, the fields of the object translate directly into columns of a relation:
The relation (or, table) of the top-level object is called “Root” here, although it can be replaced by, for example, the name of the source collection, if such a name exists. In the interest of space and readability, the type names string, number, and boolean have been shortened to str, num, and bool.
The type can be added to the attribute name in order to support type polymorphism. For instance, consider the following schema:
The resulting relational schema would then have separate “id” and “id” columns:
Nested Objects
Nested objects produce new relations with foreign-key relationships. For instance, consider the JSON schema:
The corresponding relational schema is
The nested object is “normalized” into a separate relation named by its path, “Root.user” in this case. The column “Root.user”.“id_jk” in the new table that represents the sub-object is a foreign-key for the column “Root.user” (“user” column in the table “Root”). The type is specified as “joinkey” to distinguish it from other columns, but in actual implementations, the join_key type is typically an integer.
Objects can be nested several levels deep. For example, retweet objects may include a retweeted status object, which includes the profile of the user that retweeted, resulting in the following schema:
The corresponding relational view is:
Note that “Root.user”, “Root.retweeted_status”, and “Root.retweeted_status.user” are all separated into different tables.
Optimizing 1-to-1 Relationships
In nested object relationships, often there is a 1-to-1 relationship from rows in the main table to the rows in the table for the nested object. As a result, these can be collapsed 1-to-1 into a single table using dotted notation for the column names.
For example, the multi-relation examples above flatten into:
and, for the three-level nested object example,
Note that, since the relational schema is simply a view over the JSON schema, flattened, partially flattened, or separate (un-flattened) relational schema can be presented to the user as desired by the analysis platform without modifying the underlying data. The only limitation is that the user not be presented with conflicting table definitions.
Maps
Without designating a set of fields as a map, the corresponding relational schema may include a huge number of columns. In addition, the user may want to query the field names; for example, they may want to find the average page views in December.
To solve these issues, the tables for (nested) objects that are adorned as maps can be “pivoted.” For example, consider the following schema for keeping track of various metrics (daily page views, clicks, time spent, etc.) for each page on a web site:
Rather than producing a table with a separate column for each day, the fields and values can be stored as key-value pairs in a relation:
In this case, the id column is a foreign key; indicating within which record each map entry was originally present. For a year's worth of page views, instead of having 365 columns in table “Root.metric”, there are only two. The “key” column stores the field names and the “val” column stores the values. For example, for the above schema, the database may contain these records for “www.noudata.com/jobs” (page_id 284):
Pivoting still works when there is type polymorphism in the map. For example, suppose the metric represents sentiment, which contains both a category and a score indicating the strength of the category:
The JSON schema would be:
When creating the relational schema, a new “val” column can be added to the map relation to include the new type. The other “val” columns can be appended with their types as well to distinguish the column names, as shown:
The entries resulting from the above JSON object would appear as:
Once these maps are pivoted, users can apply predicates and functions to the key column as they would any other column.
Nested Maps
The basic principles are the same for nested maps. Consider a list of statistics per day and per hour:
The resulting schema would be
Objects can also be nested inside maps:
The resulting flattened relational schema is:
Empty Elements
Empty objects sometimes appear in the data. Consider the schema:
A JSON object may be received without user information, as shown here:
The empty user object can be represented with the following relational tuples:
If all ingested user objects had an empty object in the ingested stream, the resulting JSON schema would include an empty object. For example, see the final field (“user”) in this schema:
Note that Root.user<map> does not have any value columns, and initially is empty. However, this design makes it straightforward to add columns later if the schema changes as new objects are ingested, because each record in Root will have already been assigned a join key.
Arrays
Arrays are treated similarly to maps, so the schema translation is quite similar. The major difference is that the string “key” field of a map is replaced by an “index” field of type integer (int) corresponding to the array index. A simple example is:
Type polymorphism and nested arrays work the same way as for maps. Consider the following schema:
An object may be nested within in an array, as here:
Using the 1-to-1 flattening optimization, the relational schema becomes:
Nested and Empty Arrays
Relational schemas can be created for nested and empty arrays in a similar manner to maps. For the following schema:
Note that, for the nested array, a separate table is created with “val” appended to the table name. For the empty array, a separate table is created with only an “index” column, but no “val” column, which can be added later once the contents of the array are observed and typed.
Type Inference on Atomic Values
The above type inference and conversion to relational schema procedure relies on the basic types available in JSON. The same procedure applies equally to whatever type system is selected. In other words, the analysis platform can infer narrower scalar types like integer, float, and time, as long as the atomic scalar types can be inferred from the value. BSON and XML have such extended type systems. Moreover, various heuristics (such as regular expressions) can be used to detect more complex types such as dates and times.
Since ANSI SQL does not support the same types as JSON, the inferred types are converted into the most specific types seen thus far for the relational view. For example, if only integers have been seen for field “freq”, then the number type will be converted to integer in the relational schema for “freq”. Similarly, if both integers and floats have been observed, then the relational schema will show the “freq” column as a float. Likewise, string fields convert to character varying types in the relational schema. In other words, the more specific types than basic JSON types may be tracked.
An alternative is to rely on type polymorphism and use the more specific type system to infer the data value's types. That is, instead of using JSON primitive types, use ANSI SQL's primitive types.
Below are the list of types tracked during ingestion (on the left) and how they are converted for the SQL schema (on the right). Most SQL databases support additional types including text which can be used if desired by the client. Note: the ObjectId type is specific to BSON.
Procedure
Converting from a JSON schema to a relational schema can be accomplished using a recursive unpacking of the nested JSON schema structure. A pseudocode representation of an example implementation is shown here.
The above procedure will create the relational schema without the 1-to-1 optimization. A second pass may be performed through the relational schema, identifying object tables with 1-to-1 relationships and collapsing them. Alternatively, the 1-to-1-optimization could be performed inline, but this was not shown for clarity. When a sub-tree of the schema with nested objects is not “interrupted” by arrays or maps, then the entire object sub-tree can be collapsed into a single table with attributes named by their path to the root of the sub-tree. An attribute that is a map or object remains in a separate table, but any sub-objects contained within can be collapsed recursively. These principles apply to any arbitrary depth of nested objects.
Once the JSON and relational schemas have been updated in response to a new object, the data contained within the object can be stored in indexes, as described below.
The indexes in the analysis platform rely on order-preserving indexes that store key-value pairs. The indexes support the operations: lookup(prefix), insert(key, value), delete (key), update(key, value), and get_next( ) for range searches. There are a number of data structures and low-level libraries that support such an interface. Examples include BerkeleyDB, TokyoCabinet, KyotoCabinet, LevelDB, and so on. These internally use order-preserving, secondary store data structures like B-trees, LSM (log-structured merge) trees, and Fractal trees. There may be special cases where non-order-preserving indexes (such as hash tables) are used, such as for object IDs. With non-order-preserving indexes, get_next( ) and the ability to do range searches may be sacrificed.
In various implementations, the analysis framework uses LevelDB, which implements LSM trees, does compression, and provides good performance for data sets with high insert rates. LevelDB also makes performance trade-offs that may be consistent with common use models for the analysis framework. For example, when analyzing data such as log data, data will be frequently added, but existing data will be infrequently, or, never, changed. Advantageously, LevelDB is optimized for fast data insertion at the expense of slower data deletion and data modification.
Order-preserving indexes have the property that they collocate the key-value pairs in key order. Thus, when searching for key-value pairs nearby a certain key or retrieving items in order, the responses will return much faster than when retrieving items out of order.
The analysis platform can maintain multiple key-value indexes for each source collection, and in some implementations, between two and six indexes for each source collection. The analysis platform uses these indexes for evaluating SQL queries over the relational schema (the SQL schema does not need to be materialized). Each object is assigned a unique id denoted by tid. The two indexes from which the other indexes and the schemas can be reconstructed are the BigIndex (BI) and ArrayIndex (AI).
BigIndex (BI)
The BigIndex (BI) is the base data store that stores all fields in the data that are not embedded in an array. A value (val) can be retrieved from the BI by a key based on col_path and tid.
The col_path is the path to the field from the root object with the field's type appended. For example, for the following records:
the following key-value pairs are added to the BI:
in various implementations, the underlying index store (such as LevelDB) is unaware of the significance of the segments of the key. In other words, while “root.text<str>, 1” signifies the first element of the string text field in the root table, the index store may simply see an undifferentiated multi-character key. As a simple example, the key could be created simply by concatenating the col_path and tid (importantly, in that order). For example, the first key demonstrated above may be passed to the index store as “roottext<str>1.” The index store will collocate the second key (“root.text<str>2”) with the first key not because of any understanding of the path similarity, but simply because the first 14 characters are the same. Even though the column name and type are stored as part of every key, because of the sort ordering, compression (such as prefix-based compression) can be used to reduce the storage cost.
In the BI, all columns of the source data are combined into a single structure, unlike traditional column stores which create a separate column file for every new column. The BI approach allows for a single index instance and also enables map detection to be delayed. Since new fields simply appear as entries in the BI, failing to pivot a map does not incur the physical cost of creating a large number of physical files for each field later turned into a map.
In the BI, the key-value pairs for each attribute or “column” are collocated. Thus, like column files, the BI allows the query executor to focus on the fields of interest in a query rather than forcing it to sweep through data containing fields not referenced in a query.
ArrayIndex (AI)
Although fields from the normalized tables for arrays could be added to the BI, the array indices would then be from their corresponding values. Instead, array fields can be added to a separate ArrayIndex (AI) that preserves the index information and allows entries in the same array to be collocated by the index store, which provides good performance for many queries. The array values can be stored in the AI using the following signature:
The col_path is the path of the array field: for example, “root.tags” for elements in the tags array, or “root.tags.text” for the “text” field in an object inside the tags array. The join_key and index are the array's foreign key and index of the value. The tid is also stored, to avoid having to store a separate entry in the BI for each array. The tid can be used to look up values for corresponding columns in the same object. Consider the objects that represent hashtags in different tweets:
For these, the tags table has the following schema:
The array index allows for quickly iterating through the values of array fields. This is useful, for example, when running statistics over these fields (e.g., sum, average, variance, etc.), finding specific values, etc.
Nested Array Example
Note that, for arrays in the root object (top-level arrays), the tid and join_key fields are redundant (see above) and can be optimized away. However, for nested arrays, a separate join_key is needed and not superfluous. For example, consider this JSON object:
The corresponding relational schema is:
Recall that the AI uses the following key-value pair
Note that if the join key were removed from the nested array key-value pairs, then it would not be possible to know whether muffins was part of the first nested array or the second. Thus, the join key is redundant for a top-level array, but not for cases of nested arrays.
Array Index 2 (AI2)
Although these two indexes (BI and AI) are sufficient to reconstruct all the ingested data, there are access patterns that they do not support efficiently. For these, we introduce the following indexes, which can optionally be created to improve performance at the cost of additional space.
This has the signature:
The map index is similar to the array index in its functionality and signature:
The primary difference is that the map index is not built during initial ingestion, and is instead constructed asynchronously. During initial loading, maps will be treated as objects and inserted into the BI as usual. Once both are populated, there are entries available in both the BI and MI for more efficient query processing. The BI entries remain relevant in case a user or administrator requests that the map be unadorned. Only the relational schema needs to be changed, and the original BI entries corresponding to the unmapped data will then be used in queries.
Like the AI, the MI is useful when iterating through the elements of a map: for applying statistical functions, for restricting to specific field names, etc. Consider again objects that maintain pageview statistics:
The relational schema for the page_views table if flagged as a map is:
This ordering allows the values in the page_views map to be collocated for each page, while in the BI, the values would be collocated by date.
Map Index 2 (MI2)
In addition, an auxiliary map index may be implemented. The map index is similar to the array index in its functionality and signature:
Although the above indexes are useful for looking up values for specific fields and iterating through those values, they do not allow fast access if queries are looking only for specific values or ranges of values. For example, a query may ask to return the text of tweets written by “mashah08”. To assist such queries, a ValueIndex can be built for some or all fields in the schema. The ValueIndex may be built as data is ingested or be built asynchronously later. The key for the value index is:
For example, the tweets:
are stored as:
Using the VI, one can search for all tweets authored by “mashah08” by looking for the key: (root.user.screen_name, “mashah08”) and retrieving all associate tids. Then the BI can be searched using the retrieved tids to return the corresponding text of each tweet.
The cost of indexes, and especially the value index, is the additional storage space, and the execution time needed to update them as new objects are added to the system. Due to space or update overheads, the user may not want to index all possible paths because of these. So, the user can specify which paths to index in the VI.
RowIndex (RI)
To facilitate re-creation of an entire ingested object (similar to requesting a record in a traditional row-based store), a RowIndex (RI) can be implemented. The RowIndex stores a key-value pair
The JSON object may be stored as a string representation, as a BSON, or as any other serialized format, such as a tree structure used for internal representation of a JSON object. For the two tweets discussed above with respect to the VI, the corresponding RI entries would be:
An example for the BI, AI, MI, and VI. Consider tweets similar to the above, where a “retweet_freq” attribute is added, which keeps track of how many times a tweet was retweeted in a day:
The schema for these records is:
The JSON-Schema for these records will be
If retweet_freq is not treated as a map, the relational schema is:
In this case, the example records above would populate these relations as follows:
Note that these are the tuples the queries would return if a “select *” query were run on these tables. These tuples are not necessarily materialized as such in the storage engine. That is, this may simply be a virtual view over the underlying data, and not physically stored as depicted.
If retweet_freq is identified as a map, the relational schema becomes more concise (and more accommodating of additional data), as follows:
The corresponding tuples are:
The key-value pairs added to the BI are:
The key-value pairs added to the AI are as follows. Note that in this case, the join key is redundant (same as tid) since there are no nested arrays.
The RI will have the following two entries
If and when it is built, the MI will have the following entries:
Similarly the VI will have the following entries (if all paths are indexed and maps are treated like maps):
Although the actions above are described in phases, they can be pipelined to allow the ingest to be performed in a single pass, loading the BI, AI, and RI, and computing the JSON schema. The other indexes can be built asynchronously and can be enabled and disabled as desired.
The analysis platform is architected to be service-oriented. In various implementations, there are five main services: a proxy, a metadata service, a query executor, a storage service, and an ingestion service.
This decoupled approach may have several advantages. Since these services communicate only through external APIs (remote procedure calls), the services can be multiplexed and each shared independently. For example, multiple proxies may be used per executor and multiple executors per storage service. The metadata service can also be shared across multiple instances of executor and storage services.
The executor, storage, and ingestion services are parallelized, and can run the individual pieces in virtualized machine instances in either private or public infrastructures. This allows suspending and scaling these services independently. This is useful for reducing costs by adjusting service capacity based on fluctuations in demand. For example, the elasticity of a public cloud can be used to highly parallelize the ingestion service for fast overnight loading, while keeping the execution and storage service reduced in size for daily query workloads.
The proxy is the gateway to clients and supports one or more standard protocols, such as ODBC (Open Database Connectivity), libpq, JDBC (Java Database Connectivity), SSL (secure sockets layer), etc. The gateway serves as a firewall, authentication service, and a locus of control for the internal services. For example, client connections (such as network sockets) can be kept open at the proxy while the supporting execution and storage services are suspended to save costs. When the client connection becomes active again, the needed services can be woken on-demand with a relatively short start-up latency.
The metadata service is typically shared by many instances of the other services. It stores metadata including schemas, source information, partitioning information, client usernames, keys, statistics (histograms, value distributions, etc.), and information about the current state of each service (number of instances, IP addresses, etc.).
The storage service manages indexes and serves read and write requests. In addition, the query executor can push down a number of functions into the storage service. In various implementations, the storage service can evaluate predicates and UDFs (user defined functions) to filter results, evaluate local joins (e.g., to reconstruct objects), evaluate pushed-down joins (e.g., broadcast joins), and evaluate local aggregations.
The storage service can be parallelized through a technique called partitioned parallelism. In this approach, numerous instances or partitions of the storage service are created and the ingested objects are divided among the partitions. Each partition stores each type of index, just as if it were a single whole instance. However, each partition only indexes a subset of the ingested data.
The analysis engine supports one or more partitioning strategies. A simple but effective strategy is to partition the objects by tid and store their respective entries in the local indexes. In this way, ingested objects are not split across different instances, which may consume significant network bandwidth when a query relies on multiple portions of an object. The tid can be assigned in a number of ways, including hash assignment, round robin, or range-based assignment. These particular assignments distribute the most recent data across all the instances, thereby spreading the load.
Another strategy is to partition by another field value (or combination of field values), such as a user id or session id. Alternate partitioning fields (columns) make it convenient to perform local joins with other tables or collections, e.g., user profiles. The partitioning strategy may be hash partitioning or use sampling and range partitioning. The former is used for efficient point lookups and the latter for supporting efficient range searches.
Regardless of the partitioning strategy, an object or any subset of the object should be able to be reconstructed locally. Therefore, the storage service partitions have no cross talk during query processing and only need to communicate with the execution service via their API.
The storage service has a cache. We can increase the cache size in each partition or increase the number of partitions to improve the performance of the storage service. The storage service can cache the indexes in memory or on local disk, and the indexes can live on external storage like Amazon S3. This feature allows for shutting down and destroying the storage service nodes and redeploying them whenever necessary. Moreover, it allows extreme elasticity: the ability to hibernate the storage service to S3 at low cost and change storage service capacity as demand fluctuates.
The query execution service executes the query plan generated by the query planning phase. It implements query operators, e.g., join, union, sort, aggregation, and so on. Many of these operations can be pushed down to the storage service, and are when possible. These include predicates, projection, columnar joins to reconstruct the projected attributes, and partial aggregations for distributive and algebraic aggregation functions with group by statements.
The query execution service takes in data from the storage service and computes the non-local operations: non-local joins, group by statements that need repartitioning, sorts, and so on. The executor is similar to a partitioned parallel executor. It uses exchange operators to repartition between query execution steps and employs local storage for spilling intermediate results. For many queries, it is possible to run most of the query in the storage service and require only a single executor node to collect the results and perform any small non-local operations.
The ingestion service is responsible for loading semi-structured data into the storage service where it can be queried. Users provide data in a variety of formats (e.g., JSON, BSON, CSV) from a variety of platforms (e.g., MongoDB, Amazon S3, HDFS), optionally compressed with a compression mechanism (e.g., GZIP, BZIP2, Snappy). The basic procedure holds true regardless of the format used.
The ingestion task can be roughly divided into two parts: the initial ingestion task that loads a large volume of new user data, and incremental ingestion, which occurs periodically when new data is available.
Initial Ingestion
The initial ingestion process can be broken into several steps. First, partition input data into chunks. Users provide initial data in a collection of files or by providing direct connections to their data sources. The location and format of these files is recorded in the metadata service. Users may provide data that is already partitioned, for instance due to log file rotation, but if not, the files can be partitioned into chunks to support parallel loading. These chunks are typically on the order of several hundred megabytes and are processed independently.
The exact mechanism for partitioning the input files depends on the data format. For uncompressed formats in which records are separated by newlines, (e.g., JSON or CSV), a single file can be processed in parallel using a number of processes equal to the target number of chunks. Processing starts at the appropriate offset in the file (file_size/total_num_chunks)*chunk_num, and then searching until a newline is found. For compressed data or data in a binary format like BSON, each input file may need to be scanned sequentially. The location of each chunk (file, offset, size) is stored in the metadata service.
Once the data is divided into chunks, the actual schema inference and ingestion is performed. As part of this process, two services are launched: the ingestion service and the storage service. These two services can employ multiple servers to do the work. The two services can also be co-located on any given machine. The ingestion service is transient and used only during the ingestion process, while the storage service holds the actual data and must be persistent. The servers involved in ingestion send data to the storage service servers and the number of ingestion servers is independent of the number of storage servers where the number is chosen to minimize imbalance between the throughput of each service. The chunks are partitioned between the ingestion servers. Each ingestion server is responsible for the following steps for each chunk assigned to it: (i) parsing and type inference, (ii) communication with storage service, and (iii) computing local schema and statistics.
First, the data record is parsed into an internal tree representation. A consistent internal representation may be used for all the source formats (JSON, BSON, etc.). Depending on the input format, type inferencing may also be performed. For instance, JSON does not have a representation of a date, so it is common to store dates as strings. Since dates are very common, they are on example of a type detected during ingestion so that users can issue queries making use of dates. For CSV input files, since the columns are not typed, basic types such as integers must be detected as well.
Once the record has been parsed and types inferred, a compressed representation of the parse tree is sent to the storage service. This takes the form of a preorder traversal of the tree. The storage service is responsible for determining the values to store in each of the indexes (BI, AI, etc), and for generating tuple ids and join keys. Key generation is deferred to the storage service so that keys can be generated sequentially, which improves ingestion performance to the underlying index store.
As records are ingested, a local JSON schema is updated using the rules described above. The schema will reflect the records seen by a single ingestion machine, and different machines may have different schemas.
In addition to computing the schema, statistics are maintained, which are useful for query processing as well as identifying maps. These include metrics like the number of times each attribute appears as well as its average size in bytes. For example, the following records
would produce the schema {id: int, id: string}, and id: int could be annotated with a count of 3 and id: string with a count of 2. Each ingestion machine stores the schema and statistics it computed in the metadata service.
Once all of the chunks have been ingested, the overall schema is computed, which will be used by the query engine and presented to the user. This can be accomplished using a single process that reads the partial schemas from the metadata service, merges them using the method described above, and stores the result back in the metadata service. Since the number of schemas is limited to the number of ingestion machines, this process is not performance-critical.
Determining maps is optional. As described previously, heuristics can be used along with the statistics stored in the metadata service to determine which attributes should be stored as maps in the MI. Recall that this is not necessary for query processing, but it makes some queries more natural to express and improves efficiency. Once maps have been identified, each storage server receives a message identifying which attributes should be maps. The storage server then scans these columns and inserts them into the MI.
Incremental Updates
Some users may load the bulk of their data up front, but most will periodically load new data over time, often as part of a regular (e.g., hourly or daily) process. Ingesting this data is largely similar to the initial ingestion. The new data is split into chunks, the schema is computed per chunk, and the local schemas are merged with the global schema maintained in the metadata service.
The system automatically detects new data as it is added. The method depends on the source data platform. For example, for S3 files, the simplest case is to detect changes in an S3 bucket. A special process periodically scans the bucket for new key-value pairs (i.e., new files), and adds any that are found to the metadata service. After a certain number of new files have been found or a certain time period has elapsed, the process launches a new ingestion process to load the data.
Operations performed in MongoDB can be stored in a special collection called the operation log (or oplog). The oplog provides a consistent record of write operations that is used by MongoDB internally for replication. The oplog is read and used to create a set of flat files in S3 storing the new records. The above method can then be used to ingest the new data.
The incremental ingestion process can handle both new data (e.g. new JSON documents) and updates to existing documents (e.g. new attributes in existing JSON documents or new values for existing attributes). Each data source platform has different capabilities in terms of exposing updates in the source files. We refer to this type of information as ‘deltas’ and it can take the form of flat files or log files (e.g. MongoDB). The incremental ingestion process processes the information from the ‘delta’ files and combines that with the existing schema information to generate new data that are sent to the storage service.
Subsetting Data
While the system described here for ingesting data and doing incremental updates can ingest all data from the source, it is relatively simple to ingest only a subset, by specifying up-front the JSON schema (or the relational schema) of the data that we would like ingested. This is done by either providing the JSON schema itself, or by providing queries that specify the subset. In this manner, the analysis platform can be thought of as a materialized view of the source data.
It is also possible to specify data that the user does not want ingested. A JSON schema or a relational schema can be provided, describing the portion of the data that should not be ingested. Then it is simply a matter of recording that information in the metadata service which tells the ingestion process to simply skip those elements of all future rows. If this is done after data has already been ingested, the already ingested data simply becomes unavailable and can be garbage collected by a background task. This garbage collection would be incorporated into the compaction process of the index store (e.g., LevelDB).
Fault Tolerance
While it is possible to restart the loading process during the initial ingest, the incremental ingestion process should not corrupt the existing data in the system, to prevent users from having to reload all data from scratch. Since ingesting a file is not an idempotent operation, due to id generation, a simple fault-tolerance scheme can be implemented based on taking snapshots of the underlying storage system.
Taking snapshots may be straightforward when the underlying storage system supports taking consistent snapshots at a point in time, as LevelDB does. With this primitive, the steps for incremental loading are as follows. A single process directs each storage server to take a snapshot locally and directs all queries to this snapshot for the duration of the load. Each chunk is loaded as described above. When complete, the ingestion server responsible for loading a chunk marks it as finished in the metadata service.
A process monitors the metadata service. When all chunks have been loaded, it atomically redirects queries to the updated version of the state. The snapshot taken in the first step can then be discarded. In the event of a failure, the snapshot becomes the canonical version of the state and the partially updated (and potentially corrupted) original version of the state is discarded. The ingestion process is then restarted. Additionally, snapshots of the storage system disk volume can be used for recovery in the event of a server failure.
Example Query
To show example execution, consider the simple query:
Execution node then makes RPC calls to storage service nodes, pushing down t.a>10 predicate and count function. Next, storage nodes compute sub-counts and return them to executor node. Executor node then returns result to the proxy when proxy fetches the next result value.
Dynamic Typing
The storage engines of database systems (e.g., PostgreSQL) are strongly typed, which means that all the values of a column (or attribute) must have the exact same type (e.g., integer, string, timestamp, etc.). In the context of big-data analytics this is a significant limitation because quite often applications need to change the representation of a particular piece of information (attribute) and, consequently, the data type that they use to store it. For instance, an application may initially store the values of a particular attribute using integers and then switch to using floats. Database systems are not designed to support such operations.
One way to handle this problem is to use multiple relational columns for each attribute—one for each different data type. For example, if we have seen the attribute “user.id” with values 31432 and “31433” (i.e., an integer and a string), we can store “userid<int>” and “userid<string>” as separate columns. A single record will have a value for only one of these columns corresponding to the type of “user.id” in that record. The values for the other columns for that record will be NULL.
Presenting multiple columns for the same attribute is often too complicated for users to use. To simplify the user experience, the analysis platform can dynamically, at query time, infer the type the user intends to use. To this end, the storage service keeps track of multiple types. For example, the storage service uses a generic data type for numbers, called NUMBER, which covers both integers and floats. When the NUMBER type is used, the more specific data type is stored as part of the value. For example, the integer value 10 of attribute “Customer.metric” is stored in the BI as a key-value pair where (Customer.metric, <NUMBER>, tid) is the key and (10, INTEGER) is the value. The floating point value 10.5 of the same attribute would be stored as key: (Customer.metric,<NUMBER>, TID), value: (10.5, FLOAT).
Finally, at query time, the analysis platform can perform dynamic casting between data types according to the properties of the query (predicates, casting operations, etc.) as long as these operations do not result in information loss. Although “number” is not an ANSI SQL type, the flexible typing system allows clients to treat it as a standard ANSI SQL float, integer, or numeric type from query context. For example, consider the query:
Although ANSI (American National Standards Institute)/ISO (International Organization for Standardization) SQL:2003 is mentioned as an example, in other implementations compliance with other standards, SQL or otherwise, can be accomplished. For example only, the exposed interface could be compliant with ANSI/ISO SQL:2011.
In
The servers 112 may also have their own storage on which the processing capability operates. For example, the servers 112 may implement both the query executor and the storage service. While traditional columnar storage systems store data as columns on disk, when that data is read into memory, rows are reassembled from the columnar data. The indexes of present disclosure, however, operate as columnar storage both on disk and in memory. Because of the unique configuration of the indexes, benefits of fast columnar access can be achieved with relatively little penalty.
A storage cloud 116 includes storage arrays 120 used for index data because according to the present disclosure data is stored in indexes and not in materialized tables. When storage resources of the servers 112 are used the storage arrays 120 may be used for backup and nearline storage, not for responding to each query.
In various implementations, storage arrays 124 may include data on which the analysis framework will operate. For example only, the storage arrays 124 may hold relevant data, such as log data, which users may want to query using the analysis framework. Although storage arrays 120 and storage arrays 124 are shown in the same storage cloud 116, they may be located in different clouds, including private externally hosted clouds, public clouds, and organization-specific internally-hosted virtualized environments.
For example only, the storage cloud 116 may be an Amazon Web Services (AWS) S3 cloud, which the business was already using to store data in the storage arrays 124. As a result, transferring data into the storage arrays 120 may be achieved with high throughput and low cost. The compute cloud 108 may be provided by AWS EC2 in which case the compute cloud 108 and the storage cloud 116 are hosted by a common provider. A user 130 constructs a query using standard SQL tools, that query is run in the compute cloud 108, and a response is returned to the user 130. The SQL tools may be tools already installed on a computer 134 of the user 130, and do not have to be modified in order to work with the present analysis framework.
In
The server appliance 180 retrieves and stores index data for responding to queries of the user 130. The storage cloud 116 may include additional data sources 188, which may hold yet other data and/or may be a nearline data storage facility for older data. The server appliance 180 may, in order to satisfy user queries, retrieve additional data from the additional data sources 188. The server appliance 180 may also store data, such as for backup purposes, in the storage cloud 116. In various other implementations, the additional data sources 188 may be part of a Hadoop implementation in the cloud.
The analytical framework of the present disclosure is flexible such that many other deployment scenarios are possible. For example only, software may be provided to a business, and that software could be installed on owned or hosted servers. In another implementation, virtual machine instances may be provided, which can be instantiated through virtualization environments. Still further, the user could be provided with a user interface in a browser and the SQL portion could be hosted by a service provider, such as Nou Data, and implemented on their systems or in the cloud.
In
Using the data warehouse 192 may provide a variety of benefits. For example only, the data warehouse 192 will generally have a mature and full-featured query processing layer and ODBC interface. Further, the data warehouse 192 may be a central repository for other data than would be ingested by a system according to the present disclosure. In addition, the data warehouse 192 may implement snapshotting and revision control of data, and may also be part of an established backup strategy.
In various implementations, the data warehouse 192 may simply be a relational database, such as one that supports a subset or the full set of SQL commands, including PostgreSQL, MySQL, Microsoft SQL Server, Oracle, etc. Because the schema of the ingested data may change over time, implementing the data warehouse 192 using columnar storage may allow for additional columns (such as a new attribute or a new type of an existing attribute) can be added efficiently.
In traditional database systems, which are row-oriented, adding columns may be time- and/or space-inefficient. Various implementations of the data warehouse 192 may have columnar features, including products from Vertica, Greenplum, Aster/Teradata, and Amazon (RedShift). Some implementations of the data warehouse 192, such as Vertica and Amazon RedShift, support parallel loading so that properly-formatted data can be ingested from several sources simultaneously. By packaging data into multiple intermediate files, the time required to load data into the data warehouse 192 may be significantly reduced.
Implementing the data warehouse 192 in the cloud 196 may offer various advantages, such as reducing up-front costs associated with purchasing hardware and software for the data warehouse 192. In addition, the cloud 196 serving the data warehouse 192 may be able to ingest data from the index storage 120 or the data source 124 with a greater throughput that might be available via public portions of the Internet 104. In various implementations, such as when the data warehouse 192 is Amazon RedShift and the index storage 120 is stored in Amazon S3, data may be transferred between the index storage 120 and the data warehouse 192 without leaving Amazon's network. This may allow for reduced latency and increased throughput.
In
Input/output functionality 224 may include inputs such as keyboard and mouse, and outputs such as a graphic display and audio output. The server 200 communicates with other computing devices using a networking card 228. In various implementations or at various times, the input/output functionality 224 may be dormant, with all interaction between the server 200 and external actors being via the networking card 228. For ease of illustration, additional well-known features and variations are not shown, such as, for example only, direct memory access (DMA) functionality between nonvolatile storage 216 and memory 208 or between the networking card 228 and the memory 208.
In
An administrator 308, which may be the user 130 operating in a different capacity, is able to designate guidelines for implementing these wrapper functions. The administrator 308 can also designate which of the data sources 300 to use and what data to retrieve from those data sources. In various implementations, retrieving the data may include subsetting operations and/or other computations. For example only, when one of the data sources 300 is Hadoop, a MapReduce job may be requested prior to retrieving the data for the analysis framework.
The retrieved data is processed by a schema inference module 312, which dynamically constructs the schema based on the observed structure of received data. The administrator 308 may have the ability, in various implementations, to provide typing hints to the schema inference module 312. For example, the typing hints may include requests to recognize particular formats, such as dates, times, or other administrator-defined types, which may be specified by, for example, regular expressions.
The data objects and the schema generated by the schema inference module 312 are provided to an adornment module 316 as well as an index creation module 320. Input objects include source data as well as metadata that describes the source data. The source data is stored in index storage 324 by the index creation module 320.
The adornment module 316 identifies maps in the schema generated by the schema module 312. In implementations where map identification is not desired, the adornment module 316 may be omitted. The administrator 308 may be able to specify map criteria to adjust the heuristics performed by the adornment module 316 used in identifying maps.
After maps have been identified, a relational schema creation module 328 generates a relational schema, such as an SQL-compliant schema. In addition, the identified maps are provided to an auxiliary index creation module 332, which is capable of creating additional indexes, such as the MapIndex, and map entries in the ValueIndex, as described above. The auxiliary indexes may also be stored in the index storage 324.
The administrator 308 may have the capability of requesting that the map index be created and may specify which column to add to the value index. In addition, the administrator may be able to specify which objects should be treated as maps, and can dynamically change whether an object is treated as a map or not. Such a change will result in changes to the relational schema.
A relational optimization module 336 optimizes the relational schema to present a more concise schema to the user 130. For example, the relational optimization module 336 may identify one-to-one relationships between tables and flatten those tables into a single table, as described above. The resulting relational schema is provided to a metadata service 340.
A query executor 344 interfaces with the metadata service 340 to execute queries from a proxy 348. The proxy 348 interacts with an SQL-compliant client, such as an ODBC client 352, which is, without special configuration, able to interact with the proxy 348. The user 130 uses the ODBC client 352 to send queries to the query executor 344 and to receive responses to those queries.
Via the ODBC client 352, the user 130 can also see the relational schema stored by the metadata service 340 and construct queries over the relational schema. Neither the user 130 or the administrator 308 are required to know the expected schema or help create the schema. Instead, the schema is created dynamically based on the retrieved data and then presented. Although the ODBC client 352 is shown, mechanisms other than ODBC are available including JDBC, and direct postgres queries. In various implementations, a graphical user interface application may facilitate ease of use of the ODBC client 352 by the user.
The query executor 344 operates on data from a storage service 356, which includes the index storage 324. The storage service 356 may include its own local storage processing module 360, to which the query executor 344 can delegate various processing tasks. The processed data is then provided by the storage processing module 360 to the query executor 344 to construct a response to a received query. In a cloud-based implementation, the storage service 356 and the query executor 344 may both be implemented in a compute cloud, and the index storage 324 can be stored in the compute instances. The index storage 324 may be mirrored to nearline storage, such as in the storage cloud 116 as shown in
In
In
In
As the schema monitoring module 380 is informed of changes to the schema by the metadata service 340, the schema representation module 378 may update the schema by inserting new attributes, new sub-attributes, etc. For example, new nodes may be added to a tree, including new intermediate nodes and new leaf nodes. As the schema changes, leaf nodes may be converted into intermediate nodes and changes in type of an attribute may be reflected visually with a color, a label, or a secondary indication. For example only, the secondary indication may be revealed when hovering a cursor (when using, for example, a mouse or trackpad) over the attribute.
As changes are made to the schema, the display module 382 may attempt to keep a central focus of the currently displayed schema in the center of a display area. For example only, if many new attributes are added to the beginning of a listed schema, the previously listed attributes may be shifted down on the screen or even off of the screen. To counter this visually disruptive change, the display module 382 may scroll the list of attributes to maintain an approximately constant central location. Added elements to the schema may be represented visually, such as with outlining, shadowing, color, font (bolding, italicizing, or type size).
For example only, a color gradient may indicate how recently a schema element was changed. For example only, a very bright blue may indicate a schema element that was recently changed while the color blue will fade, eventually reaching white, to indicate schema elements that have been present for a longer period of time.
In various implementations, the display module 382 may track mouse movement, keyboard usage, which windows in the operating system have focus, and whether the display has been blanked to save power in order to determine when the user has been focused on the elements of the display module 382. For example, if the display module 382 determines that the user has not been interacting with the display module 382 for the last hour, the display module 382 may retain all schema elements added in the last hour in bright blue. Once the user begins interacting with the display module 382 once more, the color blue may then start to fade. In this way, changes to the metadata since the user last interacted with the display module 382 will be brought to their attention regardless of whether they have been actively monitoring the display module 382.
The user interface 376 also includes a results representation module 384, which displays results of one or more queries. The results may be displayed in a combination of textual and graphic form, including tables, charts, and graphs. The type of visual representation may be selected by the user who may be able to choose access labels, linear or logarithmic scaling, and chart type. The query executor 344 may begin providing results before the query has competed.
A results monitoring module 386 is notified by the query executor 344 when further results are available. The results representation module 384 then updates the view of the results and presents those to the display module 382. In various other implementations, the results monitoring module 386 may poll the query executor 344 to determine when additional results are available. The query executor 344 may provide these incremental results on a time schedule or based on another metric, such as number of records processed. As the results monitoring module 386 detects additional results, the results representation module 384 may need to adjust scaling of axes to accommodate the additional data, may add additional bars or slices to a bar or pie chart, and may adjust values assigned to elements of the chart.
As a simplistic example, consider a query that requests an average GPA for each grade level in a set of data. As the query executor 344 processes the data, initial results will display average GPAs of initial records. As additional records are parsed, the GPAs may be updated. In addition, grade levels that may not have yet have been observed in the query will be added to the results by the results representation module 384.
In various applications, and for various data sets, various metrics, such as average, may begin to converge while a significant number of records have yet to be parsed. This may allow for fast visualization of data trends, and may allow a user to tailor a query or reformulate a query before waiting for a query to complete. This may be particularly valuable for queries that require a long time to run, such as on the order of minutes or hours. For some queries, seeing initial results may indicate to the user that the query needs to be re-formed to return results relevant to that user.
Returning to the simplistic example, an SQL query may take the following form: “SELECT student_id, avg(gpa) FROM students GROUP BY class ORDER BY 2 DESCENDING;”.
A query management module 388 provides queries entered by the user in the display module 382 to the query executor 344. The query management module 388 may store previously run queries, and allow those queries to be re-run. In addition, the query management module 388 may help the user to construct compound queries and/or combine results of previous queries.
In
In
A proxy 348 provides the interface between the ODBC client 352 and the query executor 344. The query executor 344 interacts with metadata service 340, which stores schemas for the data residing in the storage service 356.
At 512, if new data objects have been added to the data sources, control transfers to 516; otherwise, control returns to 504, to allow the sources of data to be modified if desired. At 516, the schema of a new object is inferred, which may be performed according to a type function such as is shown in
At 524, if adornment is desired, control transfers to 528; otherwise, control transfers to 532. At 528, maps are identified within the data, such as is shown in
In various implementations, adornment at 524 may wait until a first round of objects is processed. For example, on an initial ingest, adornment may be delayed until all of the initial objects are ingested. In this way, sufficient statistics will have been collected for use by the map heuristics. For incremental ingests of additional objects, adornment may be performed after each new group of additional objects.
At 532, if the JSON schema has changed as a result of the new objects, control transfers to 548 where the schema is converted to a relational schema. Control continues at 552 where the relational view is optimized, such as by flattening one-to-one relationships. Control then continues at 556. If the schema had not changed at 532, control would directly transfer to 556. At 556, indexes are populated with the data of the new object, which may be performed as shown in
Although population of the indexes is shown at 556 as being performed after converting the inferred schema to relational schema at 548, in various implementations, the indexes may be populated prior to generating the relational schema, as the relational schema is not required. The procedure can use the inferred JSON schema to generate paths and join keys. The relational schema serves as a relational view of the underlying semi-structured data.
If, at 604, the object is not a scalar, control transfers to 616. At 616, if the object is an array, control transfers to 620 where the type function (
If, at 616, the object is not an array, control transfers to 632. At 632, the type function (
At 716, if one of the arrays to be merged is empty, the other array is returned at 724. Otherwise, control continues at 728, where a collapse function, such as is shown in
At 720, if one of the schema elements to be merged is empty, then the other schema element is returned by the merge function at 736. If neither of the schema elements to be merged is empty, control continues at 740 where the collapse function is called on an object containing the key-value pairs of both schema elements to be merged. The collapsed object returned by the collapse function is then returned by the merge function at 744.
At 812, if any of the keys in the object are the same, control transfers to 832; otherwise, collapse is complete and the object is returned. At 832, control selects a pair of keys that are the same and continues in 836. If the values for the pair of keys are both arrays or are both objects, control transfers to 840; otherwise, control transfers to 844. At 840, the merge function is called on the values for the pair of keys. Control continues at 848, where the pair of keys is replaced with a single key having a value returned by the merge function. Control then continues at 852 where, if any additional keys are the same, control transfers to 832; otherwise, the collapse is done and the object as modified is returned. At 844, if the values for the pair of keys are both scalars, control transfers to 856; otherwise, control transfers to 852. At 856, if the scalar types of the values for the pair of keys are equal, control transfers to 840 to merge those pair of keys; otherwise, control transfers to 852.
At 920, control determines whether the tuple is for an array table. If so, control transfers to 924; otherwise, control transfers 928. At 924, if there are more value columns in the array table, control transfers to 932. At 932, if the column value exists in the original retrieved object, the value is added to the ArrayIndex at 936. Control then continues at 940. If the ValueIndex is desired for the column, control transfers to 944; otherwise, control returns 924. If the column value does not exist in the original retrieved object at 932, control returns to 924.
At 928, if the tuple is for a map table, control transfers to 948; otherwise, control transfers to 952. At 948, control determines whether more value columns are remaining in the map table. If so, control transfers to 956; otherwise, control returns to 916. At 956, control determines whether the column value exists in the original retrieved object. If so, control transfers to 960; otherwise, control returns to 948. At 960, the value is added to the MapIndex and control transfers to 964. At 964, if the ValueIndex is desired for the column, the value is added to the ValueIndex in 968; in either case, control then returns to 948.
In 952, control determines whether there are more columns present in a table. If so, control transfers to 972; otherwise, control returns to 916. At 972, control determines whether column values exist in the original retrieved object. If so, control transfers to 976; otherwise, control returns to 952. At 976, the value is added to the BigIndex and control continues at 980. At 980, if the ValueIndex is desired for the column, control transfers to 984, where the value is added to the ValueIndex; in either case, control then returns to 952.
At 1112, if Schema_Element is a map, control transfers to 1116; otherwise, control transfers to 1138. At 1116, a new table (New_Table) is created for the map. Control continues at 1140, where a Join_Key is added to Current_Table and at 1144, a corresponding Join_Key is added to New_Table. At 1148, a key field having a string type is added to New_Table. Control continues at 1152 where, for each value type in the map, the create_schema function is recursively called to add the value type to New_Table. Control then returns at 1136.
At 1138, control determines whether Schema_Element is an array. If so, control transfers to 1156; otherwise, control transfers to 1160. At 1156, a new table (New_Table) is created for the array, a Join_Key is added to Current_Table at 1164, and a corresponding Join_Key is added to New_Table at 1168. At 1172, an index field having an integer type is added to New_Table. Control continues at 1176 where, for each item type in the array, the create_schema function is called to add the item type to New_Table. Control then returns at 1136.
At 1160, Schema_Element, by process of elimination, is a primitive. If there is already a field in Current_Table having the same name as the primitive, control transfers to 1180; otherwise, control transfers to 1184. At 1184, the name field is simply added to Current_Table and control returns at 1136. At 1180, type polymorphism is present and therefore existing fields in Current_Table having the same name as the primitive are renamed to append their type to the field name. Control continues at 1188 where a new field is added based on the current primitive, with the type appended to the field name. Control then returns at 1136.
In
In
In
In
In
In
In
In
The foregoing description is merely illustrative in nature and is in no way intended to limit the disclosure, its application, or uses. The broad teachings of the disclosure can be implemented in a variety of forms. Therefore, while this disclosure includes particular examples, the true scope of the disclosure should not be so limited since other modifications will become apparent upon a study of the drawings, the specification, and the following claims. As used herein, the phrase at least one of A, B, and C should be construed to mean a logical (A or B or C), using a non-exclusive logical OR. It should be understood that one or more steps within a method may be executed in different order (or concurrently) without altering the principles of the present disclosure.
In this application, including the definitions below, the term module may be replaced with the term circuit. The term module may refer to, be part of, or include an Application Specific Integrated Circuit (ASIC); a digital, analog, or mixed analog/digital discrete circuit; a digital, analog, or mixed analog/digital integrated circuit; a combinational logic circuit; a field programmable gate array (FPGA); a processor (shared, dedicated, or group) that executes code; memory (shared, dedicated, or group) that stores code executed by a processor; other suitable hardware components that provide the described functionality; or a combination of some or all of the above, such as in a system-on-chip.
The term code, as used above, may include software, firmware, and/or microcode, and may refer to programs, routines, functions, classes, and/or objects. The term shared processor encompasses a single processor that executes some or all code from multiple modules. The term group processor encompasses a processor that, in combination with additional processors, executes some or all code from one or more modules. The term shared memory encompasses a single memory that stores some or all code from multiple modules. The term group memory encompasses a memory that, in combination with additional memories, stores some or all code from one or more modules. The term memory may be a subset of the term computer-readable medium. The term computer-readable medium does not encompass transitory electrical and electromagnetic signals propagating through a medium, and may therefore be considered tangible and non-transitory. Non-limiting examples of a non-transitory tangible computer readable medium include nonvolatile memory, volatile memory, magnetic storage, and optical storage.
The apparatuses and methods described in this application may be partially or fully implemented by one or more computer programs executed by one or more processors. The computer programs include processor-executable instructions that are stored on at least one non-transitory tangible computer readable medium. The computer programs may also include and/or rely on stored data.
The present disclosure claims the benefit of U.S. Provisional Application No. 61/800,432, filed on Mar. 15, 2013. The entire disclosure of the application referenced above is incorporated herein by reference.
Number | Name | Date | Kind |
---|---|---|---|
7007003 | Rothschiller et al. | Feb 2006 | B1 |
7007033 | Rothschiller et al. | Feb 2006 | B1 |
7096224 | Murthy et al. | Aug 2006 | B2 |
20020174125 | Lucovsky | Nov 2002 | A1 |
20030120651 | Bernstein | Jun 2003 | A1 |
20040034651 | Gupta | Feb 2004 | A1 |
20040148278 | Milo et al. | Jul 2004 | A1 |
20040243555 | Bolsius et al. | Dec 2004 | A1 |
20050160078 | Benson et al. | Jul 2005 | A1 |
20060004844 | Rothschiller | Jan 2006 | A1 |
20060020619 | Netz et al. | Jan 2006 | A1 |
20060085451 | Pal et al. | Apr 2006 | A1 |
20060167880 | Meijer et al. | Jul 2006 | A1 |
20070122118 | Seo et al. | May 2007 | A1 |
20080141182 | Barsness et al. | Jun 2008 | A1 |
20090024590 | Sturge et al. | Jan 2009 | A1 |
20090132621 | Jensen et al. | May 2009 | A1 |
20110231397 | Van Megchelen | Sep 2011 | A1 |
20130166568 | Binkert | Jun 2013 | A1 |
Number | Date | Country |
---|---|---|
1760871 | Apr 2006 | CN |
2003-157249 | May 2003 | JP |
Entry |
---|
International Search Report and Written Opinion from PCT/US2014/029484, dated Sep. 12, 2014, pp. 1-14. |
Extended European Search Report for PCT/US2014/029484, dated Oct. 13, 2016, Amazon Technologies, Inc., pp. 1-11. |
Haw Su-Cheng, et al., “Bridging XML and Relational Databases: Mapping Choices and Performance Evaluation”, IETE Technical Review, vol. 27, Issue 4, Jul.-Aug. 2010, pp. 308-317. |
Mike Stonebraker, et al., “C-Store: A Column-oriented DBMS”, Proceedings of the 31st VLDB Conference, 2005, pp. 553-564. |
Office Action from Japanese Application No. 2016/503110, dated Jul. 18, 2017 (English translation and Japanese version), Amazon Technologies, Inc., pp. 1-8. |
Office Action from China Application No. 201480021193.7, dated Feb. 2, 2018, English translation and Chinese Version. Amazon Technologies Inc., pp. 1-33. |
Petter Nasholm “Extracting Data from NoSQL Database A Step towards Interactive Visual Analysis of NoSQL”, dated Jan. 31, 2012, Retrieved from the internet: URL:http://citeseerx.ist.psu.edu/viewdoc/download/doi-10.1.1.842.8759&rep=1&type=pdf. |
Office Action from European Application No. 14764749.9, dated Apr. 18, 2018, pp. 1-10. |
Number | Date | Country | |
---|---|---|---|
20140279834 A1 | Sep 2014 | US |
Number | Date | Country | |
---|---|---|---|
61800432 | Mar 2013 | US |