-
Notifications
You must be signed in to change notification settings - Fork 18
/
QueryCalcImpl.java
36 lines (34 loc) · 1.97 KB
/
QueryCalcImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package org.query.calc;
import java.io.IOException;
import java.nio.file.Path;
public class QueryCalcImpl implements QueryCalc {
@Override
public void select(Path t1, Path t2, Path t3, Path output) throws IOException {
// - t1 is a file contains table "t1" with two columns "a" and "x". First line is a number of rows, then each
// line contains exactly one row, that contains two numbers parsable by Double.parse(): value for column a and
// x respectively.See test resources for examples.
// - t2 is a file contains table "t2" with columns "b" and "y". Same format.
// - t3 is a file contains table "t3" with columns "c" and "z". Same format.
// - output is table stored in the same format: first line is a number of rows, then each line is one row that
// contains two numbers: value for column a and s.
//
// Number of rows of all three tables lays in range [0, 1_000_000].
// It's guaranteed that full content of all three tables fits into RAM.
// It's guaranteed that full outer join of at least one pair (t1xt2 or t2xt3 or t1xt3) of tables can fit into RAM.
//
// TODO: Implement following query, put a reasonable effort into making it efficient from perspective of
// computation time, memory usage and resource utilization (in that exact order). You are free to use any lib
// from a maven central.
//
// SELECT a, SUM(x * y * z) AS s FROM
// t1 LEFT JOIN (SELECT * FROM t2 JOIN t3) AS t
// ON a < b + c
// GROUP BY a
// STABLE ORDER BY s DESC
// LIMIT 10;
//
// Note: STABLE is not a standard SQL command. It means that you should preserve the original order.
// In this context it means, that in case of tie on s-value you should prefer value of a, with a lower row number.
// In case multiple occurrences, you may assume that group has a row number of the first occurrence.
}
}