0% found this document useful (0 votes)
77 views

Snowflake Setup - MD

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.

Uploaded by

Priyanshu Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Snowflake Setup - MD

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.

Uploaded by

Priyanshu Gupta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Introduction and Environment Setup

SNOWFLAKE USER CREATION


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);

COPY INTO raw_listings (id,


listing_url,
name,
room_type,
minimum_nights,
host_id,
price,
created_at,
updated_at)
from 's3://dbtlearn/listings.csv'
FILE_FORMAT = (type = 'CSV' skip_header = 1
FIELD_OPTIONALLY_ENCLOSED_BY = '"');

CREATE OR REPLACE TABLE raw_reviews


(listing_id integer,
date datetime,
reviewer_name string,
comments string,
sentiment string);

COPY INTO raw_reviews (listing_id, date, reviewer_name, comments, sentiment)


from 's3://dbtlearn/reviews.csv'
FILE_FORMAT = (type = 'CSV' skip_header = 1
FIELD_OPTIONALLY_ENCLOSED_BY = '"');

CREATE OR REPLACE TABLE raw_hosts


(id integer,
name string,
is_superhost string,
created_at datetime,
updated_at datetime);

COPY INTO raw_hosts (id, name, is_superhost, created_at, updated_at)


from 's3://dbtlearn/hosts.csv'
FILE_FORMAT = (type = 'CSV' skip_header = 1
FIELD_OPTIONALLY_ENCLOSED_BY = '"');

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy