Skip to content

Commit e6da779

Browse files
committed
query_expression_type_t -> query_component_type_t
query expressions, query terms and query primaries are all query components. They can either contains non-join elements or joined table elements. So, instead of having a query_expression_type, query_term_type and query_primary_type, let's just have a single query_component_type that can be used by all of the query component subclasses. Issue #78
1 parent 5ff6689 commit e6da779

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

libsqltoast/include/sqltoast/query.h

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,19 @@ typedef struct query_specification {
4343
{}
4444
} query_specification_t;
4545

46-
typedef enum query_expression_type_t {
47-
QUERY_EXPRESSION_TYPE_NON_JOIN_QUERY_EXPRESSION,
48-
QUERY_EXPRESSION_TYPE_JOINED_TABLE
49-
} query_expression_type_t;
46+
// Query components are expressions, terms and primaries. Each of those
47+
// components contains either a non-join query component or a joined table
48+
typedef enum query_component_type_t {
49+
QUERY_COMPONENT_TYPE_NON_JOIN,
50+
QUERY_COMPONENT_TYPE_JOINED_TABLE
51+
} query_component_type_t;
5052

5153
// A query expression produces a table-like selection of rows.
5254

5355
typedef struct query_expression {
54-
query_expression_type_t query_expression_type;
55-
query_expression(query_expression_type_t qe_type) :
56-
query_expression_type(qe_type)
56+
query_component_type_t query_component_type;
57+
query_expression(query_component_type_t qe_type) :
58+
query_component_type(qe_type)
5759
{}
5860
} query_expression_t;
5961

@@ -81,10 +83,18 @@ typedef struct query_specification_non_join_query_primary : non_join_query_prima
8183
{}
8284
} query_specification_non_join_query_primary_t;
8385

84-
typedef struct non_join_query_term {
86+
typedef struct query_term {
87+
query_component_type_t query_component_type;
88+
query_term(query_component_type_t component_type) :
89+
query_component_type(component_type)
90+
{}
91+
} query_term_t;
92+
93+
typedef struct non_join_query_term : query_term_t {
8594
std::unique_ptr<non_join_query_primary_t> primary;
8695
non_join_query_term(
8796
std::unique_ptr<non_join_query_primary_t>& primary) :
97+
query_term_t(QUERY_COMPONENT_TYPE_NON_JOIN),
8898
primary(std::move(primary))
8999
{}
90100
} non_join_query_term_t;
@@ -93,17 +103,16 @@ typedef struct non_join_query_expression : query_expression_t {
93103
std::unique_ptr<non_join_query_term_t> term;
94104
non_join_query_expression(
95105
std::unique_ptr<non_join_query_term_t>& term) :
96-
query_expression_t(QUERY_EXPRESSION_TYPE_NON_JOIN_QUERY_EXPRESSION),
106+
query_expression_t(QUERY_COMPONENT_TYPE_NON_JOIN),
97107
term(std::move(term))
98108
{}
99109
} non_join_query_expression_t;
100110

101111
typedef struct joined_table_query_expression : query_expression_t {
102-
// Guaranteed to be static_castable to joined_table_t
103112
std::unique_ptr<joined_table_t> joined_table;
104113
joined_table_query_expression(
105114
std::unique_ptr<joined_table_t>& joined_table) :
106-
query_expression_t(QUERY_EXPRESSION_TYPE_JOINED_TABLE),
115+
query_expression_t(QUERY_COMPONENT_TYPE_JOINED_TABLE),
107116
joined_table(std::move(joined_table))
108117
{}
109118
} joined_table_query_expression_t;

libsqltoast/src/print/query.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ std::ostream& operator<< (std::ostream& out, const table_expression_t& table_exp
5454
}
5555

5656
std::ostream& operator<< (std::ostream& out, const query_expression_t& qe) {
57-
switch (qe.query_expression_type) {
58-
case QUERY_EXPRESSION_TYPE_NON_JOIN_QUERY_EXPRESSION:
57+
switch (qe.query_component_type) {
58+
case QUERY_COMPONENT_TYPE_NON_JOIN:
5959
{
6060
const non_join_query_expression_t& sub =
6161
static_cast<const non_join_query_expression_t&>(qe);
6262
out << sub;
6363
}
6464
break;
65-
case QUERY_EXPRESSION_TYPE_JOINED_TABLE:
65+
case QUERY_COMPONENT_TYPE_JOINED_TABLE:
6666
{
6767
const joined_table_query_expression_t& sub =
6868
static_cast<const joined_table_query_expression_t&>(qe);

sqltoaster/print/yaml.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,15 @@ void to_yaml(printer_t& ptr, std::ostream& out, const sqltoast::table_expression
331331
}
332332

333333
void to_yaml(printer_t& ptr, std::ostream& out, const sqltoast::query_expression_t& qe) {
334-
switch (qe.query_expression_type) {
335-
case sqltoast::QUERY_EXPRESSION_TYPE_NON_JOIN_QUERY_EXPRESSION:
334+
switch (qe.query_component_type) {
335+
case sqltoast::QUERY_COMPONENT_TYPE_NON_JOIN:
336336
{
337337
const sqltoast::non_join_query_expression_t& sub =
338338
static_cast<const sqltoast::non_join_query_expression_t&>(qe);
339339
to_yaml(ptr, out, sub);
340340
}
341341
break;
342-
case sqltoast::QUERY_EXPRESSION_TYPE_JOINED_TABLE:
342+
case sqltoast::QUERY_COMPONENT_TYPE_JOINED_TABLE:
343343
{
344344
const sqltoast::joined_table_query_expression_t& sub =
345345
static_cast<const sqltoast::joined_table_query_expression_t&>(qe);

0 commit comments

Comments
 (0)