OmniSciDB  2e3a973ef4
SerializeToSql.h
Go to the documentation of this file.
1 /*
2  * Copyright 2019 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include "Catalog/Catalog.h"
20 #include "RelAlgExecutionUnit.h"
21 #include "ScalarExprVisitor.h"
22 
23 class ScalarExprToSql : public ScalarExprVisitor<std::string> {
24  public:
25  ScalarExprToSql(const RelAlgExecutionUnit* ra_exe_unit,
26  const Catalog_Namespace::Catalog* catalog);
27 
28  std::string visitVar(const Analyzer::Var*) const override;
29 
30  std::string visitColumnVar(const Analyzer::ColumnVar* col_var) const override;
31 
32  std::string visitConstant(const Analyzer::Constant* constant) const override;
33 
34  std::string visitUOper(const Analyzer::UOper* uoper) const override;
35 
36  std::string visitBinOper(const Analyzer::BinOper* bin_oper) const override;
37 
38  std::string visitInValues(const Analyzer::InValues* in_values) const override;
39 
40  std::string visitLikeExpr(const Analyzer::LikeExpr* like) const override;
41 
42  std::string visitCaseExpr(const Analyzer::CaseExpr* case_) const override;
43 
44  std::string visitFunctionOper(const Analyzer::FunctionOper* func_oper) const override;
45 
46  std::string visitWindowFunction(
47  const Analyzer::WindowFunction* window_func) const override;
48 
49  std::string visitAggExpr(const Analyzer::AggExpr* agg) const override;
50 
51  template <typename List>
52  std::vector<std::string> visitList(const List& expressions) const;
53 
54  protected:
55  std::string aggregateResult(const std::string& aggregate,
56  const std::string& next_result) const override {
57  throw std::runtime_error("Expression not supported yet");
58  }
59 
60  std::string defaultResult() const override {
61  throw std::runtime_error("Expression not supported yet");
62  }
63 
64  private:
65  static std::string binOpTypeToString(const SQLOps op_type);
66 
69 };
70 
71 std::string serialize_table_ref(const int table_id,
72  const Catalog_Namespace::Catalog* catalog);
73 
74 std::string serialize_column_ref(const int table_id,
75  const int column_id,
76  const Catalog_Namespace::Catalog* catalog);
77 
79  std::string query;
80  std::string from_table;
81 };
82 
84  const Catalog_Namespace::Catalog* catalog);
ExecutionUnitSql serialize_to_sql(const RelAlgExecutionUnit *ra_exe_unit, const Catalog_Namespace::Catalog *catalog)
std::string visitColumnVar(const Analyzer::ColumnVar *col_var) const override
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:97
SQLOps
Definition: sqldefs.h:29
ScalarExprToSql(const RelAlgExecutionUnit *ra_exe_unit, const Catalog_Namespace::Catalog *catalog)
std::string visitWindowFunction(const Analyzer::WindowFunction *window_func) const override
std::string visitBinOper(const Analyzer::BinOper *bin_oper) const override
std::string visitConstant(const Analyzer::Constant *constant) const override
std::string visitAggExpr(const Analyzer::AggExpr *agg) const override
This file contains the class specification and related data structures for Catalog.
std::string defaultResult() const override
std::string visitCaseExpr(const Analyzer::CaseExpr *case_) const override
std::string aggregateResult(const std::string &aggregate, const std::string &next_result) const override
std::string visitVar(const Analyzer::Var *) const override
std::string visitLikeExpr(const Analyzer::LikeExpr *like) const override
static std::string binOpTypeToString(const SQLOps op_type)
const RelAlgExecutionUnit * ra_exe_unit_
std::string from_table
std::string visitFunctionOper(const Analyzer::FunctionOper *func_oper) const override
std::string visitUOper(const Analyzer::UOper *uoper) const override
const Catalog_Namespace::Catalog * catalog_
std::string query
std::vector< std::string > visitList(const List &expressions) const
Execution unit for relational algebra. It&#39;s a low-level description of any relational algebra operati...
std::string visitInValues(const Analyzer::InValues *in_values) const override
std::string serialize_table_ref(const int table_id, const Catalog_Namespace::Catalog *catalog)
std::string serialize_column_ref(const int table_id, const int column_id, const Catalog_Namespace::Catalog *catalog)