Skip to content

Commit

Permalink
query_expression_type_t -> query_component_type_t
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jaypipes committed Jun 13, 2018
1 parent 51ca34d commit 7b9b8fc
Show file tree
Hide file tree
Showing 4 changed files with 973 additions and 17 deletions.
31 changes: 20 additions & 11 deletions libsqltoast/include/sqltoast/query.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,19 @@ typedef struct query_specification {
{}
} query_specification_t;

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

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

typedef struct query_expression {
query_expression_type_t query_expression_type;
query_expression(query_expression_type_t qe_type) :
query_expression_type(qe_type)
query_component_type_t query_component_type;
query_expression(query_component_type_t qe_type) :
query_component_type(qe_type)
{}
} query_expression_t;

Expand Down Expand Up @@ -98,10 +100,18 @@ typedef struct table_value_constructor_non_join_query_primary : non_join_query_p
{}
} table_value_constructor_non_join_query_primary_t;

typedef struct non_join_query_term {
typedef struct query_term {
query_component_type_t query_component_type;
query_term(query_component_type_t component_type) :
query_component_type(component_type)
{}
} query_term_t;

typedef struct non_join_query_term : query_term_t {
std::unique_ptr<non_join_query_primary_t> primary;
non_join_query_term(
std::unique_ptr<non_join_query_primary_t>& primary) :
query_term_t(QUERY_COMPONENT_TYPE_NON_JOIN),
primary(std::move(primary))
{}
} non_join_query_term_t;
Expand All @@ -110,17 +120,16 @@ typedef struct non_join_query_expression : query_expression_t {
std::unique_ptr<non_join_query_term_t> term;
non_join_query_expression(
std::unique_ptr<non_join_query_term_t>& term) :
query_expression_t(QUERY_EXPRESSION_TYPE_NON_JOIN_QUERY_EXPRESSION),
query_expression_t(QUERY_COMPONENT_TYPE_NON_JOIN),
term(std::move(term))
{}
} non_join_query_expression_t;

typedef struct joined_table_query_expression : query_expression_t {
// Guaranteed to be static_castable to joined_table_t
std::unique_ptr<joined_table_t> joined_table;
joined_table_query_expression(
std::unique_ptr<joined_table_t>& joined_table) :
query_expression_t(QUERY_EXPRESSION_TYPE_JOINED_TABLE),
query_expression_t(QUERY_COMPONENT_TYPE_JOINED_TABLE),
joined_table(std::move(joined_table))
{}
} joined_table_query_expression_t;
Expand Down
6 changes: 3 additions & 3 deletions libsqltoast/src/print/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ std::ostream& operator<< (std::ostream& out, const table_expression_t& table_exp
}

std::ostream& operator<< (std::ostream& out, const query_expression_t& qe) {
switch (qe.query_expression_type) {
case QUERY_EXPRESSION_TYPE_NON_JOIN_QUERY_EXPRESSION:
switch (qe.query_component_type) {
case QUERY_COMPONENT_TYPE_NON_JOIN:
{
const non_join_query_expression_t& sub =
static_cast<const non_join_query_expression_t&>(qe);
out << sub;
}
break;
case QUERY_EXPRESSION_TYPE_JOINED_TABLE:
case QUERY_COMPONENT_TYPE_JOINED_TABLE:
{
const joined_table_query_expression_t& sub =
static_cast<const joined_table_query_expression_t&>(qe);
Expand Down
6 changes: 3 additions & 3 deletions sqltoaster/node/statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,15 @@ void fill(mapping_t& node, const sqltoast::table_expression_t& table_exp) {
}

void fill(mapping_t& node, const sqltoast::query_expression_t& qe) {
switch (qe.query_expression_type) {
case sqltoast::QUERY_EXPRESSION_TYPE_NON_JOIN_QUERY_EXPRESSION:
switch (qe.query_component_type) {
case sqltoast::QUERY_COMPONENT_TYPE_NON_JOIN:
{
const sqltoast::non_join_query_expression_t& sub =
static_cast<const sqltoast::non_join_query_expression_t&>(qe);
fill(node, sub);
}
break;
case sqltoast::QUERY_EXPRESSION_TYPE_JOINED_TABLE:
case sqltoast::QUERY_COMPONENT_TYPE_JOINED_TABLE:
{
const sqltoast::joined_table_query_expression_t& sub =
static_cast<const sqltoast::joined_table_query_expression_t&>(qe);
Expand Down
Loading

0 comments on commit 7b9b8fc

Please sign in to comment.