The document provides SQL statements to setup a Snowflake database, warehouse, schema, user, and roles for loading Airbnb data from S3 using dbt (data build tool). It creates the necessary database, schema, user, and roles, then loads listing, review, and host data from CSV files in S3 into corresponding tables in the Snowflake schema using COPY INTO statements.
The document provides SQL statements to setup a Snowflake database, warehouse, schema, user, and roles for loading Airbnb data from S3 using dbt (data build tool). It creates the necessary database, schema, user, and roles, then loads listing, review, and host data from CSV files in S3 into corresponding tables in the Snowflake schema using COPY INTO statements.
Copy these SQL statements into a Snowflake Worksheet, select all and execute them (i.e. pressing the play button).
-- Use an admin role
USE ROLE ACCOUNTADMIN;
-- Create the `transform` role
CREATE ROLE IF NOT EXISTS transform; GRANT ROLE TRANSFORM TO ROLE ACCOUNTADMIN;
-- Create the `dbt` user and assign to role
CREATE USER IF NOT EXISTS dbt PASSWORD='dbtPassword123' LOGIN_NAME='dbt' MUST_CHANGE_PASSWORD=FALSE DEFAULT_WAREHOUSE='COMPUTE_WH' DEFAULT_ROLE='transform' DEFAULT_NAMESPACE='AIRBNB.RAW' COMMENT='DBT user used for data transformation'; GRANT ROLE transform to USER dbt;
-- Create our database and schemas
CREATE DATABASE IF NOT EXISTS AIRBNB; CREATE SCHEMA IF NOT EXISTS AIRBNB.RAW;
-- Set up permissions to role `transform`
GRANT ALL ON WAREHOUSE COMPUTE_WH TO ROLE transform; GRANT ALL ON DATABASE AIRBNB to ROLE transform; GRANT ALL ON ALL SCHEMAS IN DATABASE AIRBNB to ROLE transform; GRANT ALL ON FUTURE SCHEMAS IN DATABASE AIRBNB to ROLE transform; GRANT ALL ON ALL TABLES IN SCHEMA AIRBNB.RAW to ROLE transform; GRANT ALL ON FUTURE TABLES IN SCHEMA AIRBNB.RAW to ROLE transform;
SNOWFLAKE DATA IMPORT
Copy these SQL statements into a Snowflake Worksheet, select all and execute them (i.e. pressing the play button).
-- Set up the defaults
USE WAREHOUSE COMPUTE_WH; USE DATABASE airbnb; USE SCHEMA RAW;
-- Create our three tables and import the data from S3
CREATE OR REPLACE TABLE raw_listings (id integer, listing_url string, name string, room_type string, minimum_nights integer, host_id integer, price string, created_at datetime, updated_at datetime);