Metadata Columns
All Metadb-generated tables include standard metadata columns with names beginning with double underscores:| Column | Description |
|---|---|
__id | Surrogate key that uniquely identifies a row (defined by Metadb) |
__start | Timestamp when the row was generated |
__end | Timestamp when the row became no longer current, or 9999-12-31 00:00:00+00 if still current |
__current | Boolean indicating whether the row is current |
__origin | Optional identifier for grouping related data from one or more data sources |
The
__id column is distinct from any id column that may come from your data source. The __id is always unique and managed by Metadb, while source columns may change with schema changes.Main Tables
Main tables have names ending with two underscores (e.g.,patrongroup__) and contain both the current state and complete history of all previous states.
Example: Library Patron Groups
__start | __end | __current | id | groupname | description |
|---|---|---|---|---|---|
| 2022-04-17 21:42:25-00 | 2022-04-18 19:27:18-00 | false | 15 | undergrad | Student |
| 2022-04-18 19:27:18-00 | 9999-12-31 00:00:00+00 | true | 15 | undergrad | Undergraduate Student |
| 2022-04-17 21:42:25-00 | 9999-12-31 00:00:00+00 | true | 10 | graduate | Graduate Student |
id = 15 has two rows because it was modified, changing the description from “Student” to “Undergraduate Student”.
Main tables are perfect for historical analysis, tracking changes over time, and answering questions like “What did this record look like on a specific date?”
Current Tables
For queries that only need current records, current tables provide a convenient filtered view. Current tables have the same name as their main table but without the trailing underscores.Querying Current Data
These two queries are equivalent:In some database client applications, current tables may not appear separately in the table list because they have a parent-child relationship with main tables.
Current Table Benefits
- Simpler queries: No need to filter on
__current - Better performance: Optimized for current state queries
- Familiar naming: Matches the original table names in the data source
Transformed Tables
Metadb can apply transformations to create additional tables with processed data. The most common transformation is extracting JSON fields into columns.JSON Transformation
Suppose your data contains JSON in ajsondata column:
__id | __start | id | jsondata |
|---|---|---|---|
| 8 | 2022-04-18 19:27:18-00 | 15 | {"groupname": "undergrad", "description": "Undergraduate Student"} |
Creating Transformations
Define a transformation to automatically extract JSON fields:- Main transformed table:
patrongroup__t__ - Current transformed table:
patrongroup__t
JSON fields are inferred dynamically from the data. A new column is added automatically when a record contains a new JSON field.
Nested JSON Transformations
For nested JSON objects and arrays, create multiple mappings:An object or array will only be transformed if all its parent objects are also transformed. For example, transforming
$.tags.tagList requires transforming both $.tags and $.Table Type Comparison
- Summary Table
- Use Cases
| Table Name | Table Type | Description |
|---|---|---|
patrongroup__ | Main table | Current and historical records |
patrongroup | Current table (base table) | Current records only |
patrongroup__t__ | Main transformed table | Transformed versions of records in patrongroup__ |
patrongroup__t | Current transformed table | Transformed versions of records in patrongroup |
t is an identifier configured during transformation setup. Multiple transformed tables can exist with different identifiers.Partition Tables
Some partition tables have names beginning withzzz___. These are internal tables used by Metadb for performance optimization.
It is recommended not to query partition tables directly. Access to these tables is generally disabled.
Modifying Tables
You can modify table definitions using thealter table command:
Adding Columns
Changing Column Types
Currently supported types for manual alterations are
text and uuid. Metadb also performs automatic type conversions in many cases.Best Practices
Choose the Right Table Type
Use current tables for most queries. Only query main tables when you need historical data.
Transform Complex JSON
Create transformations for frequently queried JSON fields to improve query simplicity and performance.
Avoid Querying Partition Tables
Stick to main, current, and transformed tables. Partition tables are internal implementation details.
Monitor Transformed Columns
Remember that JSON transformations add columns dynamically as new fields appear in the data.
