Created
September 22, 2016 04:48
-
-
Save anonymous/657b5175b978cdc7dd0cba2b0d44ef77 to your computer and use it in GitHub Desktop.
RedShift Prep Steps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table part cascade; | |
drop table supplier cascade; | |
drop table customer cascade; | |
drop table dwdate cascade; | |
drop table lineorder cascade; | |
CREATE TABLE part | |
( | |
p_partkey INTEGER NOT NULL, | |
p_name VARCHAR(22) NOT NULL, | |
p_mfgr VARCHAR(6) NOT NULL, | |
p_category VARCHAR(7) NOT NULL, | |
p_brand1 VARCHAR(9) NOT NULL, | |
p_color VARCHAR(11) NOT NULL, | |
p_type VARCHAR(25) NOT NULL, | |
p_size INTEGER NOT NULL, | |
p_container VARCHAR(10) NOT NULL | |
); | |
CREATE TABLE supplier | |
( | |
s_suppkey INTEGER NOT NULL, | |
s_name VARCHAR(25) NOT NULL, | |
s_address VARCHAR(25) NOT NULL, | |
s_city VARCHAR(10) NOT NULL, | |
s_nation VARCHAR(15) NOT NULL, | |
s_region VARCHAR(12) NOT NULL, | |
s_phone VARCHAR(15) NOT NULL | |
); | |
CREATE TABLE customer | |
( | |
c_custkey INTEGER NOT NULL, | |
c_name VARCHAR(25) NOT NULL, | |
c_address VARCHAR(25) NOT NULL, | |
c_city VARCHAR(10) NOT NULL, | |
c_nation VARCHAR(15) NOT NULL, | |
c_region VARCHAR(12) NOT NULL, | |
c_phone VARCHAR(15) NOT NULL, | |
c_mktsegment VARCHAR(10) NOT NULL | |
); | |
CREATE TABLE dwdate | |
( | |
d_datekey INTEGER NOT NULL, | |
d_date VARCHAR(19) NOT NULL, | |
d_dayofweek VARCHAR(10) NOT NULL, | |
d_month VARCHAR(10) NOT NULL, | |
d_year INTEGER NOT NULL, | |
d_yearmonthnum INTEGER NOT NULL, | |
d_yearmonth VARCHAR(8) NOT NULL, | |
d_daynuminweek INTEGER NOT NULL, | |
d_daynuminmonth INTEGER NOT NULL, | |
d_daynuminyear INTEGER NOT NULL, | |
d_monthnuminyear INTEGER NOT NULL, | |
d_weeknuminyear INTEGER NOT NULL, | |
d_sellingseason VARCHAR(13) NOT NULL, | |
d_lastdayinweekfl VARCHAR(1) NOT NULL, | |
d_lastdayinmonthfl VARCHAR(1) NOT NULL, | |
d_holidayfl VARCHAR(1) NOT NULL, | |
d_weekdayfl VARCHAR(1) NOT NULL | |
); | |
CREATE TABLE lineorder | |
( | |
lo_orderkey INTEGER NOT NULL, | |
lo_linenumber INTEGER NOT NULL, | |
lo_custkey INTEGER NOT NULL, | |
lo_partkey INTEGER NOT NULL, | |
lo_suppkey INTEGER NOT NULL, | |
lo_orderdate INTEGER NOT NULL, | |
lo_orderpriority VARCHAR(15) NOT NULL, | |
lo_shippriority VARCHAR(1) NOT NULL, | |
lo_quantity INTEGER NOT NULL, | |
lo_extendedprice INTEGER NOT NULL, | |
lo_ordertotalprice INTEGER NOT NULL, | |
lo_discount INTEGER NOT NULL, | |
lo_revenue INTEGER NOT NULL, | |
lo_supplycost INTEGER NOT NULL, | |
lo_tax INTEGER NOT NULL, | |
lo_commitdate INTEGER NOT NULL, | |
lo_shipmode VARCHAR(10) NOT NULL | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop table part cascade; | |
drop table supplier cascade; | |
drop table customer cascade; | |
drop table dwdate cascade; | |
drop table lineorder cascade; | |
CREATE TABLE part | |
( | |
p_partkey INTEGER NOT NULL sortkey distkey, | |
p_name VARCHAR(22) NOT NULL, | |
p_mfgr VARCHAR(6) NOT NULL, | |
p_category VARCHAR(7) NOT NULL, | |
p_brand1 VARCHAR(9) NOT NULL, | |
p_color VARCHAR(11) NOT NULL, | |
p_type VARCHAR(25) NOT NULL, | |
p_size INTEGER NOT NULL, | |
p_container VARCHAR(10) NOT NULL | |
); | |
CREATE TABLE supplier | |
( | |
s_suppkey INTEGER NOT NULL sortkey, | |
s_name VARCHAR(25) NOT NULL, | |
s_address VARCHAR(25) NOT NULL, | |
s_city VARCHAR(10) NOT NULL, | |
s_nation VARCHAR(15) NOT NULL, | |
s_region VARCHAR(12) NOT NULL, | |
s_phone VARCHAR(15) NOT NULL | |
) diststyle all; | |
CREATE TABLE customer | |
( | |
c_custkey INTEGER NOT NULL sortkey, | |
c_name VARCHAR(25) NOT NULL, | |
c_address VARCHAR(25) NOT NULL, | |
c_city VARCHAR(10) NOT NULL, | |
c_nation VARCHAR(15) NOT NULL, | |
c_region VARCHAR(12) NOT NULL, | |
c_phone VARCHAR(15) NOT NULL, | |
c_mktsegment VARCHAR(10) NOT NULL | |
) diststyle all; | |
CREATE TABLE dwdate | |
( | |
d_datekey INTEGER NOT NULL sortkey, | |
d_date VARCHAR(19) NOT NULL, | |
d_dayofweek VARCHAR(10) NOT NULL, | |
d_month VARCHAR(10) NOT NULL, | |
d_year INTEGER NOT NULL, | |
d_yearmonthnum INTEGER NOT NULL, | |
d_yearmonth VARCHAR(8) NOT NULL, | |
d_daynuminweek INTEGER NOT NULL, | |
d_daynuminmonth INTEGER NOT NULL, | |
d_daynuminyear INTEGER NOT NULL, | |
d_monthnuminyear INTEGER NOT NULL, | |
d_weeknuminyear INTEGER NOT NULL, | |
d_sellingseason VARCHAR(13) NOT NULL, | |
d_lastdayinweekfl VARCHAR(1) NOT NULL, | |
d_lastdayinmonthfl VARCHAR(1) NOT NULL, | |
d_holidayfl VARCHAR(1) NOT NULL, | |
d_weekdayfl VARCHAR(1) NOT NULL | |
) diststyle all; | |
CREATE TABLE lineorder | |
( | |
lo_orderkey INTEGER NOT NULL, | |
lo_linenumber INTEGER NOT NULL, | |
lo_custkey INTEGER NOT NULL, | |
lo_partkey INTEGER NOT NULL distkey, | |
lo_suppkey INTEGER NOT NULL, | |
lo_orderdate INTEGER NOT NULL sortkey, | |
lo_orderpriority VARCHAR(15) NOT NULL, | |
lo_shippriority VARCHAR(1) NOT NULL, | |
lo_quantity INTEGER NOT NULL, | |
lo_extendedprice INTEGER NOT NULL, | |
lo_ordertotalprice INTEGER NOT NULL, | |
lo_discount INTEGER NOT NULL, | |
lo_revenue INTEGER NOT NULL, | |
lo_supplycost INTEGER NOT NULL, | |
lo_tax INTEGER NOT NULL, | |
lo_commitdate INTEGER NOT NULL, | |
lo_shipmode VARCHAR(10) NOT NULL | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
copy customer from 's3://awssampledbuswest2/ssbgz/customer' | |
gzip compupdate off region 'us-west-2'; | |
copy dwdate from 's3://awssampledbuswest2/ssbgz/dwdate' | |
gzip compupdate off region 'us-west-2'; | |
copy lineorder from 's3://awssampledbuswest2/ssbgz/lineorder' | |
gzip compupdate off region 'us-west-2'; | |
copy part from 's3://awssampledbuswest2/ssbgz/part' | |
gzip compupdate off region 'us-west-2'; | |
copy supplier from 's3://awssampledbuswest2/ssbgz/supplier' | |
gzip compupdate off region 'us-west-2'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UNLOAD ('select * from customer') | |
TO 's3://mynohup java -cp lib/jisql-2.0.11.jar:lib/jopt-simple-3.2.jar:lib/postgresql-8.4-703.jdbc4.jar com.xigole.util.sql.Jisql -driver postgresql -cstring jdbc:postgresql://pythian-ssb.cqfq2ecqrwnm.us-west-2.redshift.amazonaws.com:5439/ssb -user $USERNAME -password $PASSWORD -c \; -input ../bbs_create_tables.sql& | |
nohup time java -cp lib/jisql-2.0.11.jar:lib/jopt-simple-3.2.jar:lib/postgresql-8.4-703.jdbc4.jar com.xigole.util.sql.Jisql -driver postgresql -cstring jdbc:postgresql://pythian-ssb.cqfq2ecqrwnm.us-west-2.redshift.amazonaws.com:5439/ssb -user $USERNAME -password $PASSWORD -c \; -input ../bbs_load_data.sql&-redshift-export/customer_'; | |
UNLOAD ('select * from dwdate') | |
TO 's3://my-redshift-export/dwdate_'; | |
UNLOAD ('select * from lineorder') | |
TO 's3://my-redshift-export/lineorder_'; | |
UNLOAD ('select * from part') | |
TO 's3://my-redshift-export/part_'; | |
UNLOAD ('select * from supplier') | |
TO 's3://my-redshift-export/supplier_'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export ACCESS-KEY= | |
export SECRET-ACCESS-KEY= | |
export USERNAME= | |
export PASSWORD= | |
nohup time java -cp lib/jisql-2.0.11.jar:lib/jopt-simple-3.2.jar:lib/postgresql-8.4-703.jdbc4.jar com.xigole.util.sql.Jisql -driver postgresql -cstring jdbc:postgresql://pythian-ssb.cqfq2ecqrwnm.us-west-2.redshift.amazonaws.com:5439/ssb -user $USERNAME -password $PASSWORD -c \; -input ../bbs_create_tables.sql& | |
nohup time java -cp lib/jisql-2.0.11.jar:lib/jopt-simple-3.2.jar:lib/postgresql-8.4-703.jdbc4.jar com.xigole.util.sql.Jisql -driver postgresql -cstring jdbc:postgresql://pythian-ssb.cqfq2ecqrwnm.us-west-2.redshift.amazonaws.com:5439/ssb -user $USERNAME -password $PASSWORD -c \; -input ../bbs_load_data.sql& | |
nohup time java -cp lib/jisql-2.0.11.jar:lib/jopt-simple-3.2.jar:lib/postgresql-8.4-703.jdbc4.jar com.xigole.util.sql.Jisql -driver postgresql -cstring jdbc:postgresql://pythian-ssb.cqfq2ecqrwnm.us-west-2.redshift.amazonaws.com:5439/ssb -user $USERNAME -password $PASSWORD -c \; -input ../bbs_unload.sql& |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment