Skip to content

Commit

Permalink
Wrap selected column in any_value to avoid subquery issue (#303)
Browse files Browse the repository at this point in the history
Snowflake seems to not detect that these inner select queries are
returning scalar values without an aggregate.

Closes #301
  • Loading branch information
joshelser authored Sep 13, 2023
1 parent 8087dad commit 0ed8016
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions bootstrap/018_warehouse_updates.sql
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,13 @@ BEGIN
CALL INTERNAL.SET_CONFIG('WAREHOUSE_EVENTS_MAINTENANCE', CURRENT_TIMESTAMP()::string);
END;

CREATE OR REPLACE FUNCTION TOOLS.APPROX_CREDITS_USED(warehouse_name varchar, start_time timestamp, end_time timestamp)
CREATE OR REPLACE FUNCTION TOOLS.APPROX_CREDITS_USED(wh_name varchar, start_time timestamp, end_time timestamp)
RETURNS NUMBER
AS
$$
TOOLS.WAREHOUSE_CREDITS_PER_MILLI((select warehouse_size from internal.warehouse_size_mapping t where t.warehouse_name = warehouse_name),
coalesce((select warehouse_type from internal.warehouse_size_mapping t where t.warehouse_name = warehouse_name), 'STANDARD'))*timestampdiff(millisecond, start_time, end_time)
TOOLS.WAREHOUSE_CREDITS_PER_MILLI(
(select any_value(warehouse_size) from internal.warehouse_size_mapping t where t.warehouse_name = wh_name),
coalesce((select any_value(warehouse_type) from internal.warehouse_size_mapping t where t.warehouse_name = wh_name), 'STANDARD'))*timestampdiff(millisecond, start_time, end_time)
$$;

CREATE OR REPLACE FUNCTION TOOLS.APPROX_CREDITS_USED(warehouse_name varchar, start_time timestamp)
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/090_post_setup.sql
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Query Text: {bt}{bt}{bt}{query_text}{bt}{bt}{bt}
EXCEPTION
WHEN OTHER THEN
SYSTEM$LOG_ERROR(OBJECT_CONSTRUCT('error', 'Unhandled exception occurred during probe monitoring.', 'SQLCODE', :sqlcode, 'SQLERRM', :sqlerrm, 'SQLSTATE', :sqlstate));
insert into internal.probe_actions select CURRENT_TIMESTAMP(), '', '', null::VARIANT, 'Caught unhandled exception';
insert into internal.probe_actions select CURRENT_TIMESTAMP(), '', '', null::VARIANT, 'Caught unhandled exception: ' || :sqlerrm;
RAISE;
END;

Expand Down

0 comments on commit 0ed8016

Please sign in to comment.