Column-oriented GPU-accelerated Database Management System
CoGaDB
|
00001 00002 #ifndef __SQL_PARSETREE_HPP 00003 #define __SQL_PARSETREE_HPP 00004 00005 #include <utility> 00006 #include <list> 00007 #include <string> 00008 00009 #include <boost/any.hpp> 00010 #include <boost/shared_ptr.hpp> 00011 00012 #include <query_processing/query_processor.hpp> 00013 00014 namespace CoGaDB { 00015 namespace SQL { 00016 namespace ParseTree { 00017 00018 /* 00019 * Scalar types 00020 */ 00021 typedef std::string String; 00022 typedef boost::any Integer; 00023 typedef CoGaDB::AggregationMethod AggregationFunction; 00024 00025 /* base class for all Statements */ 00026 class Statement { 00027 public: 00028 virtual ~Statement() {} 00029 00030 virtual TablePtr execute(void) = 0; 00031 }; 00032 typedef boost::shared_ptr<Statement> StatementPtr; 00033 00034 typedef CoGaDB::AttributeType AttributeType; 00035 typedef CoGaDB::Attribut Attribute; 00036 typedef CoGaDB::TableSchema TableSchema; 00037 typedef CoGaDB::Table Table; 00038 typedef CoGaDB::TablePtr TablePtr; 00039 00040 typedef query_processing::LogicalQueryPlan::TypedNodePtr TypedNodePtr; 00041 00042 class CreateTable : public Statement { 00043 TablePtr table; 00044 00045 public: 00046 CreateTable(TablePtr _table) : table(_table) {} 00047 CreateTable(Table *_table) : table(_table) {} 00048 00049 TablePtr execute(void); 00050 }; 00051 00052 struct ScalarExpression { 00053 virtual ~ScalarExpression() {} 00054 00055 virtual void setColumnName(const String &name); 00056 virtual String getQueryPlan(TypedNodePtr &io_node) = 0; 00057 }; 00058 typedef boost::shared_ptr<ScalarExpression> ScalarExpressionPtr; 00059 typedef std::list<ScalarExpressionPtr> ScalarExpressionList; 00060 typedef boost::shared_ptr<ScalarExpressionList> ScalarExpressionListPtr; 00061 00062 struct AtomExpression : public ScalarExpression { 00063 boost::any atom; 00064 AttributeType type; 00065 00066 String explicit_result_colname; 00067 00068 AtomExpression(const boost::any &_atom, AttributeType _type) 00069 : atom(_atom), type(_type) {} 00070 00071 void setColumnName(const String &name); 00072 String toString(); 00073 00074 String getQueryPlan(TypedNodePtr &io_node); 00075 }; 00076 typedef boost::shared_ptr<AtomExpression> AtomExpressionPtr; 00077 00078 struct ColumnExpression : public ScalarExpression { 00079 String column; 00080 00081 ColumnExpression(String &_column) : column(_column) {} 00082 00083 String getQueryPlan(TypedNodePtr &io_node); 00084 }; 00085 typedef boost::shared_ptr<ColumnExpression> ColumnExpressionPtr; 00086 00087 struct FunctionExpression : public ScalarExpression { 00088 AggregationFunction function; 00089 ScalarExpressionPtr param; 00090 00091 FunctionExpression(AggregationFunction _function, 00092 ScalarExpressionPtr _param) 00093 : function(_function), param(_param) {} 00094 00095 void setColumnName(const String &name); 00096 String getQueryPlan(TypedNodePtr &io_node); 00097 }; 00098 typedef boost::shared_ptr<FunctionExpression> FunctionExpressionPtr; 00099 00100 typedef CoGaDB::ColumnAlgebraOperation ColumnAlgebraOperation; 00101 00102 struct AlgebraExpression : public ScalarExpression { 00103 ScalarExpressionPtr lvalue; 00104 ColumnAlgebraOperation op; 00105 ScalarExpressionPtr rvalue; 00106 00107 String explicit_result_colname; 00108 00109 AlgebraExpression(ScalarExpressionPtr _lvalue, 00110 ColumnAlgebraOperation _op, 00111 ScalarExpressionPtr _rvalue) 00112 : lvalue(_lvalue), op(_op), rvalue(_rvalue) {} 00113 00114 void setColumnName(const String &name); 00115 String getQueryPlan(TypedNodePtr &io_node); 00116 }; 00117 00118 struct SearchCondition { 00119 virtual ~SearchCondition() {} 00120 00121 virtual KNF_Selection_Expression getCNF(TypedNodePtr &io_node) = 0; 00122 }; 00123 typedef boost::shared_ptr<SearchCondition> SearchConditionPtr; 00124 00125 struct AndCondition : public SearchCondition { 00126 SearchConditionPtr lvalue; 00127 SearchConditionPtr rvalue; 00128 00129 AndCondition(SearchConditionPtr _lvalue, SearchConditionPtr _rvalue) 00130 : lvalue(_lvalue), rvalue(_rvalue) {} 00131 00132 KNF_Selection_Expression getCNF(TypedNodePtr &io_node); 00133 }; 00134 typedef boost::shared_ptr<AndCondition> AndConditionPtr; 00135 00136 struct OrCondition : public SearchCondition { 00137 SearchConditionPtr lvalue; 00138 SearchConditionPtr rvalue; 00139 00140 OrCondition(SearchConditionPtr _lvalue, SearchConditionPtr _rvalue) 00141 : lvalue(_lvalue), rvalue(_rvalue) {} 00142 00143 KNF_Selection_Expression getCNF(TypedNodePtr &io_node); 00144 }; 00145 typedef boost::shared_ptr<OrCondition> OrConditionPtr; 00146 00154 enum ValueComparator { 00155 LESSER, 00156 LESSER_EQUAL, 00157 GREATER, 00158 GREATER_EQUAL, 00159 EQUAL, 00160 UNEQUAL 00161 }; 00162 00163 struct Predicate : public SearchCondition {}; 00164 00165 struct ComparisonPredicate : public Predicate { 00166 ScalarExpressionPtr lvalue; 00167 ValueComparator op; 00168 ScalarExpressionPtr rvalue; 00169 00170 ComparisonPredicate(ScalarExpressionPtr _lvalue, 00171 ValueComparator _op, 00172 ScalarExpressionPtr _rvalue) 00173 : lvalue(_lvalue), op(_op), rvalue(_rvalue) {} 00174 00175 KNF_Selection_Expression getCNF(TypedNodePtr &io_node); 00176 }; 00177 typedef boost::shared_ptr<ComparisonPredicate> ComparisonPredicatePtr; 00178 00179 struct BetweenPredicate : public Predicate { 00180 AndConditionPtr and_cond; 00181 00182 BetweenPredicate(ScalarExpressionPtr _exp, 00183 ScalarExpressionPtr _lvalue, 00184 ScalarExpressionPtr _rvalue); 00185 00186 KNF_Selection_Expression getCNF(TypedNodePtr &io_node); 00187 }; 00188 00189 struct NotBetweenPredicate : public Predicate { 00190 OrConditionPtr or_cond; 00191 00192 NotBetweenPredicate(ScalarExpressionPtr _exp, 00193 ScalarExpressionPtr _lvalue, 00194 ScalarExpressionPtr _rvalue); 00195 00196 KNF_Selection_Expression getCNF(TypedNodePtr &io_node); 00197 }; 00198 00199 struct TableReference { 00200 virtual ~TableReference() {} 00201 00202 virtual TypedNodePtr getQueryPlan() = 0; 00203 }; 00204 typedef boost::shared_ptr<TableReference> TableReferencePtr; 00205 typedef std::list<TableReferencePtr> TableReferenceList; 00206 00207 struct TableName : public TableReference { 00208 String table; 00209 00210 TableName(String &_table) : table(_table) {} 00211 00212 TypedNodePtr getQueryPlan(); 00213 }; 00214 typedef boost::shared_ptr<TableName> TableNamePtr; 00215 00216 struct Join : public TableReference { 00217 TableReferencePtr lvalue; 00218 TableReferencePtr rvalue; 00219 00220 Join(TableReferencePtr _lvalue, TableReferencePtr _rvalue) 00221 : lvalue(_lvalue), rvalue(_rvalue) {} 00222 }; 00223 00224 struct InnerJoin : public Join { 00225 SearchConditionPtr condition; 00226 00227 InnerJoin(TableReferencePtr _lvalue, TableReferencePtr _rvalue, 00228 SearchConditionPtr _condition) 00229 : Join(_lvalue, _rvalue), condition(_condition) {} 00230 00231 TypedNodePtr getQueryPlan(); 00232 }; 00233 typedef boost::shared_ptr<InnerJoin> InnerJoinPtr; 00234 00235 struct CrossJoin : public Join { 00236 CrossJoin(TableReferencePtr _lvalue, TableReferencePtr _rvalue) 00237 : Join(_lvalue, _rvalue) {} 00238 00239 TypedNodePtr getQueryPlan(); 00240 }; 00241 typedef boost::shared_ptr<CrossJoin> CrossJoinPtr; 00242 00243 typedef std::list<String> ColumnList; 00244 typedef boost::shared_ptr<ColumnList> ColumnListPtr; 00245 typedef CoGaDB::Tuple Tuple; 00246 00247 typedef CoGaDB::SortOrder SortOrder; 00248 typedef std::pair<String, SortOrder> OrderingSpec; 00249 00250 struct OrderBy { 00251 ColumnList list; 00252 SortOrder order; 00253 }; 00254 typedef boost::shared_ptr<OrderBy> OrderByPtr; 00255 00256 class InsertInto : public Statement { 00257 String table; 00258 Tuple row; 00259 00260 public: 00261 InsertInto(TableName &_table, Tuple &_row) 00262 : table(_table.table), row(_row) {} 00263 00264 TablePtr execute(void); 00265 }; 00266 00267 struct TableExpression { 00268 TypedNodePtr table; 00269 ColumnListPtr group_by; 00270 OrderByPtr order_by; 00271 00272 TableExpression(TableReferenceList &from, SearchConditionPtr where, 00273 ColumnListPtr _group_by, OrderByPtr _order_by); 00274 }; 00275 00276 class SelectFrom : public Statement { 00277 TypedNodePtr node; 00278 00279 public: 00280 SelectFrom(ScalarExpressionListPtr columns, TableExpression &table_exp); 00281 00282 TablePtr execute(void); 00283 }; 00284 00285 class Sequence { 00286 std::list<StatementPtr> statements; 00287 00288 public: 00289 inline void 00290 push_back(StatementPtr statement) 00291 { 00292 statements.push_back(statement); 00293 } 00294 inline void 00295 push_back(Statement *statement) 00296 { 00297 push_back(StatementPtr(statement)); 00298 } 00299 00300 TablePtr execute(void); 00301 }; 00302 typedef boost::shared_ptr<Sequence> SequencePtr; 00303 00304 } /* namespace ParseTree */ 00305 } /* namespace SQL */ 00306 } /* namespace CoGaDB */ 00307 00308 #endif