prevent search optimization on dev tables (#426)

This commit is contained in:
desmond-hui 2023-12-18 11:23:32 -08:00 committed by GitHub
parent 9ab6b17123
commit fea58183bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 26 additions and 14 deletions

View File

@ -5,4 +5,10 @@
{{ sp_create_prod_clone('_internal') }};
{% endif %}
{% endif %}
{% endmacro %}
{% macro enable_search_optimization(schema_name, table_name, condition = '') %}
{% if target.database == 'SOLANA' %}
ALTER TABLE {{ schema_name }}.{{ table_name }} ADD SEARCH OPTIMIZATION {{ condition }}
{% endif %}
{% endmacro %}

View File

@ -12,6 +12,10 @@ $$
snowflake.execute({sqlText: `DROP SCHEMA IF EXISTS ${DESTINATION_DB_NAME}._INTERNAL`}); /* this only needs to be in prod */
snowflake.execute({sqlText: `GRANT USAGE ON DATABASE ${DESTINATION_DB_NAME} TO AWS_LAMBDA_SOLANA_API`});
snowflake.execute({sqlText: `ALTER TABLE ${DESTINATION_DB_NAME}.SILVER.TRANSACTIONS DROP SEARCH OPTIMIZATION;`});
snowflake.execute({sqlText: `ALTER TABLE ${DESTINATION_DB_NAME}.SILVER.VOTES DROP SEARCH OPTIMIZATION;`});
snowflake.execute({sqlText: `ALTER TABLE ${DESTINATION_DB_NAME}.SILVER.EVENTS DROP SEARCH OPTIMIZATION;`});
snowflake.execute({sqlText: `GRANT OWNERSHIP ON ALL SCHEMAS IN DATABASE ${DESTINATION_DB_NAME} TO ROLE ${ROLE_NAME} COPY CURRENT GRANTS;`});
snowflake.execute({sqlText: `GRANT OWNERSHIP ON ALL FUNCTIONS IN DATABASE ${DESTINATION_DB_NAME} TO ROLE ${ROLE_NAME} COPY CURRENT GRANTS;`});
snowflake.execute({sqlText: `GRANT OWNERSHIP ON ALL PROCEDURES IN DATABASE ${DESTINATION_DB_NAME} TO ROLE ${ROLE_NAME} COPY CURRENT GRANTS;`});
@ -27,6 +31,8 @@ $$
snowflake.execute({sqlText: `GRANT OWNERSHIP ON DATABASE ${DESTINATION_DB_NAME} TO ROLE ${ROLE_NAME} COPY CURRENT GRANTS;`})
snowflake.execute({sqlText: `COMMIT;`});
} catch (err) {
snowflake.execute({sqlText: `ROLLBACK;`});

View File

@ -3,7 +3,7 @@
incremental_strategy = 'delete+insert',
unique_key = ["account_address"],
cluster_by = ['_inserted_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}'),
full_refresh = false,
enabled = false,
) }}

View File

@ -4,7 +4,7 @@
materialized = 'incremental',
unique_key = ["tx_id", "index" ],
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE','program_id'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}'),
merge_exclude_columns = ["inserted_timestamp"],
tags = ['scheduled_non_core']
) }}

View File

@ -3,7 +3,7 @@
unique_key = ["vote_pubkey","epoch_earned","block_id"],
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['block_timestamp::DATE','floor(block_id,-6)','_inserted_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(vote_pubkey, epoch_earned);",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}','ON EQUALITY(vote_pubkey, epoch_earned)'),
tags = ['rewards', 'scheduled_non_core']
) }}

View File

@ -3,7 +3,7 @@
unique_key = ["vote_pubkey","epoch_earned","block_id"],
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['block_timestamp::DATE','floor(block_id,-6)','_inserted_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(vote_pubkey, epoch_earned);",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}','ON EQUALITY(vote_pubkey, epoch_earned)'),
tags = ['rewards'],
full_refresh = false,
enabled = false

View File

@ -3,7 +3,7 @@
unique_key = ["stake_pubkey","epoch_earned","block_id"],
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['block_timestamp::DATE','floor(block_id,-6)','_inserted_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(stake_pubkey, epoch_earned);",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}','ON EQUALITY(stake_pubkey, epoch_earned)'),
tags = ['rewards', 'scheduled_non_core']
) }}

View File

@ -3,7 +3,7 @@
unique_key = ["vote_pubkey","epoch_earned","block_id"],
merge_exclude_columns = ["inserted_timestamp"],
cluster_by = ['block_timestamp::DATE','floor(block_id,-6)','_inserted_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION ON EQUALITY(vote_pubkey, epoch_earned);",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}','ON EQUALITY(vote_pubkey, epoch_earned)'),
tags = ['rewards', 'scheduled_non_core']
) }}

View File

@ -3,7 +3,7 @@
unique_key = ['block_id','tx_id','index'],
incremental_predicates = ['DBT_INTERNAL_DEST.block_timestamp::date >= LEAST(current_date-7,(select min(block_timestamp)::date from ' ~ generate_tmp_view_name(this) ~ '))'],
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE','program_id'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}'),
full_refresh = false,
merge_exclude_columns = ["inserted_timestamp"],
tags = ['scheduled_core']

View File

@ -3,7 +3,7 @@
unique_key = "tx_id",
incremental_predicates = ['DBT_INTERNAL_DEST.block_timestamp::date >= LEAST(current_date-7,(select min(block_timestamp)::date from ' ~ generate_tmp_view_name(this) ~ '))'],
cluster_by = ['block_timestamp::DATE','block_id','_inserted_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}'),
full_refresh = false,
merge_exclude_columns = ["inserted_timestamp"],
tags = ['scheduled_core']

View File

@ -3,7 +3,7 @@
unique_key = ["block_id","tx_id","index"],
incremental_predicates = ['DBT_INTERNAL_DEST.block_timestamp::date >= LEAST(current_date-7,(select min(block_timestamp)::date from ' ~ generate_tmp_view_name(this) ~ '))'],
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}'),
full_refresh = false,
merge_exclude_columns = ["inserted_timestamp"],
tags = ['scheduled_core']

View File

@ -3,7 +3,7 @@
unique_key = "tx_id",
incremental_predicates = ['DBT_INTERNAL_DEST.block_timestamp::date >= LEAST(current_date-7,(select min(block_timestamp)::date from ' ~ generate_tmp_view_name(this) ~ '))'],
cluster_by = ['block_timestamp::DATE','block_id','_inserted_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}'),
full_refresh = false,
tags = ['scheduled_non_core']
) }}

View File

@ -3,7 +3,7 @@
unique_key = ["block_id","tx_id","swap_index"],
incremental_predicates = ['DBT_INTERNAL_DEST.block_timestamp::date >= LEAST(current_date-7,(select min(block_timestamp)::date from ' ~ generate_tmp_view_name(this) ~ '))'],
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}'),
tags = ['scheduled_non_core']
) }}

View File

@ -3,7 +3,7 @@
unique_key = ["block_id","tx_id","swap_index"],
incremental_predicates = ['DBT_INTERNAL_DEST.block_timestamp::date >= LEAST(current_date-7,(select min(block_timestamp)::date from ' ~ generate_tmp_view_name(this) ~ '))'],
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}'),
tags = ['scheduled_non_core']
) }}

View File

@ -3,7 +3,7 @@
unique_key = ["block_id","tx_id","swap_index"],
incremental_predicates = ['DBT_INTERNAL_DEST.block_timestamp::date >= LEAST(current_date-7,(select min(block_timestamp)::date from ' ~ generate_tmp_view_name(this) ~ '))'],
cluster_by = ['block_timestamp::DATE','_inserted_timestamp::DATE'],
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}'),
tags = ['scheduled_non_core']
) }}

View File

@ -3,7 +3,7 @@
materialized = "incremental",
unique_key = "id",
cluster_by = "ROUND(block_id, -3)",
post_hook = "ALTER TABLE {{ this }} ADD SEARCH OPTIMIZATION on equality(id)",
post_hook = enable_search_optimization('{{this.schema}}','{{this.identifier}}','ON EQUALITY(id)'),
tags = ['streamline'],
) }}