-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse.h
48 lines (40 loc) · 868 Bytes
/
parse.h
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
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef PARSE_H
#define PARSE_H
#include <cassert>
#include "array.h"
#include "pair.h"
enum class PRED {
UNDEFINED,
JOIN,
FILTER,
};
struct Predicate {
PRED kind;
Pair<int, int> lhs;
union {
struct {
int filter_val;
int op;
};
Pair<int, int> rhs;
};
void print() const {
assert(kind != PRED::UNDEFINED);
if (kind == PRED::JOIN) {
printf("%d.%d = %d.%d\n", lhs.first, lhs.second, rhs.first, rhs.second);
} else {
printf("%d.%d %c %d\n", lhs.first, lhs.second, op, filter_val);
}
}
};
constexpr int max_relations = 20;
constexpr int max_columns = 20;
constexpr int max_joins = 4;
struct ParseQueryResult {
int num_relations;
int actual_relations[max_relations + 1];
Array<Predicate> predicates;
Array<Pair<int, int>> sums;
};
ParseQueryResult parse_query(const char *query);
#endif