-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest-template.json
30 lines (30 loc) · 3.19 KB
/
manifest-template.json
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
{
"sql": [
"CREATE USER reader REQUIRE ISSUER '/CN=Owner CA' SUBJECT '/CN=Reader'",
"CREATE USER writer REQUIRE ISSUER '/CN=Owner CA' SUBJECT '/CN=Writer'",
"CREATE USER fakeUser ACCOUNT LOCK",
"CREATE DATABASE attribution",
"CREATE TABLE attribution.reports (id MEDIUMINT NOT NULL AUTO_INCREMENT, match_key INT, is_trigger BOOL, value INT, breakdown_key INT, PRIMARY KEY (id))",
"CREATE TABLE attribution.aggregated (id MEDIUMINT AUTO_INCREMENT, value INT DEFAULT 0, PRIMARY KEY (id))",
"CREATE DEFINER=writer PROCEDURE attribution.init_aggregated(breakdown INT) BEGIN DECLARE i INT DEFAULT 0;SET i=0; SET i =0; WHILE i<breakdown DO INSERT INTO attribution.aggregated SET value = 0; SET i=i+1; END WHILE; END",
"CREATE DEFINER=fakeUser PROCEDURE attribution.select_row(IN i INT, OUT trigger_key INT, OUT trigger_id INT, OUT trigger_value INT, OUT row_is_trigger INT) BEGIN SELECT id, match_key, value, is_trigger INTO @trigger_id, @trigger_key, @trigger_value, @row_is_trigger FROM attribution.reports WHERE id = i; END",
"CREATE DEFINER=fakeUser PROCEDURE attribution.match_opt(OUT breakdown_source INT, IN trigger_id INT, IN trigger_key INT) BEGIN SELECT breakdown_key, id INTO @breakdown_source, @max FROM attribution.reports WHERE is_trigger = 0 AND match_key = trigger_key AND id < trigger_id ORDER BY id DESC LIMIT 1; END",
"CREATE DEFINER=fakeUser PROCEDURE attribution.output_opt() BEGIN DECLARE start_time bigint; DECLARE end_time bigint; DECLARE done INT DEFAULT FALSE; DECLARE trigger_key INT DEFAULT 0; DECLARE trigger_id INT DEFAULT 0; DECLARE breakdown_source INT DEFAULT 0; DECLARE trigger_value INT DEFAULT 0; DECLARE sum INT DEFAULT 0; DECLARE cur1 CURSOR FOR SELECT id, match_key, value FROM attribution.reports WHERE is_trigger = 1; DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; SET @start_time = (UNIX_TIMESTAMP(NOW()) * 1000000 + MICROSECOND(NOW(6))); OPEN cur1; read_loop: LOOP FETCH cur1 INTO trigger_id, trigger_key, trigger_value; IF done THEN LEAVE read_loop; END IF; CALL attribution.match_opt(breakdown_source, trigger_id, trigger_key); UPDATE attribution.aggregated SET value = value + trigger_value WHERE id = @breakdown_source; END LOOP; SET @end_time = (UNIX_TIMESTAMP(NOW()) * 1000000 + MICROSECOND(NOW(6))); select (@end_time - @start_time) AS val; END",
"GRANT EXECUTE ON PROCEDURE attribution.output_opt TO fakeUser",
"GRANT EXECUTE ON PROCEDURE attribution.select_row to fakeUser",
"GRANT EXECUTE ON PROCEDURE attribution.match_opt TO fakeUser",
"GRANT INSERT ON attribution.reports TO writer",
"GRANT INSERT ON attribution.aggregated TO writer",
"GRANT EXECUTE ON PROCEDURE attribution.init_aggregated TO writer",
"GRANT SELECT ON attribution.reports TO fakeUser",
"GRANT INSERT ON attribution.aggregated TO fakeUser",
"GRANT SELECT ON attribution.aggregated TO fakeUser",
"GRANT UPDATE ON attribution.aggregated TO fakeUser",
"GRANT EXECUTE ON PROCEDURE attribution.output_opt TO reader",
"GRANT SELECT ON attribution.aggregated TO reader",
"CREATE INDEX match_key_index ON attribution.reports(match_key)",
"CALL attribution.init_aggregated(100)",
"CREATE INDEX is_trigger_index ON attribution.reports(is_trigger ASC)",
"SET profiling = 1"
]
}