SuperDB Documentation

repository·main·Indexed 23 days ago

https://github.com/brimdata/super

SuperDB is an analytics database for high-performance data wrangling of heterogeneous datasets. It treats relational and JSON data as a unified 'super-structured' model using SuperSQL, an extended SQL dialect featuring pipe syntax. The system supports native formats including Super (SUP), Super Binary (BSUP), and Super Columnar (CSUP), and provides tools like the `super` query engine and `super db` command for database management and metadata inspection.

Tokens
127.8K
Snippets
419
Records
769
Agent score
80%

What's inside SuperDB

  1. Introduction to SuperSQL

    main

    SuperSQL is a Pipe SQL language adapted for super-structured data. It is a superset of standard SQL query syntax and includes a modern type system with sum types to handle heterogeneous data.

    Queries follow a Unix-like pipeline pattern where a data source is followed by a series of operators that manipulate the data:

    from source | operator | operator | ...

    While the syntax implies a linear dataflow, the SuperSQL compiler can optimize the query execution for better performance.

    from source | operator | operator | ...
  2. Overview of SuperDB

    main

    SuperDB is an analytics database designed to handle relational tables and JSON on equal footing. It is optimized for data wrangling, exploring, and processing large, heterogeneous (eclectic) datasets.

    Key characteristics include:

    • Unified Data Model: All ingested data (JSON, CSV, Parquet, Arrow, etc.) is converted into super-structured data. This allows a single compute engine to support both statically-typed relational models and dynamically-typed JSON models.
    • Strong/Dynamic Typing: Unlike standard document models, every value in SuperDB is strongly and dynamically typed, providing both flexibility and performance.
    • Schema Flexibility: SuperDB does not rely on fragile schema inference for JSON; it ingests data in its natural form, allowing for high heterogeneity without failure.
  3. SuperSQL compatibility with PostgreSQL and SQLite

    main

    SuperSQL aims for high compatibility with the PostgreSQL dialect. It is validated using sqllogictest queries from SQLite.

    As of the first GA release, SuperSQL achieves a 99.88% success rate against eligible SQLite queries compared to PostgreSQL.

    Known compatibility issues/limitations:

    • Correlated subqueries
    • INTERSECT and EXCEPT operators
    • Large cartesian products (performance issues)
    • NULL values absent from JOIN output
    • Signed zero handling
    • Promoting return types to a common type of arguments
  4. Understand the Super data model and supported formats

    main

    SuperDB uses a unified data model for super-structured data, allowing for lossless conversions between human-readable, row-based binary, and columnar formats. The three primary formats are:

    • Super (SUP): A human-readable format. It is a strict superset of JSON, meaning all JSON documents are valid SUP values.
    • Super Binary (BSUP): A row-based binary representation (similar to Avro) designed to represent a sequence of arbitrarily-typed values.
    • Super Columnar (CSUP): A columnar format (similar to Parquet, ORC, or Arrow) optimized for super-structured data.

    Because these formats all implement the same underlying data model, you can convert data between them without losing information.

  5. Explore SuperDB libraries and integrations

    main
    SuperDB provides specialized libraries for interacting with the database and initial integrations for connecting to external systems. Developers can extend the ecosystem by utilizing these core components to build database-driven applications.
  6. What is Type Fusion and when to use it

    main

    Type fusion is the process of merging a set of input types into a single output type where all input values are subtypes of the output. This allows heterogeneous data to be represented in a single, unified schema.

    Key Concepts

    • Type Fusion: Determining a single fused type from a collection of data. This is implemented by the fuse aggregate function.
    • Data Fusion: Transforming actual data into a new collection using the fused type via a cast operation. This is implemented by the fuse operator.
    • Schema Inference: When type fusion is used on semi-structured data to model a relational schema, it resembles schema inference. You can use the infer operator after type fusion to refine primitive types (e.g., converting strings to dates or IP addresses).

    Common Use Cases

    • Data Exploration: Sampling or filtering raw data by fusing slices of data together.
    • Exporting Data: Converting super-structured data to formats with rigid schemas like Parquet or CSV.
    • ETL Pipelines: Gathering data from APIs, transforming it in a SuperDB pipeline, and writing it to a data warehouse.

    Note: When exporting via type fusion, the original data is altered to fit the rigid structure of the output format (e.g., missing columns are set to null).

  7. What is SuperSQL?

    main

    SuperSQL is the extended SQL dialect used by SuperDB. It extends standard SQL with pipe syntax and various functional shortcuts to facilitate complex data transformations.

    In SuperSQL, you can chain operations using the pipe (|) operator, allowing for a flow-based query style similar to Unix pipes. This is particularly useful for complex joins, subqueries, and data reshaping.

    FROM 'https://data.gharchive.org/2015-01-01-15.json.gz'
    | SELECT union(repo.name) AS repos, actor.login AS user
      GROUP BY user
      ORDER BY len(repos) DESC
      LIMIT 5
    | FORK
      ( FROM f'https://api.github.com/users/{user}'
        SELECT login AS user, created_at::time AS created_at )
      ( PASS )
    | JOIN USING (user)
    | VALUES {...left,repos:right.repos}
  8. What is data shaping in SuperSQL?

    main

    Data shaping is the process of unifying heterogeneous data sources by transforming them to fit a well-defined schema. In SuperSQL, shaping involves converting leaf field types, adding or removing fields, and reordering fields to match a target type. This is essential for cleaning up disparate data for use in a unified store like a data warehouse.

    Core shaping functions include:

    • cast: Coerces values to a different type.
    • crop: Removes fields not present in the target type.
    • fill: Adds missing fields with null values.
    • order: Reorders fields to match the target type.
    • shape: A composite function that applies cast, fill, and order in a single step.
  9. What is Super-structured Data?

    main

    Super-structured data is the core data model of SuperDB. It unifies relational tables and dynamic JSON into a single, powerful model. Unlike traditional relational models that struggle with mixed-type JSON, super-structured data is:

    • Dynamic: Data collections can vary by type and are not constrained by rigid schemas.
    • Strongly Typed: Allows for static type checking and type-based query optimizations even on dynamic data.
    • Self-describing: Eliminates the need to define schemas upfront, as the data carries its own type information.

    In this model, a relational table is simply a collection of uniformly typed records, while dynamic data (like logs or events) can be modeled as sequences of varying JSON-like values. This allows you to mix and match formats like Parquet and JSON seamlessly in a single query.

  10. What is the Super Binary (BSUP) format?

    main

    Super Binary (BSUP) is an efficient, row-oriented, sequence-oriented serialization format designed for super-structured data.

    Key characteristics include:

    • Schema-less: Unlike Apache Avro, BSUP does not require external schema definitions. Instead, it embeds type information directly into the data stream using the super data model's fine-grained type system.
    • Lazy Parsing: The binary format allows for lazy parsing, meaning only the specific fields of interest need to be deserialized and interpreted.
    • Heterogeneous Data Support: BSUP supports multiplexing different data types by prepending each value with a simple integer identifier that references its type.
    • Dynamic Type Context: A "type context" is constructed on the fly by composing the dynamic type definitions embedded within the stream.
    • Efficient Merging: Multiple BSUP streams with different type contexts can be merged by merging their input contexts into an output context and adjusting type references. This process does not require traversing or rewriting the actual values.
  11. Understand Type Checking in SuperSQL

    main

    SuperSQL uses strong typing for all data. It supports two modes of type checking:

    1. Static Type Checking: For data conforming to a schema, types are checked at compile time. This works for traditional relational SQL and super-structured pipe queries.
    2. Fused Type Checking: For dynamic data (like JSON or CSV), the compiler uses a technique called fused types. It interrogates data sources to compute a fused type on the fly and performs type checking based on these types rather than a fixed relational schema.

    If a file is too large for the compiler to compute fused types efficiently, the process may be skipped (based on a configurable limit), which may result in runtime errors instead of compile-time errors.

  12. How Pipe Joins work in SuperSQL

    main
    Joins in SuperSQL pipe context differ from standard SQL joins. Instead of using SQL selections to combine data in a projection from different relations, Pipe Joins use multi-column records to combine data. The join operator allows you to combine a primary stream of data with a secondary input (often provided via a subquery or another operator) based on a matching condition defined by the on clause.