Skip to content

Commit d076a87

Browse files
authored
Merge pull request #98 from andrewm4894/develop
Develop
2 parents db3d58d + 64527e1 commit d076a87

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

anomstack/external/gcp/gcs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ def get_credentials():
4040
credentials_path = os.getenv("ANOMSTACK_GOOGLE_APPLICATION_CREDENTIALS")
4141
credentials_json = os.getenv("ANOMSTACK_GOOGLE_APPLICATION_CREDENTIALS_JSON")
4242

43-
if credentials_path:
44-
return service_account.Credentials.from_service_account_file(credentials_path)
45-
elif credentials_json:
43+
if credentials_json:
4644
return service_account.Credentials.from_service_account_info(
4745
json.loads(credentials_json)
4846
)
47+
elif credentials_path:
48+
return service_account.Credentials.from_service_account_file(credentials_path)
4949
else:
5050
return None
5151

anomstack/sql/read.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
This module provides functions for reading data from SQL databases using different database connectors.
33
"""
44

5+
import re
56
import pandas as pd
67
import sqlglot
78
from dagster import get_dagster_logger
@@ -23,9 +24,14 @@ def db_translate(sql: str, db: str) -> str:
2324
Returns:
2425
str: The translated SQL query.
2526
"""
26-
sql = sqlglot.transpile(sql, write=db, identify=True)[0]
27+
# Transpile the SQL query to the target database dialect
28+
sql = sqlglot.transpile(sql, write=db, identify=True, pretty=True)[0]
29+
# Replace some functions with their db-specific equivalents
2730
if db == "sqlite":
2831
sql = sql.replace("GET_CURRENT_TIMESTAMP()", "DATETIME('now')")
32+
elif db == "bigquery":
33+
sql = sql.replace("GET_CURRENT_TIMESTAMP()", "CURRENT_TIMESTAMP()")
34+
sql = re.sub(r"DATE\('now', '(-?\d+) day'\)", "DATE_ADD(CURRENT_DATE(), INTERVAL \\1 DAY)", sql)
2935

3036
return sql
3137

metrics/defaults/sql/alerts.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ data_alerts AS (
120120
metric_has_recent_alert,
121121
CASE
122122
WHEN metric_score_recency_rank <= {{ alert_recent_n }}
123-
AND (metric_score_smooth >= {{ alert_threshold }} OR {{ alert_always }} = 1)
123+
AND (metric_score_smooth >= {{ alert_threshold }} OR {{ alert_always }} = True)
124124
AND metric_has_recent_alert = 0
125125
THEN 1
126126
ELSE 0

0 commit comments

Comments
 (0)