Skip to main content

Materializing Metrics using Python

Materializations are invoked through the interfaces and scheduled to run at a cadence. The configuration for the materialization must already exist in your Transform configurations in order for you to run this command. For more information on Materializations, see here.

Usage

See API Reference Doc

Examples

The materialization-name should map to the one committed in your Transform directory. If you don't provide a start and end-time, the materialization will run across all available data, which can be very expensive.

from transform import mql
mql.materialize("transaction_metrics") # synchronous
    /opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/fuzzywuzzy/fuzz.py:11: UserWarning: Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning
warnings.warn('Using slow pure-python SequenceMatcher. Install python-Levenshtein to remove this warning')





MqlMaterializeResp(schema='transform_sales_demo', table='transaction_metrics', query_id='240_1675213512554_0000155')
mql.create_materialization("transaction_metrics") # asynchronous
    MqlQueryStatusResp(query_id='240_1675213512554_0000156', status=<MqlQueryStatus.RUNNING: 'RUNNING'>, error=None, sql='', chart_value_min=None, chart_value_max=None, result=None, result_source=None, result_primary_time_granularity=None, warnings=[])

Providing a start and end time will bound the data for the materialization.

mql.materialize("transaction_metrics", start_time="2020-01-01", end_time="2020-01-31")
    MqlMaterializeResp(schema='transform_sales_demo', table='transaction_metrics', query_id='240_1675213512554_0000157')

By default, the materialization will write to the Transform schema and any other location you've specified in the destinations for your configuration. Optionally provide a specific schema and table to write the materialization to. Note this won't be managed by Transform once it's written outside our cache.

mql.materialize("transaction_metrics", start_time="2020-01-01", end_time="2020-01-31", output_table="my_schmea.my_table")
    MqlMaterializeResp(schema='my_schmea', table='my_table', query_id='240_1675213512554_0000160')