Twing Data

Snowflake Integration

This guide will help you integrate Snowflake with Twing Data.

Live Integration

This creates a new role, account, and data warehouse with limited permission to pull the necessary metadata.

-- Create user and role
use role useradmin;
create user if not exists twing_user
  password = 'RANDOM_PASSWORD_HERE'
  default_role = twing_user_role
  default_warehouse = twing_user_dw
  comment = 'Used by Twing Data'
;
create role if not exists twing_user_role
  comment = 'Used by Twing Data';
grant role twing_user_role to role sysadmin;
grant role twing_user_role to user twing_user;

-- Create warehouse
use role sysadmin;
create warehouse if not exists twing_user_dw
  warehouse_size=xsmall
  auto_suspend=60
  initially_suspended=true
  comment = 'Used by Twing Data';
grant monitor, operate, usage, modify
  on warehouse twing_user_dw to role twing_user_role;

-- Grant table permissions
grant imported privileges on database snowflake
  to role twing_user_role;
use role accountadmin;
grant monitor usage on account to role twing_user_role;

One-time Integration

This is a one-time pull of two tables that can be loaded in manually for an analysis.

-- The query history
select *
from snowflake.account_usage.query_history
where query_type in (
    'ALTER_TABLE', 'ALTER_TABLE_ADD_COLUMN', 'ALTER_TABLE_DROP_COLUMN',
    'COPY',
    'CREATE_TABLE', 'CREATE_TABLE_AS_SELECT', 'CREATE_VIEW',
    'DELETE', 'DROP', 'INSERT', 'MERGE',
    'RENAME_TABLE', 'SELECT', 'TRUNCATE_TABLE', 'UPDATE'
)
and query_text not in (
  'SELECT 1;',
  'SELECT CURRENT_SESSION()'
)
order by start_time desc
limit 10000; -- Specify limit to match desired rows and file size

-- The warehouse usage
-- Note that this table is likely small and can be exported
-- without any filters
select *
from snowflake.account_usage.warehouse_metering_history;