Alias Columns
Overview
Hydrolix separates the write schema (storage) from the read schema (views). Alias columns exist only in the read schema and are calculated at query time from a SQL expression. They don’t exist in transforms or in table partitions.
Alias columns make queries simpler by combining logic and related fields into a single reusable expression.
Alias columns aren’t the same as the
aliases
attribute for stored columns.Alias columns define new calculated columns in views and are not stored.
Use alias columns
When querying a table, alias columns behave like a shortcut for an expression.
For example, an alias may be an expression that calculates a value added tax (VAT) rate, and can be reused anywhere that calculation is needed.
Query a table
In this example, the total
alias expands to price + (price * tax_rate)
when the query runs:
{
"name": "total",
"type": "uint32",
"expression": "price + (price * tax_rate)"
}
The SQL query is now much shorter with total
:
SELECT
price,
tax_rate,
total
FROM products;
The total
column alias isn’t stored, but is calculated each time the query runs.
Use an alias in query
Alias columns can add calculated fields to views during query.
They also provide more consistent output because the input, especially expressions, are always the same.
In this example, the alias column ua_normalized
references the coalesced data without repeating logic:
{
"name": "ua_normalized",
"expression": "coalesce(ua, user_agent, UA)"
}
The result now shows the same information in dashboards and queries, with a predictable value each time.
Rules and limitations
Query behavior
- The query must specifically reference the alias column by name.
For example,SELECT alias_column FROM
works, butSELECT *
doesn’t. - Alias columns can be used with
WHERE
,JOIN
, andSELECT
. - Alias columns can’t be indexed. To optimize performance, index the underlying columns instead.
Insertion and storage
- Alias columns are not stored and don’t exist on disk. The values are calculated when they’re run in a query.
- You can’t insert data directly into an alias column.
- Alias columns aren’t stored in partitions, or returned in
.medatata
or.catalog
.
Naming rules
- An alias column can use other alias columns as a chain, but may not be cyclical.
Usage restrictions
- Alias columns can't be used as inputs for summary tables, but you can use standard SQL aggregation aliases in your
SELECT
statement when defining a summary table. - The alias type must be valid. For example, the expression must resolve to a supported data type, and can’t contain tuples.
- Alias columns can be safely deleted if they have no dependencies.
Schema examples
Aliases require:
name
- the alias title used for identificationexpression
- required for alias columnstype
- inferred automatically.aliases
- only valid for real columns, as alias columns can’t have extra names
The id
isn’t required for aliases because they aren’t stored on disk.
Chain alias columns
In this example, one alias references another, but isn’t a cyclical chain.
{
"name": "alias_int_1",
"type": "int32",
"expression": "int + 1"
},
{
"name": "alias_int_2",
"type": "int64",
"expression": "alias_int_1 * 2"
}
In transform output_columns
output_columns
The output_columns
section can include an alias. This allows normalization of coalesced data for consistency and predictability.
"output_columns": [
{
"name": "userAgent",
"id": "userAgent_uuid",
"datatype": { "type": "string" }
},
{
"name": "ua_normalized",
"expression": "coalesce(userAgent, UA)"
}
]
API schema (column object)
An example of a real column and an alias column.
{
"id": "1234",
"name": "userAgent",
"type": "string",
"aliases": ["userAgent", "ua"],
"index": true
},
{
"name": "ua_normalized",
"type": "string",
"expression": "coalesce(userAgent, UA)",
"index": false
}
Updated 8 days ago