Macros
The macros below are available to use in your dbt project. They are also used internally by the adapter to implement the configuration options.
Tip
Usually the macros below won't be used directly but instead will be used via the configuration options of the hypertables and continuous aggregates. They are documented here for completeness.
set_compression
Enable or disable compression on a (virtual) hypertable or continuous aggregate.
{{ set_compression('table_name', {"orderby": "column_name"}) }}
add_compression_policy
Add a compression policy to a (virtual) hypertable or continuous aggregate.
{{ add_compression_policy('table_name', {"after": "interval '60d'"}) }}
clear_compression_policy
Remove any existing compression policy from a (virtual) hypertable or continuous aggregate.
{{ clear_compression_policy('table_name') }}
add_reorder_policy
Add a reorder policy to a (virtual) hypertable.
{{ add_reorder_policy('table_name', {"index": {"columns": "column_name"}}) }}
clear_reorder_policy
Remove any existing reorder policy from a (virtual) hypertable.
{{ clear_reorder_policy('table_name') }}
add_refresh_policy
Add a refresh policy to a continuous aggregate.
{{ add_refresh_policy('continuous_aggregate_name', {
"start_offset": "interval '3 day'",
"end_offset": "interval '2 day'"}) }}
clear_refresh_policy
Remove any existing refresh policy from a continuous aggregate.
{{ clear_refresh_policy('continuous_aggregate_name') }}
set_integer_now_func
Set the function used to generate the current time for integer time columns in hypertables.
{{ set_integer_now_func('table_name', 'function_name') }}
set_chunk_time_interval
Set the chunk time interval for a (virtual) hypertable. This macro has an optional argument dimension_name
. If provided, the chunk time interval will be set for the specified dimension only
{{ set_chunk_time_interval('table_name', 'interval') }}
add_dimension
Add a dimension to a (virtual) hypertable.
{{ add_dimension('table_name', dimension_config) }}
In this adapter, dimensions can be provided as a dictionary with the following options:
column_name
type
:by_hash
orby_range
(default isby_range
)partition_interval
(only forby_range
)number_partitions
(only forby_hash
)partitioning_func
Since most dimensions will probably be by_range
dimensions with a column name, you can also provide the name of the column as a shorthand instead of a dictionary.
Empty hypertable required
You can only add dimensions to an empty hypertable.
Info
Consult the Timescale docs for more information regarding adding dimensions or the documentation on dimension builders.
{{ config(
materialized = 'hypertable',
main_dimension = 'time_column',
dimensions=[
{"column_name": "id", "type": "by_hash", "number_partitions": 5},
{"column_name": "col_1", "type": "by_range", "partition_interval": "interval '1 day'"},
{"column_name": "another_column", "type": "by_range"}
]
}}
select
current_timestamp as time_column,
1 as id,
2 as col_1,
3 as another_column
models:
your_project_name:
model_name:
+materialized: hypertable
+main_dimension:
column_name: time_column
type: by_range
# the above would be equivalent to +main_dimension: time_column
+dimensions:
- column_name: id
type: by_hash
number_partitions: 5
- column_name: another_time_column
type: by_range
partition_interval: interval '1 day'
# ...
add_retention_policy
Add a retention policy to a (virtual) hypertable or continuous aggregate.
{{ add_retention_policy('table_name', {
"drop_after": "interval '1 month'"
}) }}
clear_retention_policy
Remove any existing retention policy from a (virtual) hypertable or a continuous aggregate.
{{ clear_retention_policy('table_name') }}