Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from flowetl.mixins.fixed_sql_with_params_mixin import fixed_sql_operator_with_params
CreateIndexesOperator = fixed_sql_operator_with_params(
class_name="CreateIndexesOperator",
sql="""
{% for index_column in params.index_columns %}
DROP INDEX IF EXISTS {{ table_name }}_{{ index_column }}_idx;
CREATE INDEX {{ table_name }}_{{ index_column }}_idx ON {{ extract_table }} ({{ index_column }});
{% endfor %}
""",
params=["index_columns"],
)
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from flowetl.mixins.fixed_sql_with_params_mixin import fixed_sql_operator_with_params
ClusterOperator = fixed_sql_operator_with_params(
class_name="ClusterOperator",
sql="""
DROP INDEX IF EXISTS {{ table_name }}_{{ params.cluster_field }}_idx;
CREATE INDEX {{ table_name }}_{{ params.cluster_field }}_idx ON {{ extract_table }} ({{ params.cluster_field }});
CLUSTER {{ extract_table }} USING {{ table_name }}_{{ params.cluster_field }}_idx;
""",
params=["cluster_field"],
)
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from flowetl.mixins.fixed_sql_with_params_mixin import fixed_sql_operator_with_params
TableFluxSensor = fixed_sql_operator_with_params(
class_name="TableFluxSensor",
sql="""
CREATE TEMPORARY TABLE {{ staging_table_name }}_count AS
SELECT count(*) FROM {{ staging_table }};
SELECT pg_sleep({{ params.flux_check_interval }});
SELECT 1 WHERE (SELECT * FROM {{ staging_table_name }}_count) = (SELECT count(*) FROM {{ staging_table }});
""",
params=["flux_check_interval"],
is_sensor=True,
)