31 if (
auto base = cast<BaseTable>(ds.get())) {
32 auto name = base->table().name();
34 if (name != ds->alias()) {
36 out_ <<
" AS " << ds->alias();
38 }
else if (
auto query = cast<Query>(ds.get())) {
43 if (ds->alias().has_value())
55 where = where
and ds->filter();
57 where = where
and j->condition();
58 if (not where.empty()) {
69 if (it->second.has_value())
70 out_ <<
" AS " << it->second;
89 out_ <<
" LIMIT " << limit;
91 out_ <<
" OFFSET " << offset;
99 std::ostringstream expr;
111 if (
streq(expr.str().c_str(), alias.c_str()))
114 out_ << expr.str() <<
" AS " << alias;
120 if (p.second.has_value()) {
122 (*this)(p.first.get());
124 std::string alias(*p.second);
135 static uint64_t
id(0);
136 std::ostringstream oss;
137 oss <<
"alias_" <<
id++;
139 return C.
pool(oss.str().c_str());
150 out_ << e.table_name.text <<
'.';
151 out_ << e.attr_name.text;
164 for (
auto it = e.args.cbegin(), end = e.args.cend(); it != end; ++it) {
165 if (it != e.args.cbegin())
183 out_ <<
'(' << e.op().text;
184 if (e.op() == TK_Not)
out_ <<
' ';
193 out_ <<
' ' << e.op().text <<
' ';
200 out_ << e.alias() <<
"._res";
212 for (
auto it = clause.begin(); it != clause.end(); ++it) {
213 if (it != clause.begin())
223 else if (cnf.size() == 1)
226 for (
auto it = cnf.begin(); it != cnf.end(); ++it) {
227 if (it != cnf.begin())
#define M_unreachable(MSG)
::wasm::Expression * expr()
Moves the underlying Binaryen ::wasm::Expression out of this.
std::string replace_all(std::string str, const std::string &from, const std::string &to)
bool streq(const char *first, const char *second)
std::string to_string(const TokenType tt)
ThreadSafeStringPool::proxy_optional_type ThreadSafePooledOptionalString
The catalog contains all Databases and keeps track of all meta information of the database system.
ThreadSafePooledString pool(const char *str) const
Creates an internalized copy of the string str by adding it to the internal StringPool.
static Catalog & Get()
Return a reference to the single Catalog instance.
A data type representing a pooled (or internalized) object.
Translates a query graph in SQL.
void insert_projection(const ast::Expr *)
Inserts a projection for the given Expr which is computed by a grouping operator.
void translate_projection(std::pair< std::reference_wrapper< const ast::Expr >, ThreadSafePooledOptionalString >)
Translates a projection for the given pair of Expr and alias.
void translate(const QueryGraph &)
Translates the given QueryGraph into SQL.
void operator()(const QueryGraph &graph)
static ThreadSafePooledString make_unique_alias()
bool after_grouping_
the graph to translate
std::ostream & out_
the output stream to write to
const QueryGraph * graph_
The query graph represents all data sources and joins in a graph structure.
const auto & group_by() const
const std::vector< projection_type > & projections() const
const auto & joins() const
const auto & order_by() const
const auto & sources() const
A CNF represents a conjunction of cnf::Clauses.
A cnf::Clause represents a disjunction of Predicates.
A Predicate contains a Expr of Boolean type in either positive or negative form.
bool negative() const
Returns true iff this Predicate is negative.