Skip to content
Snippets Groups Projects
Commit 567d55a0 authored by Julien Lopez's avatar Julien Lopez
Browse files

Add tests

parent 7e999c53
No related branches found
No related tags found
No related merge requests found
Showing
with 180 additions and 0 deletions
people = new.tableRef("people", "Hive", "hive.config", "main")
role = new.tableRef("role", "Hive", "hive.config", "main")
director = new.tableRef("director", "Hive", "hive.config", "main")
q = query.where(function (x) x$firstname == "John",
query.join(query.join(query.from(people), query.from(role), function (x,y) x$pid == y$pid),
query.from(director), function (x,y) x$did == y$did))
results = query.force(q)
print(results)
ename
1 SMITH
2 TURNER
3 ADAMS
4 JAMES
5 FORD
6 MILLER
7 ALLEN
8 WARD
9 JONES
10 MARTIN
11 BLAKE
12 CLARK
13 SCOTT
14 KING
people = new.tableRef("people", "Spark", "hive.config", "")
q = query.select(function (x) {
res = new.env()
res$firstname = x$firstname
res },
query.from(people))
results = query.force(q)
print(results)
ename
1 SMITH
2 ALLEN
3 WARD
4 JONES
5 MARTIN
6 BLAKE
7 CLARK
8 SCOTT
9 KING
10 TURNER
11 ADAMS
12 JAMES
13 FORD
14 MILLER
trip = new.tableRef("trip", "PostgreSQL", "postgre.config", "public")
airport = new.tableRef("airport", "HBase", "hbase-site.xml", "default")
q = query.join(query.select(function (t) {
res = new.env()
res$depart = t$depart
res },
query.where(function (t) t$duration > 480L,
query.from(trip))), query.from(airport), function (t,a) t$depart == a$code)
results = query.force(q)
print(results)
code city depart
1 CDG Paris CDG
2 NRT Narita NRT
3 SYD Sydney SYD
trip = new.tableRef("trip", "PostgreSQL", "postgre.config", "public")
airport = new.tableRef("airport", "HBase", "hbase-site.xml", "default")
q = merge(subset(query.from(trip),
function(e) e$duration > 480L,
c(depart)),
query.from(airport), by.x="depart", by.y="code")
results = query.force(q)
print(results)
code city depart
1 CDG Paris CDG
2 NRT Narita NRT
3 SYD Sydney SYD
max_duration = 480L
trip = new.tableRef("trip", "PostgreSQL", "postgre.config", "public")
airport = new.tableRef("airport", "PostgreSQL", "postgre.config", "public")
q = query.select(function (t) {
res = new.env()
res$city = t$city
res$arrival = t$arrival
res$duration = t$duration
res },
query.where(function (t) t$duration > max_duration,
query.join(query.from(trip), query.from(airport), function (t,a) t$depart == a$code)))
results = query.force(q)
print(results)
duration arrival city
1 710 SFO Paris
2 615 LAX Narita
3 510 MNL Sydney
max_duration = 480L
trip = new.tableRef("trip", "PostgreSQL", "postgre.config", "public")
airport = new.tableRef("airport", "PostgreSQL", "postgre.config", "public")
q = subset(merge(query.from(trip), query.from(airport), by.x="depart", by.y="code"),
function(e) e$duration > max_duration,
c(city, arrival, duration))
results = query.force(q)
print(results)
duration arrival city
1 710 SFO Paris
2 615 LAX Narita
3 510 MNL Sydney
emp = new.tableRef("emp", "PostgreSQL", "postgre.config", "public")
dept = new.tableRef("dept", "PostgreSQL", "postgre.config", "public")
q = subset(merge(query.from(emp), query.from(dept), by.x="deptno", by.y="deptno"),
function(e) e$loc == "NEW YORK",
c(ename))
results = query.force(q)
print(results)
ename
1 CLARK
2 KING
3 MILLER
max_duration = 480L
trip = new.tableRef("trip", "PostgreSQL", "postgre.config", "public")
airport = new.tableRef("airport", "PostgreSQL", "postgre.config", "public")
q = query.select(function (t) {
res = new.env()
res$depart = t$depart
res$arrival = t$arrival
res$duration = (function (d){
a = d * 89.0 / 100.0
while (a > 100.0) a = a * 89.0 / 100.0
a
})(t$duration)
res },
query.where(function (t) t$duration > max_duration,
query.join(query.from(trip), query.from(airport), function (t,a) t$depart == a$code)))
results = query.force(q)
print(results)
duration arrival depart
1 97.9238458757057 SFO CDG
2 95.30489826485044 LAX NRT
3 99.77696031866253 MNL SYD
emp = new.tableRef("emp", "PostgreSQL", "postgre.config", "public")
q = (query.from(emp))$ename
results = query.force(q)
print(results)
ename
1 SMITH
2 ALLEN
3 WARD
4 JONES
5 MARTIN
6 BLAKE
7 CLARK
8 SCOTT
9 KING
10 TURNER
11 ADAMS
12 JAMES
13 FORD
14 MILLER
emp = new.tableRef("emp", "PostgreSQL", "postgre.config", "public")
q = subset(query.from(emp),
function(e) e$sal > 2500,
c(ename, sal))
results = query.force(q)
print(results)
ename sal
1 WARD 5220
2 JONES 3500
3 SCOTT 4235
4 ADAMS 5000
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment