Skip to content

Instantly share code, notes, and snippets.

View gregrahn's full-sized avatar

Greg Rahn gregrahn

View GitHub Profile
--------------
alter table call_center add constraint cc_d1 foreign key (cc_closed_date_sk) references date_dim (d_date_sk)
--------------
Query OK, 6 rows affected (0.03 sec)
Records: 6 Duplicates: 0 Warnings: 0
--------------
alter table call_center add constraint cc_d2 foreign key (cc_open_date_sk) references date_dim (d_date_sk)
--------------
create unique index person_pk on person(person_id);
create index person_n1 on person(date_id);
create unique index calendar_pk on calendar(date_id) ;
@gregrahn
gregrahn / tez-crash.sql
Created July 18, 2014 22:06
tez-crash.sql
hive> set hive.execution.engine=tez;
hive> select split('I crash Tez',' ');
Query ID = hue_20140718150505_1eafc45c-6e2b-49f1-9d72-0ec737a72377
Total jobs = 1
Launching Job 1 out of 1
Status: Running (application id: application_1405217363240_0016)
Map 1: -/-
@gregrahn
gregrahn / inmap.sh
Last active August 29, 2015 14:05
download and merge all the tiles to make a high resolution LinkedIn InMap
# 1) get your inmap from http://inmaps.linkedinlabs.com/
# 2) zoom all the way in and note the url for the individual tiles (I used Charles Proxy to do this,
# but right/control-click, "Inspect Element", "Network" tab, then reload page, also works.)
# 3) download your tiles
# 4) merge the tiles into column-wise strips
# 5) merge the column-wise strips into the final high resolution image
# download the individual tiles
# my inmap happended to be 15 tiles wide and 12 tiles tall
--
-- triangle_counting.sql
--
-- get flat file from http://www.vertica.com/benchmark/TriangleCounting/edges.txt.gz
-- gunzip & place in /tmp
--
create or replace directory GRAPH_DATA as '/tmp';
DROP TABLE ET_EDGES;
@gregrahn
gregrahn / rowgen.sql
Created February 10, 2012 22:55
row generator using recursive subquery factoring (recursive with / recursive CTE) in Oracle. More: http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10002.htm#BABCDJDB
WITH RecursiveCTE (rnum) AS
(
SELECT 1 AS rnum
FROM dual
UNION ALL
SELECT rnum + 1
FROM RecursiveCTE
WHERE rnum < 24
)
SELECT rnum
col CURSOR_TYPE for a15
col PROGRAM for a36
select
s.program,
o.sql_id,
o.sql_exec_id,
o.cursor_type,
o.sql_text
from
--
-- open EMP2 tab & browse DATA tab, notice there are 2 open cursors, noting the SQL_EXEC_ID numbers
--
PROGRAM SQL_ID SQL_EXEC_ID CURSOR_TYPE SQL_TEXT
------------------------------------ ------------- ----------- --------------- ------------------------------------------------------------
SQL Developer apdcq2s3sxn9y 16777216 OPEN SELECT ROWID "ROWID", ORA_ROWSCN "ORA_ROWSCN", EMPNO EMPNO,
oracle@localhost.localdomain (P000) apdcq2s3sxn9y 16777216 OPEN-RECURSIVE SELECT ROWID "ROWID", ORA_ROWSCN "ORA_ROWSCN", EMPNO EMPNO,
oracle@localhost.localdomain (P001) apdcq2s3sxn9y 16777216 OPEN-RECURSIVE SELECT ROWID "ROWID", ORA_ROWSCN "ORA_ROWSCN", EMPNO EMPNO,
SQL Developer apdcq2s3sxn9y 16777217 OPEN SELECT ROWID "ROWID", ORA_ROWSCN "ORA_ROWSCN", EMPNO EMPNO,
create table emp2 as select * from emp;
insert into emp2 select * from emp2;
insert into emp2 select * from emp2;
insert into emp2 select * from emp2;
insert into emp2 select * from emp2;
insert into emp2 select * from emp2;
insert into emp2 select * from emp2;
commit;
alter table emp2 parallel 2;
@gregrahn
gregrahn / query2csv.R
Created April 14, 2012 06:28
example of using R to save query results to csv file
library(RJDBC)
drv <-JDBC("oracle.jdbc.driver.OracleDriver","/Users/grahn/code/jdbc/ojdbc6.jar")
conn<-dbConnect(drv,"jdbc:oracle:thin:@grahn-dev.us.oracle.com:1521:orcl","scott","tiger")
data <-dbGetQuery(conn, "select * from emp")
write.table(data, file="emp.csv", sep = ",", row.names=FALSE)