OmniSciDB  85c2d10cdc
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ParserNode.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, 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 
24 #ifndef PARSER_NODE_H_
25 #define PARSER_NODE_H_
26 
27 #include <cstdint>
28 #include <cstring>
29 #include <list>
30 #include <string>
31 
32 #include <boost/algorithm/string/predicate.hpp>
33 #include <boost/process/search_path.hpp>
34 
35 #include "../Analyzer/Analyzer.h"
36 #include "../Catalog/Catalog.h"
37 #include "../Distributed/AggregatedResult.h"
38 #include "../Shared/sqldefs.h"
39 #include "../Shared/sqltypes.h"
41 #include "Utils/DdlUtils.h"
42 
43 #include "../Fragmenter/InsertDataLoader.h"
44 
45 #include <ImportExport/Importer.h>
47 
48 #include <functional>
49 
50 namespace query_state {
51 class QueryState;
52 class QueryStateProxy;
53 } // namespace query_state
55 
56 namespace Parser {
57 
58 /*
59  * @type Node
60  * @brief root super class for all nodes in a pre-Analyzer
61  * parse tree.
62  */
63 class Node {
64  public:
65  virtual ~Node() {}
66 };
67 
68 /*
69  * @type SQLType
70  * @brief class that captures type, predication and scale.
71  */
72 class SQLType : public Node, public ddl_utils::SqlType {
73  public:
74  explicit SQLType(SQLTypes t) : ddl_utils::SqlType(t, -1, 0, false, -1) {}
75  SQLType(SQLTypes t, int p1) : ddl_utils::SqlType(t, p1, 0, false, -1) {}
76  SQLType(SQLTypes t, int p1, int p2, bool a) : ddl_utils::SqlType(t, p1, p2, a, -1) {}
77  SQLType(SQLTypes t, int p1, int p2, bool a, int array_size)
78  : ddl_utils::SqlType(t, p1, p2, a, array_size) {}
79  SQLType(SQLTypes t, bool a, int array_size)
80  : ddl_utils::SqlType(t, -1, 0, a, array_size) {}
81 };
82 
83 /*
84  * @type Expr
85  * @brief root super class for all expression nodes
86  */
87 class Expr : public Node {
88  public:
90  /*
91  * @brief Performs semantic analysis on the expression node
92  * @param catalog The catalog object for the current database
93  * @return An Analyzer::Expr object for the expression post semantic analysis
94  */
95  virtual std::shared_ptr<Analyzer::Expr> analyze(
96  const Catalog_Namespace::Catalog& catalog,
97  Analyzer::Query& query,
98  TlistRefType allow_tlist_ref = TLIST_NONE) const = 0;
99  virtual std::string to_string() const = 0;
100 };
101 
102 /*
103  * @type Literal
104  * @brief root super class for all literals
105  */
106 class Literal : public Expr {
107  public:
108  std::shared_ptr<Analyzer::Expr> analyze(
109  const Catalog_Namespace::Catalog& catalog,
110  Analyzer::Query& query,
111  TlistRefType allow_tlist_ref = TLIST_NONE) const override = 0;
112  std::string to_string() const override = 0;
113 };
114 
115 /*
116  * @type NullLiteral
117  * @brief the Literal NULL
118  */
119 class NullLiteral : public Literal {
120  public:
122  std::shared_ptr<Analyzer::Expr> analyze(
123  const Catalog_Namespace::Catalog& catalog,
124  Analyzer::Query& query,
125  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
126  std::string to_string() const override { return "NULL"; }
127 };
128 
129 /*
130  * @type StringLiteral
131  * @brief the literal for string constants
132  */
133 class StringLiteral : public Literal {
134  public:
135  explicit StringLiteral(std::string* s) : stringval(s) {}
136  const std::string* get_stringval() const { return stringval.get(); }
137  std::shared_ptr<Analyzer::Expr> analyze(
138  const Catalog_Namespace::Catalog& catalog,
139  Analyzer::Query& query,
140  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
141  static std::shared_ptr<Analyzer::Expr> analyzeValue(const std::string&);
142  std::string to_string() const override { return "'" + *stringval + "'"; }
143 
144  private:
145  std::unique_ptr<std::string> stringval;
146 };
147 
148 /*
149  * @type IntLiteral
150  * @brief the literal for integer constants
151  */
152 class IntLiteral : public Literal {
153  public:
154  explicit IntLiteral(int64_t i) : intval(i) {}
155  int64_t get_intval() const { return intval; }
156  std::shared_ptr<Analyzer::Expr> analyze(
157  const Catalog_Namespace::Catalog& catalog,
158  Analyzer::Query& query,
159  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
160  static std::shared_ptr<Analyzer::Expr> analyzeValue(const int64_t intval);
161  std::string to_string() const override {
162  return boost::lexical_cast<std::string>(intval);
163  }
164 
165  private:
166  int64_t intval;
167 };
168 
169 /*
170  * @type FixedPtLiteral
171  * @brief the literal for DECIMAL and NUMERIC
172  */
173 class FixedPtLiteral : public Literal {
174  public:
175  explicit FixedPtLiteral(std::string* n) : fixedptval(n) {}
176  const std::string* get_fixedptval() const { return fixedptval.get(); }
177  std::shared_ptr<Analyzer::Expr> analyze(
178  const Catalog_Namespace::Catalog& catalog,
179  Analyzer::Query& query,
180  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
181  static std::shared_ptr<Analyzer::Expr> analyzeValue(const int64_t numericval,
182  const int scale,
183  const int precision);
184  std::string to_string() const override { return *fixedptval; }
185 
186  private:
187  std::unique_ptr<std::string> fixedptval;
188 };
189 
190 /*
191  * @type FloatLiteral
192  * @brief the literal for FLOAT or REAL
193  */
194 class FloatLiteral : public Literal {
195  public:
196  explicit FloatLiteral(float f) : floatval(f) {}
197  float get_floatval() const { return floatval; }
198  std::shared_ptr<Analyzer::Expr> analyze(
199  const Catalog_Namespace::Catalog& catalog,
200  Analyzer::Query& query,
201  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
202  std::string to_string() const override {
203  return boost::lexical_cast<std::string>(floatval);
204  }
205 
206  private:
207  float floatval;
208 };
209 
210 /*
211  * @type DoubleLiteral
212  * @brief the literal for DOUBLE PRECISION
213  */
214 class DoubleLiteral : public Literal {
215  public:
216  explicit DoubleLiteral(double d) : doubleval(d) {}
217  double get_doubleval() const { return doubleval; }
218  std::shared_ptr<Analyzer::Expr> analyze(
219  const Catalog_Namespace::Catalog& catalog,
220  Analyzer::Query& query,
221  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
222  std::string to_string() const override {
223  return boost::lexical_cast<std::string>(doubleval);
224  }
225 
226  private:
227  double doubleval;
228 };
229 
230 /*
231  * @type TimestampLiteral
232  * @brief the literal for Timestamp
233  */
234 class TimestampLiteral : public Literal {
235  public:
236  explicit TimestampLiteral() { time(reinterpret_cast<time_t*>(&timestampval_)); }
237  std::shared_ptr<Analyzer::Expr> analyze(
238  const Catalog_Namespace::Catalog& catalog,
239  Analyzer::Query& query,
240  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
241  static std::shared_ptr<Analyzer::Expr> get(const int64_t);
242  std::string to_string() const override {
243  // TODO: Should we convert to a datum and use the datum toString converters to pretty
244  // print?
245  return boost::lexical_cast<std::string>(timestampval_);
246  }
247 
248  private:
249  int64_t timestampval_;
250 };
251 
252 /*
253  * @type UserLiteral
254  * @brief the literal for USER
255  */
256 class UserLiteral : public Literal {
257  public:
259  std::shared_ptr<Analyzer::Expr> analyze(
260  const Catalog_Namespace::Catalog& catalog,
261  Analyzer::Query& query,
262  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
263  static std::shared_ptr<Analyzer::Expr> get(const std::string&);
264  std::string to_string() const override { return "USER"; }
265 };
266 
267 /*
268  * @type ArrayLiteral
269  * @brief the literal for arrays
270  */
271 class ArrayLiteral : public Literal {
272  public:
274  ArrayLiteral(std::list<Expr*>* v) {
275  CHECK(v);
276  for (const auto e : *v) {
277  value_list.emplace_back(e);
278  }
279  delete v;
280  }
281  const std::list<std::unique_ptr<Expr>>& get_value_list() const { return value_list; }
282  std::shared_ptr<Analyzer::Expr> analyze(
283  const Catalog_Namespace::Catalog& catalog,
284  Analyzer::Query& query,
285  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
286  std::string to_string() const override;
287 
288  private:
289  std::list<std::unique_ptr<Expr>> value_list;
290 };
291 
292 /*
293  * @type OperExpr
294  * @brief all operator expressions
295  */
296 class OperExpr : public Expr {
297  public:
299  : optype(t), opqualifier(kONE), left(l), right(r) {}
301  : optype(t), opqualifier(q), left(l), right(r) {}
302  SQLOps get_optype() const { return optype; }
303  const Expr* get_left() const { return left.get(); }
304  const Expr* get_right() const { return right.get(); }
305  std::shared_ptr<Analyzer::Expr> analyze(
306  const Catalog_Namespace::Catalog& catalog,
307  Analyzer::Query& query,
308  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
309  static std::shared_ptr<Analyzer::Expr> normalize(
310  const SQLOps optype,
311  const SQLQualifier qual,
312  std::shared_ptr<Analyzer::Expr> left_expr,
313  std::shared_ptr<Analyzer::Expr> right_expr);
314  std::string to_string() const override;
315 
316  private:
319  std::unique_ptr<Expr> left;
320  std::unique_ptr<Expr> right;
321 };
322 
323 // forward reference of QuerySpec
324 class QuerySpec;
325 
326 /*
327  * @type SubqueryExpr
328  * @brief expression for subquery
329  */
330 class SubqueryExpr : public Expr {
331  public:
332  explicit SubqueryExpr(QuerySpec* q) : query(q) {}
333  const QuerySpec* get_query() const { return query.get(); }
334  std::shared_ptr<Analyzer::Expr> analyze(
335  const Catalog_Namespace::Catalog& catalog,
337  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
338  std::string to_string() const override;
339 
340  private:
341  std::unique_ptr<QuerySpec> query;
342 };
343 
344 class IsNullExpr : public Expr {
345  public:
346  IsNullExpr(bool n, Expr* a) : is_not(n), arg(a) {}
347  bool get_is_not() const { return is_not; }
348  std::shared_ptr<Analyzer::Expr> analyze(
349  const Catalog_Namespace::Catalog& catalog,
350  Analyzer::Query& query,
351  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
352  std::string to_string() const override;
353 
354  private:
355  bool is_not;
356  std::unique_ptr<Expr> arg;
357 };
358 
359 /*
360  * @type InExpr
361  * @brief expression for the IS NULL predicate
362  */
363 class InExpr : public Expr {
364  public:
365  InExpr(bool n, Expr* a) : is_not(n), arg(a) {}
366  bool get_is_not() const { return is_not; }
367  const Expr* get_arg() const { return arg.get(); }
368  std::shared_ptr<Analyzer::Expr> analyze(
369  const Catalog_Namespace::Catalog& catalog,
370  Analyzer::Query& query,
371  TlistRefType allow_tlist_ref = TLIST_NONE) const override = 0;
372  std::string to_string() const override;
373 
374  protected:
375  bool is_not;
376  std::unique_ptr<Expr> arg;
377 };
378 
379 /*
380  * @type InSubquery
381  * @brief expression for the IN (subquery) predicate
382  */
383 class InSubquery : public InExpr {
384  public:
385  InSubquery(bool n, Expr* a, SubqueryExpr* q) : InExpr(n, a), subquery(q) {}
386  const SubqueryExpr* get_subquery() const { return subquery.get(); }
387  std::shared_ptr<Analyzer::Expr> analyze(
388  const Catalog_Namespace::Catalog& catalog,
389  Analyzer::Query& query,
390  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
391  std::string to_string() const override;
392 
393  private:
394  std::unique_ptr<SubqueryExpr> subquery;
395 };
396 
397 /*
398  * @type InValues
399  * @brief expression for IN (val1, val2, ...)
400  */
401 class InValues : public InExpr {
402  public:
403  InValues(bool n, Expr* a, std::list<Expr*>* v) : InExpr(n, a) {
404  CHECK(v);
405  for (const auto e : *v) {
406  value_list.emplace_back(e);
407  }
408  delete v;
409  }
410  const std::list<std::unique_ptr<Expr>>& get_value_list() const { return value_list; }
411  std::shared_ptr<Analyzer::Expr> analyze(
412  const Catalog_Namespace::Catalog& catalog,
413  Analyzer::Query& query,
414  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
415  std::string to_string() const override;
416 
417  private:
418  std::list<std::unique_ptr<Expr>> value_list;
419 };
420 
421 /*
422  * @type BetweenExpr
423  * @brief expression for BETWEEN lower AND upper
424  */
425 class BetweenExpr : public Expr {
426  public:
427  BetweenExpr(bool n, Expr* a, Expr* l, Expr* u)
428  : is_not(n), arg(a), lower(l), upper(u) {}
429  bool get_is_not() const { return is_not; }
430  const Expr* get_arg() const { return arg.get(); }
431  const Expr* get_lower() const { return lower.get(); }
432  const Expr* get_upper() const { return upper.get(); }
433  std::shared_ptr<Analyzer::Expr> analyze(
434  const Catalog_Namespace::Catalog& catalog,
435  Analyzer::Query& query,
436  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
437  std::string to_string() const override;
438 
439  private:
440  bool is_not;
441  std::unique_ptr<Expr> arg;
442  std::unique_ptr<Expr> lower;
443  std::unique_ptr<Expr> upper;
444 };
445 
446 /*
447  * @type CharLengthExpr
448  * @brief expression to get length of string
449  */
450 
451 class CharLengthExpr : public Expr {
452  public:
453  CharLengthExpr(Expr* a, bool e) : arg(a), calc_encoded_length(e) {}
454  const Expr* get_arg() const { return arg.get(); }
456  std::shared_ptr<Analyzer::Expr> analyze(
457  const Catalog_Namespace::Catalog& catalog,
458  Analyzer::Query& query,
459  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
460  std::string to_string() const override;
461 
462  private:
463  std::unique_ptr<Expr> arg;
465 };
466 
467 /*
468  * @type CardinalityExpr
469  * @brief expression to get cardinality of an array
470  */
471 
472 class CardinalityExpr : public Expr {
473  public:
475  const Expr* get_arg() const { return arg.get(); }
476  std::shared_ptr<Analyzer::Expr> analyze(
477  const Catalog_Namespace::Catalog& catalog,
478  Analyzer::Query& query,
479  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
480  std::string to_string() const override;
481 
482  private:
483  std::unique_ptr<Expr> arg;
484 };
485 
486 /*
487  * @type LikeExpr
488  * @brief expression for the LIKE predicate
489  */
490 class LikeExpr : public Expr {
491  public:
492  LikeExpr(bool n, bool i, Expr* a, Expr* l, Expr* e)
493  : is_not(n), is_ilike(i), arg(a), like_string(l), escape_string(e) {}
494  bool get_is_not() const { return is_not; }
495  const Expr* get_arg() const { return arg.get(); }
496  const Expr* get_like_string() const { return like_string.get(); }
497  const Expr* get_escape_string() const { return escape_string.get(); }
498  std::shared_ptr<Analyzer::Expr> analyze(
499  const Catalog_Namespace::Catalog& catalog,
500  Analyzer::Query& query,
501  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
502  static std::shared_ptr<Analyzer::Expr> get(std::shared_ptr<Analyzer::Expr> arg_expr,
503  std::shared_ptr<Analyzer::Expr> like_expr,
504  std::shared_ptr<Analyzer::Expr> escape_expr,
505  const bool is_ilike,
506  const bool is_not);
507  std::string to_string() const override;
508 
509  private:
510  bool is_not;
511  bool is_ilike;
512  std::unique_ptr<Expr> arg;
513  std::unique_ptr<Expr> like_string;
514  std::unique_ptr<Expr> escape_string;
515 
516  static void check_like_expr(const std::string& like_str, char escape_char);
517  static bool test_is_simple_expr(const std::string& like_str, char escape_char);
518  static void erase_cntl_chars(std::string& like_str, char escape_char);
519 };
520 
521 /*
522  * @type RegexpExpr
523  * @brief expression for REGEXP
524  */
525 class RegexpExpr : public Expr {
526  public:
527  RegexpExpr(bool n, Expr* a, Expr* p, Expr* e)
528  : is_not(n), arg(a), pattern_string(p), escape_string(e) {}
529  bool get_is_not() const { return is_not; }
530  const Expr* get_arg() const { return arg.get(); }
531  const Expr* get_pattern_string() const { return pattern_string.get(); }
532  const Expr* get_escape_string() const { return escape_string.get(); }
533  std::shared_ptr<Analyzer::Expr> analyze(
534  const Catalog_Namespace::Catalog& catalog,
535  Analyzer::Query& query,
536  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
537  static std::shared_ptr<Analyzer::Expr> get(std::shared_ptr<Analyzer::Expr> arg_expr,
538  std::shared_ptr<Analyzer::Expr> pattern_expr,
539  std::shared_ptr<Analyzer::Expr> escape_expr,
540  const bool is_not);
541  std::string to_string() const override;
542 
543  private:
544  bool is_not;
545  std::unique_ptr<Expr> arg;
546  std::unique_ptr<Expr> pattern_string;
547  std::unique_ptr<Expr> escape_string;
548 
549  static void check_pattern_expr(const std::string& pattern_str, char escape_char);
550  static bool translate_to_like_pattern(std::string& pattern_str, char escape_char);
551 };
552 
553 /*
554  * @type LikelihoodExpr
555  * @brief expression for LIKELY, UNLIKELY
556  */
557 class LikelihoodExpr : public Expr {
558  public:
559  LikelihoodExpr(bool n, Expr* a, float l) : is_not(n), arg(a), likelihood(l) {}
560  bool get_is_not() const { return is_not; }
561  const Expr* get_arg() const { return arg.get(); }
562  float get_likelihood() const { return likelihood; }
563  std::shared_ptr<Analyzer::Expr> analyze(
564  const Catalog_Namespace::Catalog& catalog,
565  Analyzer::Query& query,
566  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
567  static std::shared_ptr<Analyzer::Expr> get(std::shared_ptr<Analyzer::Expr> arg_expr,
568  float likelihood,
569  const bool is_not);
570  std::string to_string() const override;
571 
572  private:
573  bool is_not;
574  std::unique_ptr<Expr> arg;
575  float likelihood;
576 };
577 
578 /*
579  * @type ExistsExpr
580  * @brief expression for EXISTS (subquery)
581  */
582 class ExistsExpr : public Expr {
583  public:
584  explicit ExistsExpr(QuerySpec* q) : query(q) {}
585  const QuerySpec* get_query() const { return query.get(); }
586  std::shared_ptr<Analyzer::Expr> analyze(
587  const Catalog_Namespace::Catalog& catalog,
589  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
590  std::string to_string() const override;
591 
592  private:
593  std::unique_ptr<QuerySpec> query;
594 };
595 
596 /*
597  * @type ColumnRef
598  * @brief expression for a column reference
599  */
600 class ColumnRef : public Expr {
601  public:
602  explicit ColumnRef(std::string* n1) : table(nullptr), column(n1) {}
603  ColumnRef(std::string* n1, std::string* n2) : table(n1), column(n2) {}
604  const std::string* get_table() const { return table.get(); }
605  const std::string* get_column() const { return column.get(); }
606  std::shared_ptr<Analyzer::Expr> analyze(
607  const Catalog_Namespace::Catalog& catalog,
608  Analyzer::Query& query,
609  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
610  std::string to_string() const override;
611 
612  private:
613  std::unique_ptr<std::string> table;
614  std::unique_ptr<std::string> column; // can be nullptr in the t.* case
615 };
616 
617 /*
618  * @type FunctionRef
619  * @brief expression for a function call
620  */
621 class FunctionRef : public Expr {
622  public:
623  explicit FunctionRef(std::string* n) : name(n), distinct(false), arg(nullptr) {}
624  FunctionRef(std::string* n, Expr* a) : name(n), distinct(false), arg(a) {}
625  FunctionRef(std::string* n, bool d, Expr* a) : name(n), distinct(d), arg(a) {}
626  const std::string* get_name() const { return name.get(); }
627  bool get_distinct() const { return distinct; }
628  Expr* get_arg() const { return arg.get(); }
629  std::shared_ptr<Analyzer::Expr> analyze(
630  const Catalog_Namespace::Catalog& catalog,
631  Analyzer::Query& query,
632  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
633  std::string to_string() const override;
634 
635  private:
636  std::unique_ptr<std::string> name;
637  bool distinct; // only true for COUNT(DISTINCT x)
638  std::unique_ptr<Expr> arg; // for COUNT, nullptr means '*'
639 };
640 
641 class CastExpr : public Expr {
642  public:
643  CastExpr(Expr* a, SQLType* t) : arg(a), target_type(t) {}
644  std::shared_ptr<Analyzer::Expr> analyze(
645  const Catalog_Namespace::Catalog& catalog,
646  Analyzer::Query& query,
647  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
648  std::string to_string() const override {
649  return "CAST(" + arg->to_string() + " AS " + target_type->to_string() + ")";
650  }
651 
652  private:
653  std::unique_ptr<Expr> arg;
654  std::unique_ptr<SQLType> target_type;
655 };
656 
657 class ExprPair : public Node {
658  public:
659  ExprPair(Expr* e1, Expr* e2) : expr1(e1), expr2(e2) {}
660  const Expr* get_expr1() const { return expr1.get(); }
661  const Expr* get_expr2() const { return expr2.get(); }
662 
663  private:
664  std::unique_ptr<Expr> expr1;
665  std::unique_ptr<Expr> expr2;
666 };
667 
668 class CaseExpr : public Expr {
669  public:
670  CaseExpr(std::list<ExprPair*>* w, Expr* e) : else_expr(e) {
671  CHECK(w);
672  for (const auto e : *w) {
673  when_then_list.emplace_back(e);
674  }
675  delete w;
676  }
677  std::shared_ptr<Analyzer::Expr> analyze(
678  const Catalog_Namespace::Catalog& catalog,
679  Analyzer::Query& query,
680  TlistRefType allow_tlist_ref = TLIST_NONE) const override;
681  static std::shared_ptr<Analyzer::Expr> normalize(
682  const std::list<
683  std::pair<std::shared_ptr<Analyzer::Expr>, std::shared_ptr<Analyzer::Expr>>>&,
684  const std::shared_ptr<Analyzer::Expr>);
685  std::string to_string() const override;
686 
687  private:
688  std::list<std::unique_ptr<ExprPair>> when_then_list;
689  std::unique_ptr<Expr> else_expr;
690 };
691 
692 /*
693  * @type TableRef
694  * @brief table reference in FROM clause
695  */
696 class TableRef : public Node {
697  public:
698  explicit TableRef(std::string* t) : table_name(t), range_var(nullptr) {}
699  TableRef(std::string* t, std::string* r) : table_name(t), range_var(r) {}
700  const std::string* get_table_name() const { return table_name.get(); }
701  const std::string* get_range_var() const { return range_var.get(); }
702  std::string to_string() const;
703 
704  private:
705  std::unique_ptr<std::string> table_name;
706  std::unique_ptr<std::string> range_var;
707 };
708 
709 /*
710  * @type Stmt
711  * @brief root super class for all SQL statements
712  */
713 class Stmt : public Node {
714  // intentionally empty
715 };
716 
717 /*
718  * @type DMLStmt
719  * @brief DML Statements
720  */
721 class DMLStmt : public Stmt {
722  public:
723  virtual void analyze(const Catalog_Namespace::Catalog& catalog,
724  Analyzer::Query& query) const = 0;
725 };
726 
727 /*
728  * @type DDLStmt
729  * @brief DDL Statements
730  */
731 class ColumnDef;
732 class DDLStmt : public Stmt {
733  public:
734  virtual void execute(const Catalog_Namespace::SessionInfo& session) = 0;
735  void setColumnDescriptor(ColumnDescriptor& cd, const ColumnDef* coldef);
736 };
737 
738 /*
739  * @type TableElement
740  * @brief elements in table definition
741  */
742 class TableElement : public Node {
743  // intentionally empty
744 };
745 
746 /*
747  * @type ColumnConstraintDef
748  * @brief integrity constraint on a column
749  */
750 class ColumnConstraintDef : public Node {
751  public:
752  ColumnConstraintDef(bool n, bool u, bool p, Literal* d)
753  : notnull(n), unique(u), is_primarykey(p), defaultval(d) {}
756  ColumnConstraintDef(std::string* t, std::string* c)
757  : notnull(false)
758  , unique(false)
760  , foreign_table(t)
761  , foreign_column(c) {}
762  bool get_notnull() const { return notnull; }
763  bool get_unique() const { return unique; }
764  bool get_is_primarykey() const { return is_primarykey; }
765  const Literal* get_defaultval() const { return defaultval.get(); }
766  const Expr* get_check_condition() const { return check_condition.get(); }
767  const std::string* get_foreign_table() const { return foreign_table.get(); }
768  const std::string* get_foreign_column() const { return foreign_column.get(); }
769 
770  private:
771  bool notnull;
772  bool unique;
774  std::unique_ptr<Literal> defaultval;
775  std::unique_ptr<Expr> check_condition;
776  std::unique_ptr<std::string> foreign_table;
777  std::unique_ptr<std::string> foreign_column;
778 };
779 
780 /*
781  * @type CompressDef
782  * @brief Node for compression scheme definition
783  */
784 class CompressDef : public Node, public ddl_utils::Encoding {
785  public:
786  CompressDef(std::string* n, int p) : ddl_utils::Encoding(n, p) {}
787 };
788 
789 /*
790  * @type ColumnDef
791  * @brief Column definition
792  */
793 class ColumnDef : public TableElement {
794  public:
795  ColumnDef(std::string* c, SQLType* t, CompressDef* cp, ColumnConstraintDef* cc)
797  const std::string* get_column_name() const { return column_name.get(); }
798  SQLType* get_column_type() const { return column_type.get(); }
799  const CompressDef* get_compression() const { return compression.get(); }
801  return column_constraint.get();
802  }
803 
804  private:
805  std::unique_ptr<std::string> column_name;
806  std::unique_ptr<SQLType> column_type;
807  std::unique_ptr<CompressDef> compression;
808  std::unique_ptr<ColumnConstraintDef> column_constraint;
809 };
810 
811 /*
812  * @type TableConstraintDef
813  * @brief integrity constraint for table
814  */
816  // intentionally empty
817 };
818 
819 /*
820  * @type UniqueDef
821  * @brief uniqueness constraint
822  */
824  public:
825  UniqueDef(bool p, std::list<std::string*>* cl) : is_primarykey(p) {
826  CHECK(cl);
827  for (const auto s : *cl) {
828  column_list.emplace_back(s);
829  }
830  delete cl;
831  }
832  bool get_is_primarykey() const { return is_primarykey; }
833  const std::list<std::unique_ptr<std::string>>& get_column_list() const {
834  return column_list;
835  }
836 
837  private:
839  std::list<std::unique_ptr<std::string>> column_list;
840 };
841 
842 /*
843  * @type ForeignKeyDef
844  * @brief foreign key constraint
845  */
847  public:
848  ForeignKeyDef(std::list<std::string*>* cl, std::string* t, std::list<std::string*>* fcl)
849  : foreign_table(t) {
850  CHECK(cl);
851  for (const auto s : *cl) {
852  column_list.emplace_back(s);
853  }
854  delete cl;
855  if (fcl) {
856  for (const auto s : *fcl) {
857  foreign_column_list.emplace_back(s);
858  }
859  }
860  delete fcl;
861  }
862  const std::list<std::unique_ptr<std::string>>& get_column_list() const {
863  return column_list;
864  }
865  const std::string* get_foreign_table() const { return foreign_table.get(); }
866  const std::list<std::unique_ptr<std::string>>& get_foreign_column_list() const {
867  return foreign_column_list;
868  }
869 
870  private:
871  std::list<std::unique_ptr<std::string>> column_list;
872  std::unique_ptr<std::string> foreign_table;
873  std::list<std::unique_ptr<std::string>> foreign_column_list;
874 };
875 
876 /*
877  * @type CheckDef
878  * @brief Check constraint
879  */
880 class CheckDef : public TableConstraintDef {
881  public:
883  const Expr* get_check_condition() const { return check_condition.get(); }
884 
885  private:
886  std::unique_ptr<Expr> check_condition;
887 };
888 
889 /*
890  * @type SharedDictionaryDef
891  * @brief Shared dictionary hint. The underlying string dictionary will be shared with the
892  * referenced column.
893  */
895  public:
896  SharedDictionaryDef(const std::string& column,
897  const std::string& foreign_table,
898  const std::string foreign_column)
899  : column_(column), foreign_table_(foreign_table), foreign_column_(foreign_column) {}
900 
901  const std::string& get_column() const { return column_; }
902 
903  const std::string& get_foreign_table() const { return foreign_table_; }
904 
905  const std::string& get_foreign_column() const { return foreign_column_; }
906 
907  private:
908  const std::string column_;
909  const std::string foreign_table_;
910  const std::string foreign_column_;
911 };
912 
913 /*
914  * @type ShardKeyDef
915  * @brief Shard key for a table, mainly useful for distributed joins.
916  */
918  public:
919  ShardKeyDef(const std::string& column) : column_(column) {}
920 
921  const std::string& get_column() const { return column_; }
922 
923  private:
924  const std::string column_;
925 };
926 
927 /*
928  * @type NameValueAssign
929  * @brief Assignment of a string value to a named attribute
930  */
931 class NameValueAssign : public Node {
932  public:
933  NameValueAssign(std::string* n, Literal* v) : name(n), value(v) {}
934  const std::string* get_name() const { return name.get(); }
935  const Literal* get_value() const { return value.get(); }
936 
937  private:
938  std::unique_ptr<std::string> name;
939  std::unique_ptr<Literal> value;
940 };
941 
942 /*
943  * @type CreateTableBaseStmt
944  */
945 class CreateTableBaseStmt : public DDLStmt {
946  public:
947  virtual const std::string* get_table() const = 0;
948  virtual const std::list<std::unique_ptr<TableElement>>& get_table_element_list()
949  const = 0;
950 };
951 
952 /*
953  * @type CreateTableStmt
954  * @brief CREATE TABLE statement
955  */
957  public:
958  CreateTableStmt(std::string* tab,
959  const std::string* storage,
960  std::list<TableElement*>* table_elems,
961  bool is_temporary,
962  bool if_not_exists,
963  std::list<NameValueAssign*>* s)
964  : table_(tab), is_temporary_(is_temporary), if_not_exists_(if_not_exists) {
965  CHECK(table_elems);
966  for (const auto e : *table_elems) {
967  table_element_list_.emplace_back(e);
968  }
969  delete table_elems;
970  if (s) {
971  for (const auto e : *s) {
972  storage_options_.emplace_back(e);
973  }
974  delete s;
975  }
976  }
977 
978  CreateTableStmt(const rapidjson::Value& payload);
979 
980  const std::string* get_table() const override { return table_.get(); }
981  const std::list<std::unique_ptr<TableElement>>& get_table_element_list()
982  const override {
983  return table_element_list_;
984  }
985 
986  void execute(const Catalog_Namespace::SessionInfo& session) override;
987  void executeDryRun(const Catalog_Namespace::SessionInfo& session,
988  TableDescriptor& td,
989  std::list<ColumnDescriptor>& columns,
990  std::vector<SharedDictionaryDef>& shared_dict_defs);
991 
992  private:
993  std::unique_ptr<std::string> table_;
994  std::list<std::unique_ptr<TableElement>> table_element_list_;
997  std::list<std::unique_ptr<NameValueAssign>> storage_options_;
998 };
999 
1003 
1004  virtual size_t getOuterFragmentCount(QueryStateProxy,
1005  std::string& sql_query_string) = 0;
1006  virtual std::vector<AggregatedResult> query(QueryStateProxy,
1007  std::string& sql_query_string,
1008  std::vector<size_t> outer_frag_indices,
1009  bool allow_interrupt) = 0;
1010  virtual void checkpoint(const Catalog_Namespace::SessionInfo& parent_session_info,
1011  int tableId) = 0;
1012  virtual void rollback(const Catalog_Namespace::SessionInfo& parent_session_info,
1013  int tableId) = 0;
1014 };
1015 
1017  virtual ~LocalConnector() {}
1018 
1019  size_t getOuterFragmentCount(QueryStateProxy, std::string& sql_query_string) override;
1020 
1022  std::string& sql_query_string,
1023  std::vector<size_t> outer_frag_indices,
1024  bool validate_only,
1025  bool allow_interrupt);
1026  std::vector<AggregatedResult> query(QueryStateProxy,
1027  std::string& sql_query_string,
1028  std::vector<size_t> outer_frag_indices,
1029  bool allow_interrupt) override;
1030  size_t leafCount() override { return 1; };
1032  const size_t leaf_idx,
1033  Fragmenter_Namespace::InsertData& insert_data) override;
1034  void checkpoint(const Catalog_Namespace::SessionInfo& session, int tableId) override;
1035  void rollback(const Catalog_Namespace::SessionInfo& session, int tableId) override;
1036  std::list<ColumnDescriptor> getColumnDescriptors(AggregatedResult& result,
1037  bool for_create);
1038 };
1039 
1040 /*
1041  * @type CreateDataframeStmt
1042  * @brief CREATE DATAFRAME statement
1043  */
1045  public:
1046  CreateDataframeStmt(std::string* tab,
1047  std::list<TableElement*>* table_elems,
1048  std::string* filename,
1049  std::list<NameValueAssign*>* s)
1050  : table_(tab), filename_(filename) {
1051  CHECK(table_elems);
1052  for (const auto e : *table_elems) {
1053  table_element_list_.emplace_back(e);
1054  }
1055  delete table_elems;
1056  if (s) {
1057  for (const auto e : *s) {
1058  storage_options_.emplace_back(e);
1059  }
1060  delete s;
1061  }
1062  }
1063  const std::string* get_table() const override { return table_.get(); }
1064  const std::list<std::unique_ptr<TableElement>>& get_table_element_list()
1065  const override {
1066  return table_element_list_;
1067  }
1068 
1069  void execute(const Catalog_Namespace::SessionInfo& session) override;
1070 
1071  private:
1072  std::unique_ptr<std::string> table_;
1073  std::list<std::unique_ptr<TableElement>> table_element_list_;
1074  std::unique_ptr<std::string> filename_;
1075  std::list<std::unique_ptr<NameValueAssign>> storage_options_;
1076 };
1077 
1078 /*
1079  * @type InsertIntoTableAsSelectStmt
1080  * @brief INSERT INTO TABLE SELECT statement
1081  */
1083  public:
1084  // ITAS constructor
1085  InsertIntoTableAsSelectStmt(const std::string* table_name,
1086  const std::string* select_query,
1087  std::list<std::string*>* c)
1088  : table_name_(*table_name), select_query_(*select_query) {
1089  if (c) {
1090  for (auto e : *c) {
1091  column_list_.emplace_back(e);
1092  }
1093  delete c;
1094  }
1095 
1096  delete table_name;
1097  delete select_query;
1098  }
1099 
1101  const TableDescriptor* td,
1102  bool validate_table,
1103  bool for_CTAS = false);
1104  void execute(const Catalog_Namespace::SessionInfo& session) override;
1105 
1106  std::string& get_table() { return table_name_; }
1107 
1108  std::string& get_select_query() { return select_query_; }
1109 
1111 
1112  protected:
1113  std::vector<std::unique_ptr<std::string>> column_list_;
1114  std::string table_name_;
1115  std::string select_query_;
1116 };
1117 
1118 /*
1119  * @type CreateTableAsSelectStmt
1120  * @brief CREATE TABLE AS SELECT statement
1121  */
1123  public:
1124  CreateTableAsSelectStmt(const std::string* table_name,
1125  const std::string* select_query,
1126  const bool is_temporary,
1127  const bool if_not_exists,
1128  std::list<NameValueAssign*>* s)
1129  : InsertIntoTableAsSelectStmt(table_name, select_query, nullptr)
1130  , is_temporary_(is_temporary)
1131  , if_not_exists_(if_not_exists) {
1132  if (s) {
1133  for (const auto& e : *s) {
1134  storage_options_.emplace_back(e);
1135  }
1136  delete s;
1137  }
1138  }
1139 
1140  void execute(const Catalog_Namespace::SessionInfo& session) override;
1141 
1142  private:
1143  const bool is_temporary_;
1144  const bool if_not_exists_;
1145  std::list<std::unique_ptr<NameValueAssign>> storage_options_;
1146 };
1147 
1148 /*
1149  * @type DropTableStmt
1150  * @brief DROP TABLE statement
1151  */
1152 class DropTableStmt : public DDLStmt {
1153  public:
1154  DropTableStmt(std::string* tab, bool i) : table(tab), if_exists(i) {}
1155  DropTableStmt(const rapidjson::Value& payload);
1156 
1157  const std::string* get_table() const { return table.get(); }
1158  void execute(const Catalog_Namespace::SessionInfo& session) override;
1159 
1160  private:
1161  std::unique_ptr<std::string> table;
1163 };
1164 
1165 /*
1166  * @type TruncateTableStmt
1167  * @brief TRUNCATE TABLE statement
1168  */
1169 class TruncateTableStmt : public DDLStmt {
1170  public:
1171  TruncateTableStmt(std::string* tab) : table(tab) {}
1172  const std::string* get_table() const { return table.get(); }
1173  void execute(const Catalog_Namespace::SessionInfo& session) override;
1174 
1175  private:
1176  std::unique_ptr<std::string> table;
1177 };
1178 
1179 class OptimizeTableStmt : public DDLStmt {
1180  public:
1181  OptimizeTableStmt(std::string* table, std::list<NameValueAssign*>* o) : table_(table) {
1182  if (!table_) {
1183  throw std::runtime_error("Table name is required for OPTIMIZE command.");
1184  }
1185  if (o) {
1186  for (const auto e : *o) {
1187  options_.emplace_back(e);
1188  }
1189  delete o;
1190  }
1191  }
1192 
1193  const std::string getTableName() const { return *(table_.get()); }
1194 
1196  for (const auto& e : options_) {
1197  if (boost::iequals(*(e->get_name()), "VACUUM")) {
1198  return true;
1199  }
1200  }
1201  return false;
1202  }
1203 
1204  void execute(const Catalog_Namespace::SessionInfo& session) override {
1205  // Should pass optimize params to the table optimizer
1206  CHECK(false);
1207  }
1208 
1209  private:
1210  std::unique_ptr<std::string> table_;
1211  std::list<std::unique_ptr<NameValueAssign>> options_;
1212 };
1213 
1214 class ValidateStmt : public DDLStmt {
1215  public:
1216  ValidateStmt(std::string* type, std::list<NameValueAssign*>* with_opts) : type_(type) {
1217  if (!type_) {
1218  throw std::runtime_error("Validation Type is required for VALIDATE command.");
1219  }
1220  std::list<std::unique_ptr<NameValueAssign>> options;
1221  if (with_opts) {
1222  for (const auto e : *with_opts) {
1223  options.emplace_back(e);
1224  }
1225  delete with_opts;
1226 
1227  for (const auto& opt : options) {
1228  if (boost::iequals(*opt->get_name(), "REPAIR_TYPE")) {
1229  const auto repair_type =
1230  static_cast<const StringLiteral*>(opt->get_value())->get_stringval();
1231  CHECK(repair_type);
1232  if (boost::iequals(*repair_type, "REMOVE")) {
1233  isRepairTypeRemove_ = true;
1234  } else {
1235  throw std::runtime_error("REPAIR_TYPE must be REMOVE.");
1236  }
1237  } else {
1238  throw std::runtime_error("The only VALIDATE WITH options is REPAIR_TYPE.");
1239  }
1240  }
1241  }
1242  }
1243 
1244  bool isRepairTypeRemove() const { return isRepairTypeRemove_; }
1245 
1246  const std::string getType() const { return *(type_.get()); }
1247 
1248  void execute(const Catalog_Namespace::SessionInfo& session) override { UNREACHABLE(); }
1249 
1250  private:
1251  std::unique_ptr<std::string> type_;
1252  bool isRepairTypeRemove_ = false;
1253 };
1254 
1255 class RenameDatabaseStmt : public DDLStmt {
1256  public:
1257  RenameDatabaseStmt(std::string* database_name, std::string* new_database_name)
1258  : database_name_(database_name), new_database_name_(new_database_name) {}
1259 
1260  auto const& getPreviousDatabaseName() { return database_name_; }
1261  auto const& getNewDatabaseName() { return new_database_name_; }
1262  void execute(const Catalog_Namespace::SessionInfo& session) override;
1263 
1264  private:
1265  std::unique_ptr<std::string> database_name_;
1266  std::unique_ptr<std::string> new_database_name_;
1267 };
1268 
1269 class RenameUserStmt : public DDLStmt {
1270  public:
1271  RenameUserStmt(std::string* username, std::string* new_username)
1272  : username_(username), new_username_(new_username) {}
1273  auto const& getOldUserName() { return username_; }
1274  auto const& getNewUserName() { return new_username_; }
1275  void execute(const Catalog_Namespace::SessionInfo& session) override;
1276 
1277  private:
1278  std::unique_ptr<std::string> username_;
1279  std::unique_ptr<std::string> new_username_;
1280 };
1281 
1282 class RenameTableStmt : public DDLStmt {
1283  public:
1284  using TableNamePair =
1285  std::pair<std::unique_ptr<std::string>, std::unique_ptr<std::string>>;
1286 
1287  // when created via ddl
1288  RenameTableStmt(const rapidjson::Value& payload);
1289 
1290  // to rename a single table
1291  RenameTableStmt(std::string* tab_name, std::string* new_tab_name);
1292 
1293  // to rename multiple tables
1294  RenameTableStmt(std::list<std::pair<std::string, std::string>> tableNames);
1295 
1296  void execute(const Catalog_Namespace::SessionInfo& session) override;
1297 
1298  private:
1299  std::list<TableNamePair> tablesToRename;
1300 };
1301 
1302 class RenameColumnStmt : public DDLStmt {
1303  public:
1304  RenameColumnStmt(std::string* tab, std::string* col, std::string* new_col_name)
1305  : table(tab), column(col), new_column_name(new_col_name) {}
1306  void execute(const Catalog_Namespace::SessionInfo& session) override;
1307 
1308  private:
1309  std::unique_ptr<std::string> table;
1310  std::unique_ptr<std::string> column;
1311  std::unique_ptr<std::string> new_column_name;
1312 };
1313 
1314 class AddColumnStmt : public DDLStmt {
1315  public:
1316  AddColumnStmt(std::string* tab, ColumnDef* coldef) : table(tab), coldef(coldef) {}
1317  AddColumnStmt(std::string* tab, std::list<ColumnDef*>* coldefs) : table(tab) {
1318  for (const auto coldef : *coldefs) {
1319  this->coldefs.emplace_back(coldef);
1320  }
1321  delete coldefs;
1322  }
1323  void execute(const Catalog_Namespace::SessionInfo& session) override;
1325  const TableDescriptor* td);
1326  const std::string* get_table() const { return table.get(); }
1327 
1328  private:
1329  std::unique_ptr<std::string> table;
1330  std::unique_ptr<ColumnDef> coldef;
1331  std::list<std::unique_ptr<ColumnDef>> coldefs;
1332 };
1333 
1334 class DropColumnStmt : public DDLStmt {
1335  public:
1336  DropColumnStmt(std::string* tab, std::list<std::string*>* cols) : table(tab) {
1337  for (const auto col : *cols) {
1338  this->columns.emplace_back(col);
1339  }
1340  delete cols;
1341  }
1342  void execute(const Catalog_Namespace::SessionInfo& session) override;
1343  const std::string* get_table() const { return table.get(); }
1344 
1345  private:
1346  std::unique_ptr<std::string> table;
1347  std::list<std::unique_ptr<std::string>> columns;
1348 };
1349 
1351  public:
1352  AlterTableParamStmt(std::string* tab, NameValueAssign* p) : table(tab), param(p) {}
1353  void execute(const Catalog_Namespace::SessionInfo& session) override;
1354 
1355  private:
1356  std::unique_ptr<std::string> table;
1357  std::unique_ptr<NameValueAssign> param;
1358 };
1359 
1360 /*
1361  * @type DumpTableStmt
1362  * @brief DUMP TABLE table TO archive_file_path
1363  */
1365  public:
1366  DumpRestoreTableStmtBase(std::string* tab,
1367  std::string* path,
1368  std::list<NameValueAssign*>* options,
1369  const bool is_restore)
1370  : table(tab), path(path) {
1371  auto options_deleter = [](std::list<NameValueAssign*>* options) {
1372  for (auto option : *options) {
1373  delete option;
1374  }
1375  delete options;
1376  };
1377  std::unique_ptr<std::list<NameValueAssign*>, decltype(options_deleter)> options_ptr(
1378  options, options_deleter);
1379  std::vector<std::string> allowed_compression_programs{"lz4", "gzip", "none"};
1380  // specialize decompressor or break on osx bsdtar...
1381  if (options) {
1382  for (const auto option : *options) {
1383  if (boost::iequals(*option->get_name(), "compression")) {
1384  if (const auto str_literal =
1385  dynamic_cast<const StringLiteral*>(option->get_value())) {
1386  compression = *str_literal->get_stringval();
1387  const std::string lowercase_compression =
1388  boost::algorithm::to_lower_copy(compression);
1389  if (allowed_compression_programs.end() ==
1390  std::find(allowed_compression_programs.begin(),
1391  allowed_compression_programs.end(),
1392  lowercase_compression)) {
1393  throw std::runtime_error("Compression program " + compression +
1394  " is not supported.");
1395  }
1396  } else {
1397  throw std::runtime_error("Compression option must be a string.");
1398  }
1399  } else {
1400  throw std::runtime_error("Invalid WITH option: " + *option->get_name());
1401  }
1402  }
1403  }
1404  // default lz4 compression, next gzip, or none.
1405  if (compression.empty()) {
1406  if (boost::process::search_path(compression = "gzip").string().empty()) {
1407  if (boost::process::search_path(compression = "lz4").string().empty()) {
1408  compression = "none";
1409  }
1410  }
1411  }
1412  if (boost::iequals(compression, "none")) {
1413  compression.clear();
1414  } else {
1415  std::map<std::string, std::string> decompression{{"lz4", "unlz4"},
1416  {"gzip", "gunzip"}};
1417  const auto use_program = is_restore ? decompression[compression] : compression;
1418  const auto prog_path = boost::process::search_path(use_program);
1419  if (prog_path.string().empty()) {
1420  throw std::runtime_error("Compression program " + use_program + " is not found.");
1421  }
1422  compression = "--use-compress-program=" + use_program;
1423  }
1424  }
1425  const std::string* getTable() const { return table.get(); }
1426  const std::string* getPath() const { return path.get(); }
1427  const std::string getCompression() const { return compression; }
1428 
1429  protected:
1430  std::unique_ptr<std::string> table;
1431  std::unique_ptr<std::string> path; // dump TO file path
1432  std::string compression;
1433 };
1434 
1436  public:
1437  DumpTableStmt(std::string* tab, std::string* path, std::list<NameValueAssign*>* options)
1438  : DumpRestoreTableStmtBase(tab, path, options, false) {}
1439  void execute(const Catalog_Namespace::SessionInfo& session) override;
1440 };
1441 
1442 /*
1443  * @type RestoreTableStmt
1444  * @brief RESTORE TABLE table FROM archive_file_path
1445  */
1447  public:
1448  RestoreTableStmt(std::string* tab,
1449  std::string* path,
1450  std::list<NameValueAssign*>* options)
1451  : DumpRestoreTableStmtBase(tab, path, options, true) {}
1452  void execute(const Catalog_Namespace::SessionInfo& session) override;
1453 };
1454 
1455 /*
1456  * @type CopyTableStmt
1457  * @brief COPY ... FROM ...
1458  */
1459 class CopyTableStmt : public DDLStmt {
1460  public:
1461  CopyTableStmt(std::string* t, std::string* f, std::list<NameValueAssign*>* o)
1462  : table(t), file_pattern(f), success(true) {
1463  if (o) {
1464  for (const auto e : *o) {
1465  options.emplace_back(e);
1466  }
1467  delete o;
1468  }
1469  }
1470  void execute(const Catalog_Namespace::SessionInfo& session) override;
1471  void execute(const Catalog_Namespace::SessionInfo& session,
1472  const std::function<std::unique_ptr<import_export::Importer>(
1474  const TableDescriptor*,
1475  const std::string&,
1476  const import_export::CopyParams&)>& importer_factory);
1477  std::unique_ptr<std::string> return_message;
1478 
1479  std::string& get_table() const {
1480  CHECK(table);
1481  return *table;
1482  }
1483 
1484  bool get_success() const { return success; }
1485 
1486  bool was_geo_copy_from() const { return _was_geo_copy_from; }
1487 
1488  void get_geo_copy_from_payload(std::string& geo_copy_from_table,
1489  std::string& geo_copy_from_file_name,
1490  import_export::CopyParams& geo_copy_from_copy_params,
1491  std::string& geo_copy_from_partitions) {
1492  geo_copy_from_table = *table;
1493  geo_copy_from_file_name = _geo_copy_from_file_name;
1494  geo_copy_from_copy_params = _geo_copy_from_copy_params;
1495  geo_copy_from_partitions = _geo_copy_from_partitions;
1496  _was_geo_copy_from = false;
1497  }
1498 
1499  private:
1500  std::unique_ptr<std::string> table;
1501  std::unique_ptr<std::string> file_pattern;
1502  bool success;
1503  std::list<std::unique_ptr<NameValueAssign>> options;
1504 
1505  bool _was_geo_copy_from = false;
1509 };
1510 
1511 /*
1512  * @type CreateRoleStmt
1513  * @brief CREATE ROLE statement
1514  */
1515 class CreateRoleStmt : public DDLStmt {
1516  public:
1517  CreateRoleStmt(std::string* r) : role(r) {}
1518  const std::string& get_role() const { return *role; }
1519  void execute(const Catalog_Namespace::SessionInfo& session) override;
1520 
1521  private:
1522  std::unique_ptr<std::string> role;
1523 };
1524 
1525 /*
1526  * @type DropRoleStmt
1527  * @brief DROP ROLE statement
1528  */
1529 class DropRoleStmt : public DDLStmt {
1530  public:
1531  DropRoleStmt(std::string* r) : role(r) {}
1532  const std::string& get_role() const { return *role; }
1533  void execute(const Catalog_Namespace::SessionInfo& session) override;
1534 
1535  private:
1536  std::unique_ptr<std::string> role;
1537 };
1538 
1539 inline void parser_slistval_to_vector(std::list<std::string*>* l,
1540  std::vector<std::string>& v) {
1541  CHECK(l);
1542  for (auto str : *l) {
1543  v.push_back(*str);
1544  delete str;
1545  }
1546  delete l;
1547 }
1548 
1549 /*
1550  * @type GrantPrivilegesStmt
1551  * @brief GRANT PRIVILEGES statement
1552  */
1554  public:
1555  GrantPrivilegesStmt(std::list<std::string*>* p,
1556  std::string* t,
1557  std::string* o,
1558  std::list<std::string*>* g)
1559  : object_type(t), object(o) {
1562  }
1563 
1564  const std::vector<std::string>& get_privs() const { return privs; }
1565  const std::string& get_object_type() const { return *object_type; }
1566  const std::string& get_object() const { return *object; }
1567  const std::vector<std::string>& get_grantees() const { return grantees; }
1568  void execute(const Catalog_Namespace::SessionInfo& session) override;
1569 
1570  private:
1571  std::vector<std::string> privs;
1572  std::unique_ptr<std::string> object_type;
1573  std::unique_ptr<std::string> object;
1574  std::vector<std::string> grantees;
1575 };
1576 
1577 /*
1578  * @type RevokePrivilegesStmt
1579  * @brief REVOKE PRIVILEGES statement
1580  */
1582  public:
1583  RevokePrivilegesStmt(std::list<std::string*>* p,
1584  std::string* t,
1585  std::string* o,
1586  std::list<std::string*>* g)
1587  : object_type(t), object(o) {
1590  }
1591 
1592  const std::vector<std::string>& get_privs() const { return privs; }
1593  const std::string& get_object_type() const { return *object_type; }
1594  const std::string& get_object() const { return *object; }
1595  const std::vector<std::string>& get_grantees() const { return grantees; }
1596  void execute(const Catalog_Namespace::SessionInfo& session) override;
1597 
1598  private:
1599  std::vector<std::string> privs;
1600  std::unique_ptr<std::string> object_type;
1601  std::unique_ptr<std::string> object;
1602  std::vector<std::string> grantees;
1603 };
1604 
1605 /*
1606  * @type ShowPrivilegesStmt
1607  * @brief SHOW PRIVILEGES statement
1608  */
1609 class ShowPrivilegesStmt : public DDLStmt {
1610  public:
1611  ShowPrivilegesStmt(std::string* t, std::string* o, std::string* r)
1612  : object_type(t), object(o), role(r) {}
1613  const std::string& get_object_type() const { return *object_type; }
1614  const std::string& get_object() const { return *object; }
1615  const std::string& get_role() const { return *role; }
1616  void execute(const Catalog_Namespace::SessionInfo& session) override;
1617 
1618  private:
1619  std::unique_ptr<std::string> object_type;
1620  std::unique_ptr<std::string> object;
1621  std::unique_ptr<std::string> role;
1622 };
1623 
1624 /*
1625  * @type GrantRoleStmt
1626  * @brief GRANT ROLE statement
1627  */
1628 class GrantRoleStmt : public DDLStmt {
1629  public:
1630  GrantRoleStmt(std::list<std::string*>* r, std::list<std::string*>* g) {
1633  }
1634  const std::vector<std::string>& get_roles() const { return roles; }
1635  const std::vector<std::string>& get_grantees() const { return grantees; }
1636  void execute(const Catalog_Namespace::SessionInfo& session) override;
1637 
1638  private:
1639  std::vector<std::string> roles;
1640  std::vector<std::string> grantees;
1641 };
1642 
1643 /*
1644  * @type RevokeRoleStmt
1645  * @brief REVOKE ROLE statement
1646  */
1647 class RevokeRoleStmt : public DDLStmt {
1648  public:
1649  RevokeRoleStmt(std::list<std::string*>* r, std::list<std::string*>* g) {
1652  }
1653  const std::vector<std::string>& get_roles() const { return roles; }
1654  const std::vector<std::string>& get_grantees() const { return grantees; }
1655  void execute(const Catalog_Namespace::SessionInfo& session) override;
1656 
1657  private:
1658  std::vector<std::string> roles;
1659  std::vector<std::string> grantees;
1660 };
1661 
1662 /*
1663  * @type QueryExpr
1664  * @brief query expression
1665  */
1666 class QueryExpr : public Node {
1667  public:
1668  virtual void analyze(const Catalog_Namespace::Catalog& catalog,
1669  Analyzer::Query& query) const = 0;
1670 };
1671 
1672 /*
1673  * @type UnionQuery
1674  * @brief UNION or UNION ALL queries
1675  */
1676 class UnionQuery : public QueryExpr {
1677  public:
1678  UnionQuery(bool u, QueryExpr* l, QueryExpr* r) : is_unionall(u), left(l), right(r) {}
1679  bool get_is_unionall() const { return is_unionall; }
1680  const QueryExpr* get_left() const { return left.get(); }
1681  const QueryExpr* get_right() const { return right.get(); }
1682  void analyze(const Catalog_Namespace::Catalog& catalog,
1683  Analyzer::Query& query) const override;
1684 
1685  private:
1687  std::unique_ptr<QueryExpr> left;
1688  std::unique_ptr<QueryExpr> right;
1689 };
1690 
1691 class SelectEntry : public Node {
1692  public:
1693  SelectEntry(Expr* e, std::string* r) : select_expr(e), alias(r) {}
1694  const Expr* get_select_expr() const { return select_expr.get(); }
1695  const std::string* get_alias() const { return alias.get(); }
1696  std::string to_string() const;
1697 
1698  private:
1699  std::unique_ptr<Expr> select_expr;
1700  std::unique_ptr<std::string> alias;
1701 };
1702 
1703 /*
1704  * @type QuerySpec
1705  * @brief a simple query
1706  */
1707 class QuerySpec : public QueryExpr {
1708  public:
1709  QuerySpec(bool d,
1710  std::list<SelectEntry*>* s,
1711  std::list<TableRef*>* f,
1712  Expr* w,
1713  std::list<Expr*>* g,
1714  Expr* h)
1715  : is_distinct(d), where_clause(w), having_clause(h) {
1716  if (s) {
1717  for (const auto e : *s) {
1718  select_clause.emplace_back(e);
1719  }
1720  delete s;
1721  }
1722  CHECK(f);
1723  for (const auto e : *f) {
1724  from_clause.emplace_back(e);
1725  }
1726  delete f;
1727  if (g) {
1728  for (const auto e : *g) {
1729  groupby_clause.emplace_back(e);
1730  }
1731  delete g;
1732  }
1733  }
1734  bool get_is_distinct() const { return is_distinct; }
1735  const std::list<std::unique_ptr<SelectEntry>>& get_select_clause() const {
1736  return select_clause;
1737  }
1738  const std::list<std::unique_ptr<TableRef>>& get_from_clause() const {
1739  return from_clause;
1740  }
1741  const Expr* get_where_clause() const { return where_clause.get(); }
1742  const std::list<std::unique_ptr<Expr>>& get_groupby_clause() const {
1743  return groupby_clause;
1744  }
1745  const Expr* get_having_clause() const { return having_clause.get(); }
1746  void analyze(const Catalog_Namespace::Catalog& catalog,
1747  Analyzer::Query& query) const override;
1748  std::string to_string() const;
1749 
1750  private:
1752  std::list<std::unique_ptr<SelectEntry>> select_clause; /* nullptr means SELECT * */
1753  std::list<std::unique_ptr<TableRef>> from_clause;
1754  std::unique_ptr<Expr> where_clause;
1755  std::list<std::unique_ptr<Expr>> groupby_clause;
1756  std::unique_ptr<Expr> having_clause;
1757  void analyze_from_clause(const Catalog_Namespace::Catalog& catalog,
1758  Analyzer::Query& query) const;
1760  Analyzer::Query& query) const;
1762  Analyzer::Query& query) const;
1763  void analyze_group_by(const Catalog_Namespace::Catalog& catalog,
1764  Analyzer::Query& query) const;
1766  Analyzer::Query& query) const;
1767 };
1768 
1769 /*
1770  * @type OrderSpec
1771  * @brief order spec for a column in ORDER BY clause
1772  */
1773 class OrderSpec : public Node {
1774  public:
1775  OrderSpec(int n, ColumnRef* c, bool d, bool f)
1776  : colno(n), column(c), is_desc(d), nulls_first(f) {}
1777  int get_colno() const { return colno; }
1778  const ColumnRef* get_column() const { return column.get(); }
1779  bool get_is_desc() const { return is_desc; }
1780  bool get_nulls_first() const { return nulls_first; }
1781 
1782  private:
1783  int colno; /* 0 means use column name */
1784  std::unique_ptr<ColumnRef> column;
1785  bool is_desc;
1787 };
1788 
1789 /*
1790  * @type SelectStmt
1791  * @brief SELECT statement
1792  */
1793 class SelectStmt : public DMLStmt {
1794  public:
1795  SelectStmt(QueryExpr* q, std::list<OrderSpec*>* o, int64_t l, int64_t f)
1796  : query_expr(q), limit(l), offset(f) {
1797  if (o) {
1798  for (const auto e : *o) {
1799  orderby_clause.emplace_back(e);
1800  }
1801  delete o;
1802  }
1803  }
1804  const QueryExpr* get_query_expr() const { return query_expr.get(); }
1805  const std::list<std::unique_ptr<OrderSpec>>& get_orderby_clause() const {
1806  return orderby_clause;
1807  }
1808  void analyze(const Catalog_Namespace::Catalog& catalog,
1809  Analyzer::Query& query) const override;
1810 
1811  private:
1812  std::unique_ptr<QueryExpr> query_expr;
1813  std::list<std::unique_ptr<OrderSpec>> orderby_clause;
1814  int64_t limit;
1815  int64_t offset;
1816 };
1817 
1818 /*
1819  * @type ShowCreateTableStmt
1820  * @brief shows create table statement to create table
1821  */
1823  public:
1824  ShowCreateTableStmt(std::string* tab) : table_(tab) {}
1825  std::string getCreateStmt() { return create_stmt_; }
1826  void execute(const Catalog_Namespace::SessionInfo& session) override;
1827 
1828  private:
1829  std::unique_ptr<std::string> table_;
1830  std::string create_stmt_;
1831 };
1832 
1833 /*
1834  * @type ExportQueryStmt
1835  * @brief COPY ( query ) TO file ...
1836  */
1837 class ExportQueryStmt : public DDLStmt {
1838  public:
1839  ExportQueryStmt(std::string* q, std::string* p, std::list<NameValueAssign*>* o)
1840  : select_stmt(q), file_path(p) {
1841  if (o) {
1842  for (const auto e : *o) {
1843  options.emplace_back(e);
1844  }
1845  delete o;
1846  }
1847  }
1848  void execute(const Catalog_Namespace::SessionInfo& session) override;
1849  const std::string get_select_stmt() const { return *select_stmt; }
1850 
1852 
1853  private:
1854  std::unique_ptr<std::string> select_stmt;
1855  std::unique_ptr<std::string> file_path;
1856  std::list<std::unique_ptr<NameValueAssign>> options;
1857 
1858  void parseOptions(import_export::CopyParams& copy_params,
1859  // @TODO(se) move rest to CopyParams when we have a Thrift endpoint
1861  std::string& layer_name,
1864 };
1865 
1866 /*
1867  * @type CreateViewStmt
1868  * @brief CREATE VIEW statement
1869  */
1870 class CreateViewStmt : public DDLStmt {
1871  public:
1872  CreateViewStmt(const std::string& view_name,
1873  const std::string& select_query,
1874  const bool if_not_exists)
1875  : view_name_(view_name)
1876  , select_query_(select_query)
1877  , if_not_exists_(if_not_exists) {}
1878 
1879  CreateViewStmt(const rapidjson::Value& payload);
1880 
1881  const std::string& get_view_name() const { return view_name_; }
1882  const std::string& get_select_query() const { return select_query_; }
1883  void execute(const Catalog_Namespace::SessionInfo& session) override;
1884 
1885  private:
1886  std::string view_name_;
1887  std::string select_query_;
1889 };
1890 
1891 /*
1892  * @type DropViewStmt
1893  * @brief DROP VIEW statement
1894  */
1895 class DropViewStmt : public DDLStmt {
1896  public:
1897  DropViewStmt(std::string* v, bool i) : view_name(v), if_exists(i) {}
1898  DropViewStmt(const rapidjson::Value& payload);
1899 
1900  const std::string* get_view_name() const { return view_name.get(); }
1901  void execute(const Catalog_Namespace::SessionInfo& session) override;
1902 
1903  private:
1904  std::unique_ptr<std::string> view_name;
1906 };
1907 
1908 /*
1909  * @type CreateDBStmt
1910  * @brief CREATE DATABASE statement
1911  */
1912 class CreateDBStmt : public DDLStmt {
1913  public:
1914  CreateDBStmt(std::string* n, std::list<NameValueAssign*>* l, const bool if_not_exists)
1915  : db_name(n), if_not_exists_(if_not_exists) {
1916  if (l) {
1917  for (const auto e : *l) {
1918  name_value_list.emplace_back(e);
1919  }
1920  delete l;
1921  }
1922  }
1923  void execute(const Catalog_Namespace::SessionInfo& session) override;
1924 
1925  private:
1926  std::unique_ptr<std::string> db_name;
1927  std::list<std::unique_ptr<NameValueAssign>> name_value_list;
1929 };
1930 
1931 /*
1932  * @type DropDBStmt
1933  * @brief DROP DATABASE statement
1934  */
1935 class DropDBStmt : public DDLStmt {
1936  public:
1937  explicit DropDBStmt(std::string* n, bool if_exists)
1938  : db_name(n), if_exists_(if_exists) {}
1939  auto const& getDatabaseName() { return db_name; }
1940  void execute(const Catalog_Namespace::SessionInfo& session) override;
1941 
1942  private:
1943  std::unique_ptr<std::string> db_name;
1945 };
1946 
1947 /*
1948  * @type CreateUserStmt
1949  * @brief CREATE USER statement
1950  */
1951 class CreateUserStmt : public DDLStmt {
1952  public:
1953  CreateUserStmt(std::string* n, std::list<NameValueAssign*>* l) : user_name(n) {
1954  if (l) {
1955  for (const auto e : *l) {
1956  name_value_list.emplace_back(e);
1957  }
1958  delete l;
1959  }
1960  }
1961  void execute(const Catalog_Namespace::SessionInfo& session) override;
1962 
1963  private:
1964  std::unique_ptr<std::string> user_name;
1965  std::list<std::unique_ptr<NameValueAssign>> name_value_list;
1966 };
1967 
1968 /*
1969  * @type AlterUserStmt
1970  * @brief ALTER USER statement
1971  */
1972 class AlterUserStmt : public DDLStmt {
1973  public:
1974  AlterUserStmt(std::string* n, std::list<NameValueAssign*>* l) : user_name(n) {
1975  if (l) {
1976  for (const auto e : *l) {
1977  name_value_list.emplace_back(e);
1978  }
1979  delete l;
1980  }
1981  }
1982  void execute(const Catalog_Namespace::SessionInfo& session) override;
1983 
1984  private:
1985  std::unique_ptr<std::string> user_name;
1986  std::list<std::unique_ptr<NameValueAssign>> name_value_list;
1987 };
1988 
1989 /*
1990  * @type DropUserStmt
1991  * @brief DROP USER statement
1992  */
1993 class DropUserStmt : public DDLStmt {
1994  public:
1995  DropUserStmt(std::string* n) : user_name(n) {}
1996  auto const& getUserName() { return user_name; }
1997  void execute(const Catalog_Namespace::SessionInfo& session) override;
1998 
1999  private:
2000  std::unique_ptr<std::string> user_name;
2001 };
2002 
2003 /*
2004  * @type InsertStmt
2005  * @brief super class for INSERT statements
2006  */
2007 class InsertStmt : public DMLStmt {
2008  public:
2009  InsertStmt(std::string* t, std::list<std::string*>* c) : table(t) {
2010  if (c) {
2011  for (const auto e : *c) {
2012  column_list.emplace_back(e);
2013  }
2014  delete c;
2015  }
2016  }
2017  const std::string* get_table() const { return table.get(); }
2018  const std::list<std::unique_ptr<std::string>>& get_column_list() const {
2019  return column_list;
2020  }
2021  void analyze(const Catalog_Namespace::Catalog& catalog,
2022  Analyzer::Query& query) const override = 0;
2023 
2024  protected:
2025  std::unique_ptr<std::string> table;
2026  std::list<std::unique_ptr<std::string>> column_list;
2027 };
2028 
2029 /*
2030  * @type InsertValuesStmt
2031  * @brief INSERT INTO ... VALUES ...
2032  */
2034  public:
2035  InsertValuesStmt(std::string* t, std::list<std::string*>* c, std::list<Expr*>* v)
2036  : InsertStmt(t, c) {
2037  CHECK(v);
2038  for (const auto e : *v) {
2039  value_list.emplace_back(e);
2040  }
2041  delete v;
2042  }
2043  const std::list<std::unique_ptr<Expr>>& get_value_list() const { return value_list; }
2044  void analyze(const Catalog_Namespace::Catalog& catalog,
2045  Analyzer::Query& query) const override;
2046 
2047  size_t determineLeafIndex(const Catalog_Namespace::Catalog& catalog, size_t num_leafs);
2048 
2049  void execute(const Catalog_Namespace::SessionInfo& session);
2050 
2051  private:
2052  std::list<std::unique_ptr<Expr>> value_list;
2053 };
2054 
2055 /*
2056  * @type Assignment
2057  * @brief assignment in UPDATE statement
2058  */
2059 class Assignment : public Node {
2060  public:
2061  Assignment(std::string* c, Expr* a) : column(c), assignment(a) {}
2062  const std::string* get_column() const { return column.get(); }
2063  const Expr* get_assignment() const { return assignment.get(); }
2064 
2065  private:
2066  std::unique_ptr<std::string> column;
2067  std::unique_ptr<Expr> assignment;
2068 };
2069 
2070 /*
2071  * @type UpdateStmt
2072  * @brief UPDATE statement
2073  */
2074 class UpdateStmt : public DMLStmt {
2075  public:
2076  UpdateStmt(std::string* t, std::list<Assignment*>* a, Expr* w)
2077  : table(t), where_clause(w) {
2078  CHECK(a);
2079  for (const auto e : *a) {
2080  assignment_list.emplace_back(e);
2081  }
2082  delete a;
2083  }
2084  const std::string* get_table() const { return table.get(); }
2085  const std::list<std::unique_ptr<Assignment>>& get_assignment_list() const {
2086  return assignment_list;
2087  }
2088  const Expr* get_where_clause() const { return where_clause.get(); }
2089  void analyze(const Catalog_Namespace::Catalog& catalog,
2090  Analyzer::Query& query) const override;
2091 
2092  private:
2093  std::unique_ptr<std::string> table;
2094  std::list<std::unique_ptr<Assignment>> assignment_list;
2095  std::unique_ptr<Expr> where_clause;
2096 };
2097 
2098 /*
2099  * @type DeleteStmt
2100  * @brief DELETE statement
2101  */
2102 class DeleteStmt : public DMLStmt {
2103  public:
2104  DeleteStmt(std::string* t, Expr* w) : table(t), where_clause(w) {}
2105  const std::string* get_table() const { return table.get(); }
2106  const Expr* get_where_clause() const { return where_clause.get(); }
2107  void analyze(const Catalog_Namespace::Catalog& catalog,
2108  Analyzer::Query& query) const override;
2109 
2110  private:
2111  std::unique_ptr<std::string> table;
2112  std::unique_ptr<Expr> where_clause;
2113 };
2114 
2115 template <typename LITERAL_TYPE>
2117 
2118 template <>
2120  template <typename T>
2121  decltype(auto) operator()(T t) {
2122  const std::string property_name(boost::to_upper_copy<std::string>(*t->get_name()));
2123  if (!dynamic_cast<const IntLiteral*>(t->get_value())) {
2124  throw std::runtime_error(property_name + " must be an integer literal.");
2125  }
2126  const auto val = static_cast<const IntLiteral*>(t->get_value())->get_intval();
2127  if (val <= 0) {
2128  throw std::runtime_error(property_name + " must be a positive number.");
2129  }
2130  return val;
2131  }
2132 };
2133 
2135  template <typename T>
2136  decltype(auto) operator()(T t) {
2137  const std::string property_name(boost::to_upper_copy<std::string>(*t->get_name()));
2138  if (!dynamic_cast<const IntLiteral*>(t->get_value())) {
2139  throw std::runtime_error(property_name + " must be an integer literal.");
2140  }
2141  const auto val = static_cast<const IntLiteral*>(t->get_value())->get_intval();
2142  if (val < 0) {
2143  throw std::runtime_error(property_name + " must be greater than or equal to 0.");
2144  }
2145  return val;
2146  }
2147 };
2148 
2149 template <>
2151  template <typename T>
2152  decltype(auto) operator()(T t) {
2153  const auto val = static_cast<const StringLiteral*>(t->get_value())->get_stringval();
2154  CHECK(val);
2155  const auto val_upper = boost::to_upper_copy<std::string>(*val);
2156  return val_upper;
2157  }
2158 };
2159 
2161  template <typename T>
2162  decltype(auto) operator()(T t) {
2163  const auto val = static_cast<const StringLiteral*>(t->get_value())->get_stringval();
2164  CHECK(val);
2165  return *val;
2166  }
2167 };
2168 
2169 template <typename T>
2170 struct ShouldInvalidateSessionsByDB : public std::false_type {};
2171 template <typename T>
2172 struct ShouldInvalidateSessionsByUser : public std::false_type {};
2173 
2174 template <>
2175 struct ShouldInvalidateSessionsByDB<DropDBStmt> : public std::true_type {};
2176 template <>
2177 struct ShouldInvalidateSessionsByUser<DropUserStmt> : public std::true_type {};
2178 template <>
2179 struct ShouldInvalidateSessionsByDB<RenameDatabaseStmt> : public std::true_type {};
2180 template <>
2181 struct ShouldInvalidateSessionsByUser<RenameUserStmt> : public std::true_type {};
2182 
2189 void execute_calcite_ddl(
2190  const std::string& plan_result,
2191  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
2192 
2193 } // namespace Parser
2194 
2195 #endif // PARSERNODE_H_
virtual void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const =0
const ColumnConstraintDef * get_column_constraint() const
Definition: ParserNode.h:800
std::list< std::unique_ptr< ColumnDef > > coldefs
Definition: ParserNode.h:1331
virtual void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const =0
OperExpr(SQLOps t, SQLQualifier q, Expr *l, Expr *r)
Definition: ParserNode.h:300
void execute_calcite_ddl(const std::string &ddl_statement, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
DumpRestoreTableStmtBase(std::string *tab, std::string *path, std::list< NameValueAssign * > *options, const bool is_restore)
Definition: ParserNode.h:1366
ExistsExpr(QuerySpec *q)
Definition: ParserNode.h:584
const std::string foreign_column_
Definition: ParserNode.h:910
std::string & get_table() const
Definition: ParserNode.h:1479
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:103
QuerySpec(bool d, std::list< SelectEntry * > *s, std::list< TableRef * > *f, Expr *w, std::list< Expr * > *g, Expr *h)
Definition: ParserNode.h:1709
import_export::CopyParams _geo_copy_from_copy_params
Definition: ParserNode.h:1507
std::unique_ptr< std::string > table_name
Definition: ParserNode.h:705
void execute(const Catalog_Namespace::SessionInfo &session) override
void execute(const Catalog_Namespace::SessionInfo &session) override
ValidateStmt(std::string *type, std::list< NameValueAssign * > *with_opts)
Definition: ParserNode.h:1216
std::unique_ptr< std::string > username_
Definition: ParserNode.h:1278
std::unique_ptr< std::string > name
Definition: ParserNode.h:938
std::unique_ptr< std::string > view_name
Definition: ParserNode.h:1904
std::string filename(char const *path)
Definition: Logger.cpp:62
const Literal * get_value() const
Definition: ParserNode.h:935
LikelihoodExpr(bool n, Expr *a, float l)
Definition: ParserNode.h:559
std::unique_ptr< std::string > table
Definition: ParserNode.h:1356
std::unique_ptr< std::string > role
Definition: ParserNode.h:1536
const std::string & get_column() const
Definition: ParserNode.h:921
const std::string * get_table() const
Definition: ParserNode.h:2105
const Expr * get_arg() const
Definition: ParserNode.h:561
std::list< std::unique_ptr< ExprPair > > when_then_list
Definition: ParserNode.h:688
std::unique_ptr< std::string > table
Definition: ParserNode.h:2025
IntLiteral(int64_t i)
Definition: ParserNode.h:154
bool get_is_desc() const
Definition: ParserNode.h:1779
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:364
RevokePrivilegesStmt(std::list< std::string * > *p, std::string *t, std::string *o, std::list< std::string * > *g)
Definition: ParserNode.h:1583
void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const override
GrantPrivilegesStmt(std::list< std::string * > *p, std::string *t, std::string *o, std::list< std::string * > *g)
Definition: ParserNode.h:1555
std::unique_ptr< Expr > select_expr
Definition: ParserNode.h:1699
ExportQueryStmt(std::string *q, std::string *p, std::list< NameValueAssign * > *o)
Definition: ParserNode.h:1839
std::unique_ptr< Expr > where_clause
Definition: ParserNode.h:1754
RestoreTableStmt(std::string *tab, std::string *path, std::list< NameValueAssign * > *options)
Definition: ParserNode.h:1448
std::string to_string() const override
std::unique_ptr< Expr > arg
Definition: ParserNode.h:483
SQLType * get_column_type() const
Definition: ParserNode.h:798
std::unique_ptr< std::string > foreign_column
Definition: ParserNode.h:777
float get_likelihood() const
Definition: ParserNode.h:562
std::list< std::unique_ptr< TableRef > > from_clause
Definition: ParserNode.h:1753
const std::string * get_table() const override
Definition: ParserNode.h:980
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1075
void setColumnDescriptor(ColumnDescriptor &cd, const ColumnDef *coldef)
void execute(const Catalog_Namespace::SessionInfo &session) override
const std::string * get_table() const
Definition: ParserNode.h:2017
void execute(const Catalog_Namespace::SessionInfo &session) override
std::unique_ptr< std::string > table
Definition: ParserNode.h:1309
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:101
const std::string getCompression() const
Definition: ParserNode.h:1427
const std::string * get_table() const
Definition: ParserNode.h:604
const std::string * get_column() const
Definition: ParserNode.h:2062
SQLTypes
Definition: sqltypes.h:37
std::unique_ptr< std::string > column
Definition: ParserNode.h:614
void executeDryRun(const Catalog_Namespace::SessionInfo &session, TableDescriptor &td, std::list< ColumnDescriptor > &columns, std::vector< SharedDictionaryDef > &shared_dict_defs)
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1985
std::unique_ptr< SQLType > target_type
Definition: ParserNode.h:654
const Expr * get_arg() const
Definition: ParserNode.h:430
SqlType(SQLTypes type, int param1, int param2, bool is_array, int array_size)
Definition: DdlUtils.cpp:35
std::unique_ptr< std::string > table
Definition: ParserNode.h:1329
std::unique_ptr< std::string > table
Definition: ParserNode.h:2093
void parseOptions(import_export::CopyParams &copy_params, import_export::QueryExporter::FileType &file_type, std::string &layer_name, import_export::QueryExporter::FileCompression &file_compression, import_export::QueryExporter::ArrayNullHandling &array_null_handling)
void execute(const Catalog_Namespace::SessionInfo &session) override
tuple d
Definition: test_fsi.py:9
std::vector< std::string > roles
Definition: ParserNode.h:1639
void execute(const Catalog_Namespace::SessionInfo &session) override
CreateTableStmt(std::string *tab, const std::string *storage, std::list< TableElement * > *table_elems, bool is_temporary, bool if_not_exists, std::list< NameValueAssign * > *s)
Definition: ParserNode.h:958
virtual const std::list< std::unique_ptr< TableElement > > & get_table_element_list() const =0
const std::list< std::unique_ptr< TableElement > > & get_table_element_list() const override
Definition: ParserNode.h:1064
std::unique_ptr< Expr > arg
Definition: ParserNode.h:356
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:994
CastExpr(Expr *a, SQLType *t)
Definition: ParserNode.h:643
float get_floatval() const
Definition: ParserNode.h:197
std::list< std::unique_ptr< NameValueAssign > > options
Definition: ParserNode.h:1503
std::unique_ptr< Expr > lower
Definition: ParserNode.h:442
DropViewStmt(std::string *v, bool i)
Definition: ParserNode.h:1897
FixedPtLiteral(std::string *n)
Definition: ParserNode.h:175
SQLType(SQLTypes t, int p1)
Definition: ParserNode.h:75
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1210
const std::string getType() const
Definition: ParserNode.h:1246
SQLQualifier
Definition: sqldefs.h:69
const std::string & get_role() const
Definition: ParserNode.h:1532
static std::shared_ptr< Analyzer::Expr > analyzeValue(const int64_t intval)
Definition: ParserNode.cpp:132
auto const & getPreviousDatabaseName()
Definition: ParserNode.h:1260
std::unique_ptr< QuerySpec > query
Definition: ParserNode.h:341
const Expr * get_pattern_string() const
Definition: ParserNode.h:531
const std::string column_
Definition: ParserNode.h:908
std::string to_string() const
std::unique_ptr< std::string > alias
Definition: ParserNode.h:1700
std::unique_ptr< std::string > return_message
Definition: ParserNode.h:1477
StringLiteral(std::string *s)
Definition: ParserNode.h:135
const Expr * get_select_expr() const
Definition: ParserNode.h:1694
DoubleLiteral(double d)
Definition: ParserNode.h:216
SQLOps
Definition: sqldefs.h:29
void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const override
const std::string getTableName() const
Definition: ParserNode.h:1193
InsertStmt(std::string *t, std::list< std::string * > *c)
Definition: ParserNode.h:2009
std::string to_string() const override
void populateData(QueryStateProxy, const TableDescriptor *td, bool validate_table, bool for_CTAS=false)
std::string to_string() const override
Definition: ParserNode.h:648
std::string to_string() const override
auto const & getNewDatabaseName()
Definition: ParserNode.h:1261
std::vector< std::string > grantees
Definition: ParserNode.h:1602
InsertValuesStmt(std::string *t, std::list< std::string * > *c, std::list< Expr * > *v)
Definition: ParserNode.h:2035
const Expr * get_check_condition() const
Definition: ParserNode.h:766
UpdateStmt(std::string *t, std::list< Assignment * > *a, Expr *w)
Definition: ParserNode.h:2076
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:213
std::unique_ptr< Expr > arg
Definition: ParserNode.h:463
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:891
std::unique_ptr< std::string > object
Definition: ParserNode.h:1620
std::unique_ptr< Expr > check_condition
Definition: ParserNode.h:775
std::unique_ptr< std::string > table
Definition: ParserNode.h:613
tuple r
Definition: test_fsi.py:16
const std::string * get_table() const
Definition: ParserNode.h:1157
std::string to_string() const override
Definition: ParserNode.h:184
std::list< std::unique_ptr< std::string > > column_list
Definition: ParserNode.h:839
void execute(const Catalog_Namespace::SessionInfo &session) override
bool get_is_not() const
Definition: ParserNode.h:494
std::unique_ptr< std::string > path
Definition: ParserNode.h:1431
#define UNREACHABLE()
Definition: Logger.h:241
const std::list< std::unique_ptr< OrderSpec > > & get_orderby_clause() const
Definition: ParserNode.h:1805
AddColumnStmt(std::string *tab, std::list< ColumnDef * > *coldefs)
Definition: ParserNode.h:1317
std::string to_string() const override=0
const std::list< std::unique_ptr< std::string > > & get_foreign_column_list() const
Definition: ParserNode.h:866
std::unique_ptr< std::string > object
Definition: ParserNode.h:1573
std::unique_ptr< std::string > new_username_
Definition: ParserNode.h:1279
DropColumnStmt(std::string *tab, std::list< std::string * > *cols)
Definition: ParserNode.h:1336
void execute(const Catalog_Namespace::SessionInfo &session) override
DropDBStmt(std::string *n, bool if_exists)
Definition: ParserNode.h:1937
void execute(const Catalog_Namespace::SessionInfo &session) override
const std::string & get_foreign_table() const
Definition: ParserNode.h:903
std::unique_ptr< Expr > where_clause
Definition: ParserNode.h:2112
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:186
DistributedConnector * leafs_connector_
Definition: ParserNode.h:1851
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1964
SQLOps get_optype() const
Definition: ParserNode.h:302
Expr * get_arg() const
Definition: ParserNode.h:628
std::unique_ptr< Expr > assignment
Definition: ParserNode.h:2067
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:199
std::unique_ptr< std::string > table
Definition: ParserNode.h:1500
void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const override=0
std::string to_string() const override
DropRoleStmt(std::string *r)
Definition: ParserNode.h:1531
void parser_slistval_to_vector(std::list< std::string * > *l, std::vector< std::string > &v)
Definition: ParserNode.h:1539
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:177
OptimizeTableStmt(std::string *table, std::list< NameValueAssign * > *o)
Definition: ParserNode.h:1181
const Literal * get_defaultval() const
Definition: ParserNode.h:765
std::string to_string() const
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override=0
const Expr * get_arg() const
Definition: ParserNode.h:530
void execute(const Catalog_Namespace::SessionInfo &session) override
CaseExpr(std::list< ExprPair * > *w, Expr *e)
Definition: ParserNode.h:670
void insertDataToLeaf(const Catalog_Namespace::SessionInfo &session, const size_t leaf_idx, Fragmenter_Namespace::InsertData &insert_data) override
ShardKeyDef(const std::string &column)
Definition: ParserNode.h:919
CreateDBStmt(std::string *n, std::list< NameValueAssign * > *l, const bool if_not_exists)
Definition: ParserNode.h:1914
std::unique_ptr< Literal > defaultval
Definition: ParserNode.h:774
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1072
static void check_pattern_expr(const std::string &pattern_str, char escape_char)
Definition: ParserNode.cpp:604
std::unique_ptr< std::string > table
Definition: ParserNode.h:1161
size_t leafCount() override
Definition: ParserNode.h:1030
const Expr * get_where_clause() const
Definition: ParserNode.h:2088
void execute(const Catalog_Namespace::SessionInfo &session) override
std::unique_ptr< std::string > new_column_name
Definition: ParserNode.h:1311
const std::vector< std::string > & get_roles() const
Definition: ParserNode.h:1634
std::string to_string() const override
bool get_is_unionall() const
Definition: ParserNode.h:1679
std::unique_ptr< ColumnConstraintDef > column_constraint
Definition: ParserNode.h:808
size_t determineLeafIndex(const Catalog_Namespace::Catalog &catalog, size_t num_leafs)
SQLType(SQLTypes t, int p1, int p2, bool a)
Definition: ParserNode.h:76
std::unique_ptr< Expr > arg
Definition: ParserNode.h:545
AlterTableParamStmt(std::string *tab, NameValueAssign *p)
Definition: ParserNode.h:1352
std::unique_ptr< std::string > object_type
Definition: ParserNode.h:1619
const std::string & get_column() const
Definition: ParserNode.h:901
TableRef(std::string *t, std::string *r)
Definition: ParserNode.h:699
AggregatedResult query(QueryStateProxy, std::string &sql_query_string, std::vector< size_t > outer_frag_indices, bool validate_only, bool allow_interrupt)
const std::string * get_table() const
Definition: ParserNode.h:2084
std::unique_ptr< Expr > arg
Definition: ParserNode.h:441
const Expr * get_arg() const
Definition: ParserNode.h:475
std::unique_ptr< std::string > object_type
Definition: ParserNode.h:1600
const Expr * get_arg() const
Definition: ParserNode.h:495
SQLType(SQLTypes t, bool a, int array_size)
Definition: ParserNode.h:79
std::unique_ptr< Expr > arg
Definition: ParserNode.h:376
static bool translate_to_like_pattern(std::string &pattern_str, char escape_char)
Definition: ParserNode.cpp:610
void execute(const Catalog_Namespace::SessionInfo &session) override
const std::list< std::unique_ptr< Expr > > & get_value_list() const
Definition: ParserNode.h:410
ColumnConstraintDef(bool n, bool u, bool p, Literal *d)
Definition: ParserNode.h:752
bool get_is_not() const
Definition: ParserNode.h:366
std::unique_ptr< std::string > file_path
Definition: ParserNode.h:1855
ColumnRef(std::string *n1, std::string *n2)
Definition: ParserNode.h:603
SelectStmt(QueryExpr *q, std::list< OrderSpec * > *o, int64_t l, int64_t f)
Definition: ParserNode.h:1795
void execute(const Catalog_Namespace::SessionInfo &session) override
SQLType(SQLTypes t)
Definition: ParserNode.h:74
std::unique_ptr< std::string > column
Definition: ParserNode.h:2066
void execute(const Catalog_Namespace::SessionInfo &session) override
const std::string & get_object_type() const
Definition: ParserNode.h:1565
const Expr * get_escape_string() const
Definition: ParserNode.h:497
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1926
IsNullExpr(bool n, Expr *a)
Definition: ParserNode.h:346
const std::string & get_object() const
Definition: ParserNode.h:1614
std::vector< std::string > roles
Definition: ParserNode.h:1658
std::list< std::unique_ptr< Expr > > value_list
Definition: ParserNode.h:418
std::vector< std::string > privs
Definition: ParserNode.h:1599
void execute(const Catalog_Namespace::SessionInfo &session) override
static std::shared_ptr< Analyzer::Expr > normalize(const std::list< std::pair< std::shared_ptr< Analyzer::Expr >, std::shared_ptr< Analyzer::Expr >>> &, const std::shared_ptr< Analyzer::Expr >)
Definition: ParserNode.cpp:933
std::list< std::unique_ptr< std::string > > columns
Definition: ParserNode.h:1347
void analyze_having_clause(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const
std::string to_string() const override
const Expr * get_like_string() const
Definition: ParserNode.h:496
const std::string get_select_stmt() const
Definition: ParserNode.h:1849
std::list< TableNamePair > tablesToRename
Definition: ParserNode.h:1299
const std::vector< std::string > & get_grantees() const
Definition: ParserNode.h:1595
void execute(const Catalog_Namespace::SessionInfo &session) override
const Expr * get_arg() const
Definition: ParserNode.h:367
std::string to_string() const override
Definition: ParserNode.h:142
const std::string & get_role() const
Definition: ParserNode.h:1615
bool get_calc_encoded_length() const
Definition: ParserNode.h:455
std::unique_ptr< std::string > table
Definition: ParserNode.h:1430
const SubqueryExpr * get_subquery() const
Definition: ParserNode.h:386
const std::list< std::unique_ptr< SelectEntry > > & get_select_clause() const
Definition: ParserNode.h:1735
const std::string * getPath() const
Definition: ParserNode.h:1426
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:110
std::list< std::unique_ptr< std::string > > foreign_column_list
Definition: ParserNode.h:873
std::string to_string() const override
Definition: ParserNode.h:264
const std::string * getTable() const
Definition: ParserNode.h:1425
bool was_geo_copy_from() const
Definition: ParserNode.h:1486
InSubquery(bool n, Expr *a, SubqueryExpr *q)
Definition: ParserNode.h:385
CreateRoleStmt(std::string *r)
Definition: ParserNode.h:1517
const std::string * get_table_name() const
Definition: ParserNode.h:700
std::unique_ptr< Expr > expr2
Definition: ParserNode.h:665
bool get_success() const
Definition: ParserNode.h:1484
const ColumnRef * get_column() const
Definition: ParserNode.h:1778
std::unique_ptr< Expr > arg
Definition: ParserNode.h:638
const Expr * get_right() const
Definition: ParserNode.h:304
const std::string * get_stringval() const
Definition: ParserNode.h:136
std::list< std::unique_ptr< SelectEntry > > select_clause
Definition: ParserNode.h:1752
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:724
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1927
Definition: ParserNode.h:1691
std::list< std::unique_ptr< Expr > > value_list
Definition: ParserNode.h:289
std::string to_string() const override
Definition: ParserNode.h:242
ExprPair(Expr *e1, Expr *e2)
Definition: ParserNode.h:659
const std::string * get_fixedptval() const
Definition: ParserNode.h:176
const std::list< std::unique_ptr< Expr > > & get_value_list() const
Definition: ParserNode.h:2043
const std::string & get_role() const
Definition: ParserNode.h:1518
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1145
bool get_is_not() const
Definition: ParserNode.h:529
std::unique_ptr< ColumnRef > column
Definition: ParserNode.h:1784
ForeignKeyDef(std::list< std::string * > *cl, std::string *t, std::list< std::string * > *fcl)
Definition: ParserNode.h:848
const std::vector< std::string > & get_grantees() const
Definition: ParserNode.h:1654
std::unique_ptr< Expr > where_clause
Definition: ParserNode.h:2095
std::unique_ptr< std::string > type_
Definition: ParserNode.h:1251
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:125
std::unique_ptr< std::string > foreign_table
Definition: ParserNode.h:872
std::vector< std::string > grantees
Definition: ParserNode.h:1574
std::unique_ptr< SQLType > column_type
Definition: ParserNode.h:806
const std::list< std::unique_ptr< std::string > > & get_column_list() const
Definition: ParserNode.h:2018
std::unique_ptr< Expr > expr1
Definition: ParserNode.h:664
const std::list< std::unique_ptr< Expr > > & get_value_list() const
Definition: ParserNode.h:281
void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const override
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1986
SharedDictionaryDef(const std::string &column, const std::string &foreign_table, const std::string foreign_column)
Definition: ParserNode.h:896
std::unique_ptr< Expr > right
Definition: ParserNode.h:320
const Expr * get_check_condition() const
Definition: ParserNode.h:883
const QueryExpr * get_left() const
Definition: ParserNode.h:1680
virtual const std::string * get_table() const =0
const std::string & get_foreign_column() const
Definition: ParserNode.h:905
void analyze_where_clause(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const
void execute(const Catalog_Namespace::SessionInfo &session) override
const std::string * get_table() const
Definition: ParserNode.h:1172
auto const & getUserName()
Definition: ParserNode.h:1996
int64_t get_intval() const
Definition: ParserNode.h:155
void execute(const Catalog_Namespace::SessionInfo &session) override
const Expr * get_upper() const
Definition: ParserNode.h:432
std::unique_ptr< std::string > role
Definition: ParserNode.h:1522
const std::list< std::unique_ptr< std::string > > & get_column_list() const
Definition: ParserNode.h:833
const Expr * get_where_clause() const
Definition: ParserNode.h:2106
ColumnDef(std::string *c, SQLType *t, CompressDef *cp, ColumnConstraintDef *cc)
Definition: ParserNode.h:795
void execute(const Catalog_Namespace::SessionInfo &session) override
std::string select_query_
Definition: ParserNode.h:1887
virtual size_t getOuterFragmentCount(QueryStateProxy, std::string &sql_query_string)=0
RevokeRoleStmt(std::list< std::string * > *r, std::list< std::string * > *g)
Definition: ParserNode.h:1649
void execute(const Catalog_Namespace::SessionInfo &session) override
std::string _geo_copy_from_partitions
Definition: ParserNode.h:1508
const std::string * get_column_name() const
Definition: ParserNode.h:797
void execute(const Catalog_Namespace::SessionInfo &session) override
const std::string & get_select_query() const
Definition: ParserNode.h:1882
std::unique_ptr< std::string > table
Definition: ParserNode.h:2111
std::list< std::unique_ptr< std::string > > column_list
Definition: ParserNode.h:2026
const Expr * get_having_clause() const
Definition: ParserNode.h:1745
std::string to_string() const override
static std::shared_ptr< Analyzer::Expr > analyzeValue(const std::string &)
Definition: ParserNode.cpp:117
FunctionRef(std::string *n, Expr *a)
Definition: ParserNode.h:624
DropUserStmt(std::string *n)
Definition: ParserNode.h:1995
std::unique_ptr< QueryExpr > right
Definition: ParserNode.h:1688
std::unique_ptr< Expr > escape_string
Definition: ParserNode.h:514
RenameTableStmt(const rapidjson::Value &payload)
CreateTableAsSelectStmt(const std::string *table_name, const std::string *select_query, const bool is_temporary, const bool if_not_exists, std::list< NameValueAssign * > *s)
Definition: ParserNode.h:1124
specifies the content in-memory of a row in the column metadata table
const Expr * get_where_clause() const
Definition: ParserNode.h:1741
const std::string * get_alias() const
Definition: ParserNode.h:1695
void execute(const Catalog_Namespace::SessionInfo &session) override
CheckDef(Expr *c)
Definition: ParserNode.h:882
BetweenExpr(bool n, Expr *a, Expr *l, Expr *u)
Definition: ParserNode.h:427
std::list< std::unique_ptr< NameValueAssign > > options_
Definition: ParserNode.h:1211
std::string to_string() const override
Definition: ParserNode.h:202
const std::vector< std::string > & get_roles() const
Definition: ParserNode.h:1653
const std::string foreign_table_
Definition: ParserNode.h:909
bool g_enable_smem_group_by true
static void erase_cntl_chars(std::string &like_str, char escape_char)
Definition: ParserNode.cpp:527
const std::string * get_name() const
Definition: ParserNode.h:626
std::string to_string() const
AddColumnStmt(std::string *tab, ColumnDef *coldef)
Definition: ParserNode.h:1316
bool get_is_primarykey() const
Definition: ParserNode.h:832
std::unique_ptr< Expr > pattern_string
Definition: ParserNode.h:546
void check_executable(const Catalog_Namespace::SessionInfo &session, const TableDescriptor *td)
virtual void execute(const Catalog_Namespace::SessionInfo &session)=0
void execute(const Catalog_Namespace::SessionInfo &session) override
static std::shared_ptr< Analyzer::Expr > normalize(const SQLOps optype, const SQLQualifier qual, std::shared_ptr< Analyzer::Expr > left_expr, std::shared_ptr< Analyzer::Expr > right_expr)
Definition: ParserNode.cpp:283
int get_colno() const
Definition: ParserNode.h:1777
void execute(const Catalog_Namespace::SessionInfo &session) override
SQLType(SQLTypes t, int p1, int p2, bool a, int array_size)
Definition: ParserNode.h:77
std::string to_string() const override
std::unique_ptr< std::string > database_name_
Definition: ParserNode.h:1265
TruncateTableStmt(std::string *tab)
Definition: ParserNode.h:1171
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:2000
GrantRoleStmt(std::list< std::string * > *r, std::list< std::string * > *g)
Definition: ParserNode.h:1630
const std::list< std::unique_ptr< Expr > > & get_groupby_clause() const
Definition: ParserNode.h:1742
UnionQuery(bool u, QueryExpr *l, QueryExpr *r)
Definition: ParserNode.h:1678
void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const override
const std::string * get_name() const
Definition: ParserNode.h:934
SQLQualifier opqualifier
Definition: ParserNode.h:318
std::list< std::unique_ptr< Expr > > groupby_clause
Definition: ParserNode.h:1755
std::unique_ptr< Expr > left
Definition: ParserNode.h:319
virtual ~Node()
Definition: ParserNode.h:65
void execute(const Catalog_Namespace::SessionInfo &session) override
void checkpoint(const Catalog_Namespace::SessionInfo &session, int tableId) override
void execute(const Catalog_Namespace::SessionInfo &session) override
Definition: ParserNode.h:1248
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:716
std::unique_ptr< Expr > arg
Definition: ParserNode.h:574
const std::string * get_range_var() const
Definition: ParserNode.h:701
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:257
std::unique_ptr< std::string > column_name
Definition: ParserNode.h:805
bool get_distinct() const
Definition: ParserNode.h:627
Definition: sqldefs.h:69
virtual std::vector< AggregatedResult > query(QueryStateProxy, std::string &sql_query_string, std::vector< size_t > outer_frag_indices, bool allow_interrupt)=0
std::pair< std::unique_ptr< std::string >, std::unique_ptr< std::string >> TableNamePair
Definition: ParserNode.h:1285
std::string to_string() const override
const std::vector< std::string > & get_grantees() const
Definition: ParserNode.h:1567
RenameDatabaseStmt(std::string *database_name, std::string *new_database_name)
Definition: ParserNode.h:1257
const CompressDef * get_compression() const
Definition: ParserNode.h:799
virtual void rollback(const Catalog_Namespace::SessionInfo &parent_session_info, int tableId)=0
const std::list< std::unique_ptr< TableElement > > & get_table_element_list() const override
Definition: ParserNode.h:981
CreateUserStmt(std::string *n, std::list< NameValueAssign * > *l)
Definition: ParserNode.h:1953
std::string to_string() const override
Definition: ParserNode.cpp:242
std::unique_ptr< Literal > value
Definition: ParserNode.h:939
std::list< std::unique_ptr< Assignment > > assignment_list
Definition: ParserNode.h:2094
const Expr * get_lower() const
Definition: ParserNode.h:431
std::unique_ptr< QueryExpr > left
Definition: ParserNode.h:1687
std::unique_ptr< std::string > column
Definition: ParserNode.h:1310
void execute(const Catalog_Namespace::SessionInfo &session) override
bool get_is_not() const
Definition: ParserNode.h:429
ArrayLiteral(std::list< Expr * > *v)
Definition: ParserNode.h:274
InExpr(bool n, Expr *a)
Definition: ParserNode.h:365
const std::list< std::unique_ptr< std::string > > & get_column_list() const
Definition: ParserNode.h:862
std::unique_ptr< QueryExpr > query_expr
Definition: ParserNode.h:1812
bool isRepairTypeRemove() const
Definition: ParserNode.h:1244
DropTableStmt(std::string *tab, bool i)
Definition: ParserNode.h:1154
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override=0
std::unique_ptr< Expr > like_string
Definition: ParserNode.h:513
CompressDef(std::string *n, int p)
Definition: ParserNode.h:786
std::list< std::unique_ptr< NameValueAssign > > options
Definition: ParserNode.h:1856
Encoding(std::string *encoding_name, int encoding_param)
Definition: DdlUtils.cpp:199
std::unique_ptr< std::string > table
Definition: ParserNode.h:1346
std::unique_ptr< std::string > range_var
Definition: ParserNode.h:706
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:641
InsertIntoTableAsSelectStmt(const std::string *table_name, const std::string *select_query, std::list< std::string * > *c)
Definition: ParserNode.h:1085
InValues(bool n, Expr *a, std::list< Expr * > *v)
Definition: ParserNode.h:403
const std::string * get_foreign_table() const
Definition: ParserNode.h:865
std::string to_string() const override
Definition: ParserNode.h:161
NameValueAssign(std::string *n, Literal *v)
Definition: ParserNode.h:933
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:798
void rollback(const Catalog_Namespace::SessionInfo &session, int tableId) override
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:997
const std::string column_
Definition: ParserNode.h:924
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:874
virtual void checkpoint(const Catalog_Namespace::SessionInfo &parent_session_info, int tableId)=0
std::unique_ptr< std::string > object
Definition: ParserNode.h:1601
CharLengthExpr(Expr *a, bool e)
Definition: ParserNode.h:453
void execute(const Catalog_Namespace::SessionInfo &session) override
std::string to_string() const override
static std::shared_ptr< Analyzer::Expr > analyzeValue(const int64_t numericval, const int scale, const int precision)
Definition: ParserNode.cpp:157
auto const & getNewUserName()
Definition: ParserNode.h:1274
std::string to_string() const override
void analyze_select_clause(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const
static bool test_is_simple_expr(const std::string &like_str, char escape_char)
Definition: ParserNode.cpp:506
CreateViewStmt(const std::string &view_name, const std::string &select_query, const bool if_not_exists)
Definition: ParserNode.h:1872
const std::string * get_foreign_table() const
Definition: ParserNode.h:767
virtual std::string to_string() const =0
std::vector< std::string > privs
Definition: ParserNode.h:1571
void analyze_from_clause(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const
bool get_nulls_first() const
Definition: ParserNode.h:1780
std::vector< std::unique_ptr< std::string > > column_list_
Definition: ParserNode.h:1113
bool shouldVacuumDeletedRows() const
Definition: ParserNode.h:1195
TableRef(std::string *t)
Definition: ParserNode.h:698
void execute(const Catalog_Namespace::SessionInfo &session) override
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1829
bool get_is_not() const
Definition: ParserNode.h:347
DistributedConnector * leafs_connector_
Definition: ParserNode.h:1110
std::unique_ptr< QuerySpec > query
Definition: ParserNode.h:593
RenameUserStmt(std::string *username, std::string *new_username)
Definition: ParserNode.h:1271
std::string to_string() const override
void get_geo_copy_from_payload(std::string &geo_copy_from_table, std::string &geo_copy_from_file_name, import_export::CopyParams &geo_copy_from_copy_params, std::string &geo_copy_from_partitions)
Definition: ParserNode.h:1488
std::unique_ptr< ColumnDef > coldef
Definition: ParserNode.h:1330
std::unique_ptr< NameValueAssign > param
Definition: ParserNode.h:1357
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:696
std::string to_string() const override
std::unique_ptr< std::string > name
Definition: ParserNode.h:636
std::unique_ptr< std::string > fixedptval
Definition: ParserNode.h:187
bool get_is_primarykey() const
Definition: ParserNode.h:764
virtual std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const =0
std::unique_ptr< std::string > role
Definition: ParserNode.h:1621
std::unique_ptr< std::string > file_pattern
Definition: ParserNode.h:1501
std::unique_ptr< Expr > arg
Definition: ParserNode.h:653
bool g_enable_watchdog false
Definition: Execute.cpp:76
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:384
#define CHECK(condition)
Definition: Logger.h:197
std::list< std::unique_ptr< std::string > > column_list
Definition: ParserNode.h:871
Assignment(std::string *c, Expr *a)
Definition: ParserNode.h:2061
char * t
CreateDataframeStmt(std::string *tab, std::list< TableElement * > *table_elems, std::string *filename, std::list< NameValueAssign * > *s)
Definition: ParserNode.h:1046
const std::vector< std::string > & get_privs() const
Definition: ParserNode.h:1564
CopyTableStmt(std::string *t, std::string *f, std::list< NameValueAssign * > *o)
Definition: ParserNode.h:1461
ShowCreateTableStmt(std::string *tab)
Definition: ParserNode.h:1824
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:168
bool get_is_distinct() const
Definition: ParserNode.h:1734
std::string to_string() const override
Definition: ParserNode.h:222
const std::string & get_object_type() const
Definition: ParserNode.h:1613
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:392
const std::vector< std::string > & get_grantees() const
Definition: ParserNode.h:1635
ColumnConstraintDef(std::string *t, std::string *c)
Definition: ParserNode.h:756
SubqueryExpr(QuerySpec *q)
Definition: ParserNode.h:332
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:472
bool get_is_not() const
Definition: ParserNode.h:560
std::string to_string() const override
Definition: ParserNode.h:126
const std::string * get_foreign_column() const
Definition: ParserNode.h:768
size_t getOuterFragmentCount(QueryStateProxy, std::string &sql_query_string) override
void execute(const Catalog_Namespace::SessionInfo &session) override
std::string to_string() const override
The data to be inserted using the fragment manager.
Definition: Fragmenter.h:59
char * f
const std::string * get_table() const
Definition: ParserNode.h:1343
const Expr * get_left() const
Definition: ParserNode.h:303
std::unique_ptr< std::string > stringval
Definition: ParserNode.h:145
std::unique_ptr< std::string > table
Definition: ParserNode.h:1176
const std::vector< std::string > & get_privs() const
Definition: ParserNode.h:1592
void analyze_group_by(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const
std::list< std::unique_ptr< Expr > > value_list
Definition: ParserNode.h:2052
std::unique_ptr< std::string > object_type
Definition: ParserNode.h:1572
void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const override
const Expr * get_expr2() const
Definition: ParserNode.h:661
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:546
const std::string * get_view_name() const
Definition: ParserNode.h:1900
const QuerySpec * get_query() const
Definition: ParserNode.h:585
const std::string * get_table() const override
Definition: ParserNode.h:1063
auto const & getOldUserName()
Definition: ParserNode.h:1273
const std::string & get_object() const
Definition: ParserNode.h:1594
std::unique_ptr< Expr > having_clause
Definition: ParserNode.h:1756
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1943
void execute(const Catalog_Namespace::SessionInfo &session)
ColumnRef(std::string *n1)
Definition: ParserNode.h:602
std::string to_string() const override
const QuerySpec * get_query() const
Definition: ParserNode.h:333
const std::string & get_view_name() const
Definition: ParserNode.h:1881
LikeExpr(bool n, bool i, Expr *a, Expr *l, Expr *e)
Definition: ParserNode.h:492
std::unique_ptr< SubqueryExpr > subquery
Definition: ParserNode.h:394
std::unique_ptr< Expr > else_expr
Definition: ParserNode.h:689
std::string view_name_
Definition: ParserNode.h:1886
const Expr * get_escape_string() const
Definition: ParserNode.h:532
std::unique_ptr< Expr > upper
Definition: ParserNode.h:443
FunctionRef(std::string *n)
Definition: ParserNode.h:623
std::unique_ptr< CompressDef > compression
Definition: ParserNode.h:807
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:148
std::string _geo_copy_from_file_name
Definition: ParserNode.h:1506
std::unique_ptr< Expr > escape_string
Definition: ParserNode.h:547
OperExpr(SQLOps t, Expr *l, Expr *r)
Definition: ParserNode.h:298
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:1073
std::unique_ptr< std::string > foreign_table
Definition: ParserNode.h:776
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:372
const QueryExpr * get_query_expr() const
Definition: ParserNode.h:1804
RenameColumnStmt(std::string *tab, std::string *col, std::string *new_col_name)
Definition: ParserNode.h:1304
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:434
const std::list< std::unique_ptr< Assignment > > & get_assignment_list() const
Definition: ParserNode.h:2085
std::vector< std::string > grantees
Definition: ParserNode.h:1640
FunctionRef(std::string *n, bool d, Expr *a)
Definition: ParserNode.h:625
AlterUserStmt(std::string *n, std::list< NameValueAssign * > *l)
Definition: ParserNode.h:1974
std::unique_ptr< std::string > select_stmt
Definition: ParserNode.h:1854
std::unique_ptr< std::string > table_
Definition: ParserNode.h:993
void execute(const Catalog_Namespace::SessionInfo &session) override
Definition: ParserNode.h:1204
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1965
std::vector< std::string > grantees
Definition: ParserNode.h:1659
const Expr * get_arg() const
Definition: ParserNode.h:454
OrderSpec(int n, ColumnRef *c, bool d, bool f)
Definition: ParserNode.h:1775
void execute(const Catalog_Namespace::SessionInfo &session) override
double get_doubleval() const
Definition: ParserNode.h:217
RegexpExpr(bool n, Expr *a, Expr *p, Expr *e)
Definition: ParserNode.h:527
const std::string & get_object_type() const
Definition: ParserNode.h:1593
std::unique_ptr< std::string > filename_
Definition: ParserNode.h:1074
ShowPrivilegesStmt(std::string *t, std::string *o, std::string *r)
Definition: ParserNode.h:1611
UniqueDef(bool p, std::list< std::string * > *cl)
Definition: ParserNode.h:825
void execute(const Catalog_Namespace::SessionInfo &session) override
const std::string * get_table() const
Definition: ParserNode.h:1326
SelectEntry(Expr *e, std::string *r)
Definition: ParserNode.h:1693
const QueryExpr * get_right() const
Definition: ParserNode.h:1681
void analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query) const override
std::string to_string() const override
const Expr * get_expr1() const
Definition: ParserNode.h:660
std::shared_ptr< Analyzer::Expr > analyze(const Catalog_Namespace::Catalog &catalog, Analyzer::Query &query, TlistRefType allow_tlist_ref=TLIST_NONE) const override
Definition: ParserNode.cpp:486
const std::string & get_object() const
Definition: ParserNode.h:1566
std::list< ColumnDescriptor > getColumnDescriptors(AggregatedResult &result, bool for_create)
std::unique_ptr< Expr > arg
Definition: ParserNode.h:512
const std::string * get_column() const
Definition: ParserNode.h:605
void execute(const Catalog_Namespace::SessionInfo &session) override
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1813
static void check_like_expr(const std::string &like_str, char escape_char)
Definition: ParserNode.cpp:500
std::unique_ptr< Expr > check_condition
Definition: ParserNode.h:886
DumpTableStmt(std::string *tab, std::string *path, std::list< NameValueAssign * > *options)
Definition: ParserNode.h:1437
const std::list< std::unique_ptr< TableRef > > & get_from_clause() const
Definition: ParserNode.h:1738
auto const & getDatabaseName()
Definition: ParserNode.h:1939
DeleteStmt(std::string *t, Expr *w)
Definition: ParserNode.h:2104
std::unique_ptr< std::string > new_database_name_
Definition: ParserNode.h:1266
const Expr * get_assignment() const
Definition: ParserNode.h:2063