OmniSciDB  0264ff685a
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:
89  enum TlistRefType { TLIST_NONE, TLIST_REF, TLIST_COPY };
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,
336  Analyzer::Query& query,
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(); }
455  bool get_calc_encoded_length() const { return calc_encoded_length; }
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:
474  CardinalityExpr(Expr* a) : arg(a) {}
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,
588  Analyzer::Query& query,
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) {}
755  : notnull(false), unique(false), is_primarykey(false), check_condition(c) {}
756  ColumnConstraintDef(std::string* t, std::string* c)
757  : notnull(false)
758  , unique(false)
759  , is_primarykey(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)
796  : column_name(c), column_type(t), compression(cp), column_constraint(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:
882  CheckDef(Expr* c) : check_condition(c) {}
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) = 0;
1009  virtual void checkpoint(const Catalog_Namespace::SessionInfo& parent_session_info,
1010  int tableId) = 0;
1011  virtual void rollback(const Catalog_Namespace::SessionInfo& parent_session_info,
1012  int tableId) = 0;
1013 };
1014 
1016  virtual ~LocalConnector() {}
1017 
1018  size_t getOuterFragmentCount(QueryStateProxy, std::string& sql_query_string) override;
1019 
1021  std::string& sql_query_string,
1022  std::vector<size_t> outer_frag_indices,
1023  bool validate_only);
1024  std::vector<AggregatedResult> query(QueryStateProxy,
1025  std::string& sql_query_string,
1026  std::vector<size_t> outer_frag_indices) override;
1027  size_t leafCount() override { return 1; };
1028  void insertDataToLeaf(const Catalog_Namespace::SessionInfo& session,
1029  const size_t leaf_idx,
1030  Fragmenter_Namespace::InsertData& insert_data) override;
1031  void checkpoint(const Catalog_Namespace::SessionInfo& session, int tableId) override;
1032  void rollback(const Catalog_Namespace::SessionInfo& session, int tableId) override;
1033  std::list<ColumnDescriptor> getColumnDescriptors(AggregatedResult& result,
1034  bool for_create);
1035 };
1036 
1037 /*
1038  * @type CreateDataframeStmt
1039  * @brief CREATE DATAFRAME statement
1040  */
1042  public:
1043  CreateDataframeStmt(std::string* tab,
1044  std::list<TableElement*>* table_elems,
1045  std::string* filename,
1046  std::list<NameValueAssign*>* s)
1047  : table_(tab), filename_(filename) {
1048  CHECK(table_elems);
1049  for (const auto e : *table_elems) {
1050  table_element_list_.emplace_back(e);
1051  }
1052  delete table_elems;
1053  if (s) {
1054  for (const auto e : *s) {
1055  storage_options_.emplace_back(e);
1056  }
1057  delete s;
1058  }
1059  }
1060  const std::string* get_table() const override { return table_.get(); }
1061  const std::list<std::unique_ptr<TableElement>>& get_table_element_list()
1062  const override {
1063  return table_element_list_;
1064  }
1065 
1066  void execute(const Catalog_Namespace::SessionInfo& session) override;
1067 
1068  private:
1069  std::unique_ptr<std::string> table_;
1070  std::list<std::unique_ptr<TableElement>> table_element_list_;
1071  std::unique_ptr<std::string> filename_;
1072  std::list<std::unique_ptr<NameValueAssign>> storage_options_;
1073 };
1074 
1075 /*
1076  * @type InsertIntoTableAsSelectStmt
1077  * @brief INSERT INTO TABLE SELECT statement
1078  */
1080  public:
1081  // ITAS constructor
1082  InsertIntoTableAsSelectStmt(const std::string* table_name,
1083  const std::string* select_query,
1084  std::list<std::string*>* c)
1085  : table_name_(*table_name), select_query_(*select_query) {
1086  if (c) {
1087  for (auto e : *c) {
1088  column_list_.emplace_back(e);
1089  }
1090  delete c;
1091  }
1092 
1093  delete table_name;
1094  delete select_query;
1095  }
1096 
1097  void populateData(QueryStateProxy, const TableDescriptor* td, bool validate_table);
1098  void execute(const Catalog_Namespace::SessionInfo& session) override;
1099 
1100  std::string& get_table() { return table_name_; }
1101 
1102  std::string& get_select_query() { return select_query_; }
1103 
1104  DistributedConnector* leafs_connector_ = nullptr;
1105 
1106  protected:
1107  std::vector<std::unique_ptr<std::string>> column_list_;
1108  std::string table_name_;
1109  std::string select_query_;
1110 };
1111 
1112 /*
1113  * @type CreateTableAsSelectStmt
1114  * @brief CREATE TABLE AS SELECT statement
1115  */
1117  public:
1118  CreateTableAsSelectStmt(const std::string* table_name,
1119  const std::string* select_query,
1120  const bool is_temporary,
1121  const bool if_not_exists,
1122  std::list<NameValueAssign*>* s)
1123  : InsertIntoTableAsSelectStmt(table_name, select_query, nullptr)
1124  , is_temporary_(is_temporary)
1125  , if_not_exists_(if_not_exists) {
1126  if (s) {
1127  for (const auto& e : *s) {
1128  storage_options_.emplace_back(e);
1129  }
1130  delete s;
1131  }
1132  }
1133 
1134  void execute(const Catalog_Namespace::SessionInfo& session) override;
1135 
1136  private:
1137  const bool is_temporary_;
1138  const bool if_not_exists_;
1139  std::list<std::unique_ptr<NameValueAssign>> storage_options_;
1140 };
1141 
1142 /*
1143  * @type DropTableStmt
1144  * @brief DROP TABLE statement
1145  */
1146 class DropTableStmt : public DDLStmt {
1147  public:
1148  DropTableStmt(std::string* tab, bool i) : table(tab), if_exists(i) {}
1149  DropTableStmt(const rapidjson::Value& payload);
1150 
1151  const std::string* get_table() const { return table.get(); }
1152  void execute(const Catalog_Namespace::SessionInfo& session) override;
1153 
1154  private:
1155  std::unique_ptr<std::string> table;
1157 };
1158 
1159 /*
1160  * @type TruncateTableStmt
1161  * @brief TRUNCATE TABLE statement
1162  */
1163 class TruncateTableStmt : public DDLStmt {
1164  public:
1165  TruncateTableStmt(std::string* tab) : table(tab) {}
1166  const std::string* get_table() const { return table.get(); }
1167  void execute(const Catalog_Namespace::SessionInfo& session) override;
1168 
1169  private:
1170  std::unique_ptr<std::string> table;
1171 };
1172 
1173 class OptimizeTableStmt : public DDLStmt {
1174  public:
1175  OptimizeTableStmt(std::string* table, std::list<NameValueAssign*>* o) : table_(table) {
1176  if (!table_) {
1177  throw std::runtime_error("Table name is required for OPTIMIZE command.");
1178  }
1179  if (o) {
1180  for (const auto e : *o) {
1181  options_.emplace_back(e);
1182  }
1183  delete o;
1184  }
1185  }
1186 
1187  const std::string getTableName() const { return *(table_.get()); }
1188 
1190  for (const auto& e : options_) {
1191  if (boost::iequals(*(e->get_name()), "VACUUM")) {
1192  return true;
1193  }
1194  }
1195  return false;
1196  }
1197 
1198  void execute(const Catalog_Namespace::SessionInfo& session) override {
1199  // Should pass optimize params to the table optimizer
1200  CHECK(false);
1201  }
1202 
1203  private:
1204  std::unique_ptr<std::string> table_;
1205  std::list<std::unique_ptr<NameValueAssign>> options_;
1206 };
1207 
1208 class ValidateStmt : public DDLStmt {
1209  public:
1210  ValidateStmt(std::string* type, std::list<NameValueAssign*>* with_opts) : type_(type) {
1211  if (!type_) {
1212  throw std::runtime_error("Validation Type is required for VALIDATE command.");
1213  }
1214  std::list<std::unique_ptr<NameValueAssign>> options;
1215  if (with_opts) {
1216  for (const auto e : *with_opts) {
1217  options.emplace_back(e);
1218  }
1219  delete with_opts;
1220 
1221  for (const auto& opt : options) {
1222  if (boost::iequals(*opt->get_name(), "REPAIR_TYPE")) {
1223  const auto repair_type =
1224  static_cast<const StringLiteral*>(opt->get_value())->get_stringval();
1225  CHECK(repair_type);
1226  if (boost::iequals(*repair_type, "REMOVE")) {
1227  isRepairTypeRemove_ = true;
1228  } else {
1229  throw std::runtime_error("REPAIR_TYPE must be REMOVE.");
1230  }
1231  } else {
1232  throw std::runtime_error("The only VALIDATE WITH options is REPAIR_TYPE.");
1233  }
1234  }
1235  }
1236  }
1237 
1238  bool isRepairTypeRemove() const { return isRepairTypeRemove_; }
1239 
1240  const std::string getType() const { return *(type_.get()); }
1241 
1242  void execute(const Catalog_Namespace::SessionInfo& session) override { UNREACHABLE(); }
1243 
1244  private:
1245  std::unique_ptr<std::string> type_;
1246  bool isRepairTypeRemove_ = false;
1247 };
1248 
1249 class RenameDatabaseStmt : public DDLStmt {
1250  public:
1251  RenameDatabaseStmt(std::string* database_name, std::string* new_database_name)
1252  : database_name_(database_name), new_database_name_(new_database_name) {}
1253 
1254  auto const& getPreviousDatabaseName() { return database_name_; }
1255  auto const& getNewDatabaseName() { return new_database_name_; }
1256  void execute(const Catalog_Namespace::SessionInfo& session) override;
1257 
1258  private:
1259  std::unique_ptr<std::string> database_name_;
1260  std::unique_ptr<std::string> new_database_name_;
1261 };
1262 
1263 class RenameUserStmt : public DDLStmt {
1264  public:
1265  RenameUserStmt(std::string* username, std::string* new_username)
1266  : username_(username), new_username_(new_username) {}
1267  auto const& getOldUserName() { return username_; }
1268  auto const& getNewUserName() { return new_username_; }
1269  void execute(const Catalog_Namespace::SessionInfo& session) override;
1270 
1271  private:
1272  std::unique_ptr<std::string> username_;
1273  std::unique_ptr<std::string> new_username_;
1274 };
1275 
1276 class RenameTableStmt : public DDLStmt {
1277  public:
1278  RenameTableStmt(std::string* tab, std::string* new_tab_name)
1279  : table(tab), new_table_name(new_tab_name) {}
1280 
1281  const std::string* get_prev_table() const { return table.get(); }
1282  const std::string* get_new_table() const { return new_table_name.get(); }
1283  void execute(const Catalog_Namespace::SessionInfo& session) override;
1284 
1285  private:
1286  std::unique_ptr<std::string> table;
1287  std::unique_ptr<std::string> new_table_name;
1288 };
1289 
1290 class RenameColumnStmt : public DDLStmt {
1291  public:
1292  RenameColumnStmt(std::string* tab, std::string* col, std::string* new_col_name)
1293  : table(tab), column(col), new_column_name(new_col_name) {}
1294  void execute(const Catalog_Namespace::SessionInfo& session) override;
1295 
1296  private:
1297  std::unique_ptr<std::string> table;
1298  std::unique_ptr<std::string> column;
1299  std::unique_ptr<std::string> new_column_name;
1300 };
1301 
1302 class AddColumnStmt : public DDLStmt {
1303  public:
1304  AddColumnStmt(std::string* tab, ColumnDef* coldef) : table(tab), coldef(coldef) {}
1305  AddColumnStmt(std::string* tab, std::list<ColumnDef*>* coldefs) : table(tab) {
1306  for (const auto coldef : *coldefs) {
1307  this->coldefs.emplace_back(coldef);
1308  }
1309  delete coldefs;
1310  }
1311  void execute(const Catalog_Namespace::SessionInfo& session) override;
1312  void check_executable(const Catalog_Namespace::SessionInfo& session,
1313  const TableDescriptor* td);
1314  const std::string* get_table() const { return table.get(); }
1315 
1316  private:
1317  std::unique_ptr<std::string> table;
1318  std::unique_ptr<ColumnDef> coldef;
1319  std::list<std::unique_ptr<ColumnDef>> coldefs;
1320 };
1321 
1322 class DropColumnStmt : public DDLStmt {
1323  public:
1324  DropColumnStmt(std::string* tab, std::list<std::string*>* cols) : table(tab) {
1325  for (const auto col : *cols) {
1326  this->columns.emplace_back(col);
1327  }
1328  delete cols;
1329  }
1330  void execute(const Catalog_Namespace::SessionInfo& session) override;
1331  const std::string* get_table() const { return table.get(); }
1332 
1333  private:
1334  std::unique_ptr<std::string> table;
1335  std::list<std::unique_ptr<std::string>> columns;
1336 };
1337 
1339  public:
1340  AlterTableParamStmt(std::string* tab, NameValueAssign* p) : table(tab), param(p) {}
1341  void execute(const Catalog_Namespace::SessionInfo& session) override;
1342 
1343  private:
1344  std::unique_ptr<std::string> table;
1345  std::unique_ptr<NameValueAssign> param;
1346 };
1347 
1348 /*
1349  * @type DumpTableStmt
1350  * @brief DUMP TABLE table TO archive_file_path
1351  */
1353  public:
1354  DumpRestoreTableStmtBase(std::string* tab,
1355  std::string* path,
1356  std::list<NameValueAssign*>* options,
1357  const bool is_restore)
1358  : table(tab), path(path) {
1359  auto options_deleter = [](std::list<NameValueAssign*>* options) {
1360  for (auto option : *options) {
1361  delete option;
1362  }
1363  delete options;
1364  };
1365  std::unique_ptr<std::list<NameValueAssign*>, decltype(options_deleter)> options_ptr(
1366  options, options_deleter);
1367  std::vector<std::string> allowed_compression_programs{"lz4", "gzip", "none"};
1368  // specialize decompressor or break on osx bsdtar...
1369  if (options) {
1370  for (const auto option : *options) {
1371  if (boost::iequals(*option->get_name(), "compression")) {
1372  if (const auto str_literal =
1373  dynamic_cast<const StringLiteral*>(option->get_value())) {
1374  compression = *str_literal->get_stringval();
1375  const std::string lowercase_compression =
1376  boost::algorithm::to_lower_copy(compression);
1377  if (allowed_compression_programs.end() ==
1378  std::find(allowed_compression_programs.begin(),
1379  allowed_compression_programs.end(),
1380  lowercase_compression)) {
1381  throw std::runtime_error("Compression program " + compression +
1382  " is not supported.");
1383  }
1384  } else {
1385  throw std::runtime_error("Compression option must be a string.");
1386  }
1387  } else {
1388  throw std::runtime_error("Invalid WITH option: " + *option->get_name());
1389  }
1390  }
1391  }
1392  // default lz4 compression, next gzip, or none.
1393  if (compression.empty()) {
1394  if (boost::process::search_path(compression = "gzip").string().empty()) {
1395  if (boost::process::search_path(compression = "lz4").string().empty()) {
1396  compression = "none";
1397  }
1398  }
1399  }
1400  if (boost::iequals(compression, "none")) {
1401  compression.clear();
1402  } else {
1403  std::map<std::string, std::string> decompression{{"lz4", "unlz4"},
1404  {"gzip", "gunzip"}};
1405  const auto use_program = is_restore ? decompression[compression] : compression;
1406  const auto prog_path = boost::process::search_path(use_program);
1407  if (prog_path.string().empty()) {
1408  throw std::runtime_error("Compression program " + use_program + " is not found.");
1409  }
1410  compression = "--use-compress-program=" + use_program;
1411  }
1412  }
1413  const std::string* getTable() const { return table.get(); }
1414  const std::string* getPath() const { return path.get(); }
1415  const std::string getCompression() const { return compression; }
1416 
1417  protected:
1418  std::unique_ptr<std::string> table;
1419  std::unique_ptr<std::string> path; // dump TO file path
1420  std::string compression;
1421 };
1422 
1424  public:
1425  DumpTableStmt(std::string* tab, std::string* path, std::list<NameValueAssign*>* options)
1426  : DumpRestoreTableStmtBase(tab, path, options, false) {}
1427  void execute(const Catalog_Namespace::SessionInfo& session) override;
1428 };
1429 
1430 /*
1431  * @type RestoreTableStmt
1432  * @brief RESTORE TABLE table FROM archive_file_path
1433  */
1435  public:
1436  RestoreTableStmt(std::string* tab,
1437  std::string* path,
1438  std::list<NameValueAssign*>* options)
1439  : DumpRestoreTableStmtBase(tab, path, options, true) {}
1440  void execute(const Catalog_Namespace::SessionInfo& session) override;
1441 };
1442 
1443 /*
1444  * @type CopyTableStmt
1445  * @brief COPY ... FROM ...
1446  */
1447 class CopyTableStmt : public DDLStmt {
1448  public:
1449  CopyTableStmt(std::string* t, std::string* f, std::list<NameValueAssign*>* o)
1450  : table(t), file_pattern(f), success(true) {
1451  if (o) {
1452  for (const auto e : *o) {
1453  options.emplace_back(e);
1454  }
1455  delete o;
1456  }
1457  }
1458  void execute(const Catalog_Namespace::SessionInfo& session) override;
1459  void execute(const Catalog_Namespace::SessionInfo& session,
1460  const std::function<std::unique_ptr<import_export::Importer>(
1462  const TableDescriptor*,
1463  const std::string&,
1464  const import_export::CopyParams&)>& importer_factory);
1465  std::unique_ptr<std::string> return_message;
1466 
1467  std::string& get_table() const {
1468  CHECK(table);
1469  return *table;
1470  }
1471 
1472  bool get_success() const { return success; }
1473 
1474  bool was_geo_copy_from() const { return _was_geo_copy_from; }
1475 
1476  void get_geo_copy_from_payload(std::string& geo_copy_from_table,
1477  std::string& geo_copy_from_file_name,
1478  import_export::CopyParams& geo_copy_from_copy_params,
1479  std::string& geo_copy_from_partitions) {
1480  geo_copy_from_table = *table;
1481  geo_copy_from_file_name = _geo_copy_from_file_name;
1482  geo_copy_from_copy_params = _geo_copy_from_copy_params;
1483  geo_copy_from_partitions = _geo_copy_from_partitions;
1484  _was_geo_copy_from = false;
1485  }
1486 
1487  private:
1488  std::unique_ptr<std::string> table;
1489  std::unique_ptr<std::string> file_pattern;
1490  bool success;
1491  std::list<std::unique_ptr<NameValueAssign>> options;
1492 
1493  bool _was_geo_copy_from = false;
1497 };
1498 
1499 /*
1500  * @type CreateRoleStmt
1501  * @brief CREATE ROLE statement
1502  */
1503 class CreateRoleStmt : public DDLStmt {
1504  public:
1505  CreateRoleStmt(std::string* r) : role(r) {}
1506  const std::string& get_role() const { return *role; }
1507  void execute(const Catalog_Namespace::SessionInfo& session) override;
1508 
1509  private:
1510  std::unique_ptr<std::string> role;
1511 };
1512 
1513 /*
1514  * @type DropRoleStmt
1515  * @brief DROP ROLE statement
1516  */
1517 class DropRoleStmt : public DDLStmt {
1518  public:
1519  DropRoleStmt(std::string* r) : role(r) {}
1520  const std::string& get_role() const { return *role; }
1521  void execute(const Catalog_Namespace::SessionInfo& session) override;
1522 
1523  private:
1524  std::unique_ptr<std::string> role;
1525 };
1526 
1527 inline void parser_slistval_to_vector(std::list<std::string*>* l,
1528  std::vector<std::string>& v) {
1529  CHECK(l);
1530  for (auto str : *l) {
1531  v.push_back(*str);
1532  delete str;
1533  }
1534  delete l;
1535 }
1536 
1537 /*
1538  * @type GrantPrivilegesStmt
1539  * @brief GRANT PRIVILEGES statement
1540  */
1542  public:
1543  GrantPrivilegesStmt(std::list<std::string*>* p,
1544  std::string* t,
1545  std::string* o,
1546  std::list<std::string*>* g)
1547  : object_type(t), object(o) {
1548  parser_slistval_to_vector(p, privs);
1549  parser_slistval_to_vector(g, grantees);
1550  }
1551 
1552  const std::vector<std::string>& get_privs() const { return privs; }
1553  const std::string& get_object_type() const { return *object_type; }
1554  const std::string& get_object() const { return *object; }
1555  const std::vector<std::string>& get_grantees() const { return grantees; }
1556  void execute(const Catalog_Namespace::SessionInfo& session) override;
1557 
1558  private:
1559  std::vector<std::string> privs;
1560  std::unique_ptr<std::string> object_type;
1561  std::unique_ptr<std::string> object;
1562  std::vector<std::string> grantees;
1563 };
1564 
1565 /*
1566  * @type RevokePrivilegesStmt
1567  * @brief REVOKE PRIVILEGES statement
1568  */
1570  public:
1571  RevokePrivilegesStmt(std::list<std::string*>* p,
1572  std::string* t,
1573  std::string* o,
1574  std::list<std::string*>* g)
1575  : object_type(t), object(o) {
1576  parser_slistval_to_vector(p, privs);
1577  parser_slistval_to_vector(g, grantees);
1578  }
1579 
1580  const std::vector<std::string>& get_privs() const { return privs; }
1581  const std::string& get_object_type() const { return *object_type; }
1582  const std::string& get_object() const { return *object; }
1583  const std::vector<std::string>& get_grantees() const { return grantees; }
1584  void execute(const Catalog_Namespace::SessionInfo& session) override;
1585 
1586  private:
1587  std::vector<std::string> privs;
1588  std::unique_ptr<std::string> object_type;
1589  std::unique_ptr<std::string> object;
1590  std::vector<std::string> grantees;
1591 };
1592 
1593 /*
1594  * @type ShowPrivilegesStmt
1595  * @brief SHOW PRIVILEGES statement
1596  */
1597 class ShowPrivilegesStmt : public DDLStmt {
1598  public:
1599  ShowPrivilegesStmt(std::string* t, std::string* o, std::string* r)
1600  : object_type(t), object(o), role(r) {}
1601  const std::string& get_object_type() const { return *object_type; }
1602  const std::string& get_object() const { return *object; }
1603  const std::string& get_role() const { return *role; }
1604  void execute(const Catalog_Namespace::SessionInfo& session) override;
1605 
1606  private:
1607  std::unique_ptr<std::string> object_type;
1608  std::unique_ptr<std::string> object;
1609  std::unique_ptr<std::string> role;
1610 };
1611 
1612 /*
1613  * @type GrantRoleStmt
1614  * @brief GRANT ROLE statement
1615  */
1616 class GrantRoleStmt : public DDLStmt {
1617  public:
1618  GrantRoleStmt(std::list<std::string*>* r, std::list<std::string*>* g) {
1619  parser_slistval_to_vector(r, roles);
1620  parser_slistval_to_vector(g, grantees);
1621  }
1622  const std::vector<std::string>& get_roles() const { return roles; }
1623  const std::vector<std::string>& get_grantees() const { return grantees; }
1624  void execute(const Catalog_Namespace::SessionInfo& session) override;
1625 
1626  private:
1627  std::vector<std::string> roles;
1628  std::vector<std::string> grantees;
1629 };
1630 
1631 /*
1632  * @type RevokeRoleStmt
1633  * @brief REVOKE ROLE statement
1634  */
1635 class RevokeRoleStmt : public DDLStmt {
1636  public:
1637  RevokeRoleStmt(std::list<std::string*>* r, std::list<std::string*>* g) {
1638  parser_slistval_to_vector(r, roles);
1639  parser_slistval_to_vector(g, grantees);
1640  }
1641  const std::vector<std::string>& get_roles() const { return roles; }
1642  const std::vector<std::string>& get_grantees() const { return grantees; }
1643  void execute(const Catalog_Namespace::SessionInfo& session) override;
1644 
1645  private:
1646  std::vector<std::string> roles;
1647  std::vector<std::string> grantees;
1648 };
1649 
1650 /*
1651  * @type QueryExpr
1652  * @brief query expression
1653  */
1654 class QueryExpr : public Node {
1655  public:
1656  virtual void analyze(const Catalog_Namespace::Catalog& catalog,
1657  Analyzer::Query& query) const = 0;
1658 };
1659 
1660 /*
1661  * @type UnionQuery
1662  * @brief UNION or UNION ALL queries
1663  */
1664 class UnionQuery : public QueryExpr {
1665  public:
1666  UnionQuery(bool u, QueryExpr* l, QueryExpr* r) : is_unionall(u), left(l), right(r) {}
1667  bool get_is_unionall() const { return is_unionall; }
1668  const QueryExpr* get_left() const { return left.get(); }
1669  const QueryExpr* get_right() const { return right.get(); }
1670  void analyze(const Catalog_Namespace::Catalog& catalog,
1671  Analyzer::Query& query) const override;
1672 
1673  private:
1675  std::unique_ptr<QueryExpr> left;
1676  std::unique_ptr<QueryExpr> right;
1677 };
1678 
1679 class SelectEntry : public Node {
1680  public:
1681  SelectEntry(Expr* e, std::string* r) : select_expr(e), alias(r) {}
1682  const Expr* get_select_expr() const { return select_expr.get(); }
1683  const std::string* get_alias() const { return alias.get(); }
1684  std::string to_string() const;
1685 
1686  private:
1687  std::unique_ptr<Expr> select_expr;
1688  std::unique_ptr<std::string> alias;
1689 };
1690 
1691 /*
1692  * @type QuerySpec
1693  * @brief a simple query
1694  */
1695 class QuerySpec : public QueryExpr {
1696  public:
1697  QuerySpec(bool d,
1698  std::list<SelectEntry*>* s,
1699  std::list<TableRef*>* f,
1700  Expr* w,
1701  std::list<Expr*>* g,
1702  Expr* h)
1703  : is_distinct(d), where_clause(w), having_clause(h) {
1704  if (s) {
1705  for (const auto e : *s) {
1706  select_clause.emplace_back(e);
1707  }
1708  delete s;
1709  }
1710  CHECK(f);
1711  for (const auto e : *f) {
1712  from_clause.emplace_back(e);
1713  }
1714  delete f;
1715  if (g) {
1716  for (const auto e : *g) {
1717  groupby_clause.emplace_back(e);
1718  }
1719  delete g;
1720  }
1721  }
1722  bool get_is_distinct() const { return is_distinct; }
1723  const std::list<std::unique_ptr<SelectEntry>>& get_select_clause() const {
1724  return select_clause;
1725  }
1726  const std::list<std::unique_ptr<TableRef>>& get_from_clause() const {
1727  return from_clause;
1728  }
1729  const Expr* get_where_clause() const { return where_clause.get(); }
1730  const std::list<std::unique_ptr<Expr>>& get_groupby_clause() const {
1731  return groupby_clause;
1732  }
1733  const Expr* get_having_clause() const { return having_clause.get(); }
1734  void analyze(const Catalog_Namespace::Catalog& catalog,
1735  Analyzer::Query& query) const override;
1736  std::string to_string() const;
1737 
1738  private:
1740  std::list<std::unique_ptr<SelectEntry>> select_clause; /* nullptr means SELECT * */
1741  std::list<std::unique_ptr<TableRef>> from_clause;
1742  std::unique_ptr<Expr> where_clause;
1743  std::list<std::unique_ptr<Expr>> groupby_clause;
1744  std::unique_ptr<Expr> having_clause;
1745  void analyze_from_clause(const Catalog_Namespace::Catalog& catalog,
1746  Analyzer::Query& query) const;
1747  void analyze_select_clause(const Catalog_Namespace::Catalog& catalog,
1748  Analyzer::Query& query) const;
1749  void analyze_where_clause(const Catalog_Namespace::Catalog& catalog,
1750  Analyzer::Query& query) const;
1751  void analyze_group_by(const Catalog_Namespace::Catalog& catalog,
1752  Analyzer::Query& query) const;
1753  void analyze_having_clause(const Catalog_Namespace::Catalog& catalog,
1754  Analyzer::Query& query) const;
1755 };
1756 
1757 /*
1758  * @type OrderSpec
1759  * @brief order spec for a column in ORDER BY clause
1760  */
1761 class OrderSpec : public Node {
1762  public:
1763  OrderSpec(int n, ColumnRef* c, bool d, bool f)
1764  : colno(n), column(c), is_desc(d), nulls_first(f) {}
1765  int get_colno() const { return colno; }
1766  const ColumnRef* get_column() const { return column.get(); }
1767  bool get_is_desc() const { return is_desc; }
1768  bool get_nulls_first() const { return nulls_first; }
1769 
1770  private:
1771  int colno; /* 0 means use column name */
1772  std::unique_ptr<ColumnRef> column;
1773  bool is_desc;
1775 };
1776 
1777 /*
1778  * @type SelectStmt
1779  * @brief SELECT statement
1780  */
1781 class SelectStmt : public DMLStmt {
1782  public:
1783  SelectStmt(QueryExpr* q, std::list<OrderSpec*>* o, int64_t l, int64_t f)
1784  : query_expr(q), limit(l), offset(f) {
1785  if (o) {
1786  for (const auto e : *o) {
1787  orderby_clause.emplace_back(e);
1788  }
1789  delete o;
1790  }
1791  }
1792  const QueryExpr* get_query_expr() const { return query_expr.get(); }
1793  const std::list<std::unique_ptr<OrderSpec>>& get_orderby_clause() const {
1794  return orderby_clause;
1795  }
1796  void analyze(const Catalog_Namespace::Catalog& catalog,
1797  Analyzer::Query& query) const override;
1798 
1799  private:
1800  std::unique_ptr<QueryExpr> query_expr;
1801  std::list<std::unique_ptr<OrderSpec>> orderby_clause;
1802  int64_t limit;
1803  int64_t offset;
1804 };
1805 
1806 /*
1807  * @type ShowCreateTableStmt
1808  * @brief shows create table statement to create table
1809  */
1811  public:
1812  ShowCreateTableStmt(std::string* tab) : table_(tab) {}
1813  std::string getCreateStmt() { return create_stmt_; }
1814  void execute(const Catalog_Namespace::SessionInfo& session) override;
1815 
1816  private:
1817  std::unique_ptr<std::string> table_;
1818  std::string create_stmt_;
1819 };
1820 
1821 /*
1822  * @type ExportQueryStmt
1823  * @brief COPY ( query ) TO file ...
1824  */
1825 class ExportQueryStmt : public DDLStmt {
1826  public:
1827  ExportQueryStmt(std::string* q, std::string* p, std::list<NameValueAssign*>* o)
1828  : select_stmt(q), file_path(p) {
1829  if (o) {
1830  for (const auto e : *o) {
1831  options.emplace_back(e);
1832  }
1833  delete o;
1834  }
1835  }
1836  void execute(const Catalog_Namespace::SessionInfo& session) override;
1837  const std::string get_select_stmt() const { return *select_stmt; }
1838 
1839  DistributedConnector* leafs_connector_ = nullptr;
1840 
1841  private:
1842  std::unique_ptr<std::string> select_stmt;
1843  std::unique_ptr<std::string> file_path;
1844  std::list<std::unique_ptr<NameValueAssign>> options;
1845 
1846  void parseOptions(import_export::CopyParams& copy_params,
1847  // @TODO(se) move rest to CopyParams when we have a Thrift endpoint
1849  std::string& layer_name,
1852 };
1853 
1854 /*
1855  * @type CreateViewStmt
1856  * @brief CREATE VIEW statement
1857  */
1858 class CreateViewStmt : public DDLStmt {
1859  public:
1860  CreateViewStmt(const std::string& view_name,
1861  const std::string& select_query,
1862  const bool if_not_exists)
1863  : view_name_(view_name)
1864  , select_query_(select_query)
1865  , if_not_exists_(if_not_exists) {}
1866 
1867  CreateViewStmt(const rapidjson::Value& payload);
1868 
1869  const std::string& get_view_name() const { return view_name_; }
1870  const std::string& get_select_query() const { return select_query_; }
1871  void execute(const Catalog_Namespace::SessionInfo& session) override;
1872 
1873  private:
1874  std::string view_name_;
1875  std::string select_query_;
1877 };
1878 
1879 /*
1880  * @type DropViewStmt
1881  * @brief DROP VIEW statement
1882  */
1883 class DropViewStmt : public DDLStmt {
1884  public:
1885  DropViewStmt(std::string* v, bool i) : view_name(v), if_exists(i) {}
1886  DropViewStmt(const rapidjson::Value& payload);
1887 
1888  const std::string* get_view_name() const { return view_name.get(); }
1889  void execute(const Catalog_Namespace::SessionInfo& session) override;
1890 
1891  private:
1892  std::unique_ptr<std::string> view_name;
1894 };
1895 
1896 /*
1897  * @type CreateDBStmt
1898  * @brief CREATE DATABASE statement
1899  */
1900 class CreateDBStmt : public DDLStmt {
1901  public:
1902  CreateDBStmt(std::string* n, std::list<NameValueAssign*>* l, const bool if_not_exists)
1903  : db_name(n), if_not_exists_(if_not_exists) {
1904  if (l) {
1905  for (const auto e : *l) {
1906  name_value_list.emplace_back(e);
1907  }
1908  delete l;
1909  }
1910  }
1911  void execute(const Catalog_Namespace::SessionInfo& session) override;
1912 
1913  private:
1914  std::unique_ptr<std::string> db_name;
1915  std::list<std::unique_ptr<NameValueAssign>> name_value_list;
1917 };
1918 
1919 /*
1920  * @type DropDBStmt
1921  * @brief DROP DATABASE statement
1922  */
1923 class DropDBStmt : public DDLStmt {
1924  public:
1925  explicit DropDBStmt(std::string* n, bool if_exists)
1926  : db_name(n), if_exists_(if_exists) {}
1927  auto const& getDatabaseName() { return db_name; }
1928  void execute(const Catalog_Namespace::SessionInfo& session) override;
1929 
1930  private:
1931  std::unique_ptr<std::string> db_name;
1933 };
1934 
1935 /*
1936  * @type CreateUserStmt
1937  * @brief CREATE USER statement
1938  */
1939 class CreateUserStmt : public DDLStmt {
1940  public:
1941  CreateUserStmt(std::string* n, std::list<NameValueAssign*>* l) : user_name(n) {
1942  if (l) {
1943  for (const auto e : *l) {
1944  name_value_list.emplace_back(e);
1945  }
1946  delete l;
1947  }
1948  }
1949  void execute(const Catalog_Namespace::SessionInfo& session) override;
1950 
1951  private:
1952  std::unique_ptr<std::string> user_name;
1953  std::list<std::unique_ptr<NameValueAssign>> name_value_list;
1954 };
1955 
1956 /*
1957  * @type AlterUserStmt
1958  * @brief ALTER USER statement
1959  */
1960 class AlterUserStmt : public DDLStmt {
1961  public:
1962  AlterUserStmt(std::string* n, std::list<NameValueAssign*>* l) : user_name(n) {
1963  if (l) {
1964  for (const auto e : *l) {
1965  name_value_list.emplace_back(e);
1966  }
1967  delete l;
1968  }
1969  }
1970  void execute(const Catalog_Namespace::SessionInfo& session) override;
1971 
1972  private:
1973  std::unique_ptr<std::string> user_name;
1974  std::list<std::unique_ptr<NameValueAssign>> name_value_list;
1975 };
1976 
1977 /*
1978  * @type DropUserStmt
1979  * @brief DROP USER statement
1980  */
1981 class DropUserStmt : public DDLStmt {
1982  public:
1983  DropUserStmt(std::string* n) : user_name(n) {}
1984  auto const& getUserName() { return user_name; }
1985  void execute(const Catalog_Namespace::SessionInfo& session) override;
1986 
1987  private:
1988  std::unique_ptr<std::string> user_name;
1989 };
1990 
1991 /*
1992  * @type InsertStmt
1993  * @brief super class for INSERT statements
1994  */
1995 class InsertStmt : public DMLStmt {
1996  public:
1997  InsertStmt(std::string* t, std::list<std::string*>* c) : table(t) {
1998  if (c) {
1999  for (const auto e : *c) {
2000  column_list.emplace_back(e);
2001  }
2002  delete c;
2003  }
2004  }
2005  const std::string* get_table() const { return table.get(); }
2006  const std::list<std::unique_ptr<std::string>>& get_column_list() const {
2007  return column_list;
2008  }
2009  void analyze(const Catalog_Namespace::Catalog& catalog,
2010  Analyzer::Query& query) const override = 0;
2011 
2012  protected:
2013  std::unique_ptr<std::string> table;
2014  std::list<std::unique_ptr<std::string>> column_list;
2015 };
2016 
2017 /*
2018  * @type InsertValuesStmt
2019  * @brief INSERT INTO ... VALUES ...
2020  */
2022  public:
2023  InsertValuesStmt(std::string* t, std::list<std::string*>* c, std::list<Expr*>* v)
2024  : InsertStmt(t, c) {
2025  CHECK(v);
2026  for (const auto e : *v) {
2027  value_list.emplace_back(e);
2028  }
2029  delete v;
2030  }
2031  const std::list<std::unique_ptr<Expr>>& get_value_list() const { return value_list; }
2032  void analyze(const Catalog_Namespace::Catalog& catalog,
2033  Analyzer::Query& query) const override;
2034 
2035  size_t determineLeafIndex(const Catalog_Namespace::Catalog& catalog, size_t num_leafs);
2036 
2037  void execute(const Catalog_Namespace::SessionInfo& session);
2038 
2039  private:
2040  std::list<std::unique_ptr<Expr>> value_list;
2041 };
2042 
2043 /*
2044  * @type Assignment
2045  * @brief assignment in UPDATE statement
2046  */
2047 class Assignment : public Node {
2048  public:
2049  Assignment(std::string* c, Expr* a) : column(c), assignment(a) {}
2050  const std::string* get_column() const { return column.get(); }
2051  const Expr* get_assignment() const { return assignment.get(); }
2052 
2053  private:
2054  std::unique_ptr<std::string> column;
2055  std::unique_ptr<Expr> assignment;
2056 };
2057 
2058 /*
2059  * @type UpdateStmt
2060  * @brief UPDATE statement
2061  */
2062 class UpdateStmt : public DMLStmt {
2063  public:
2064  UpdateStmt(std::string* t, std::list<Assignment*>* a, Expr* w)
2065  : table(t), where_clause(w) {
2066  CHECK(a);
2067  for (const auto e : *a) {
2068  assignment_list.emplace_back(e);
2069  }
2070  delete a;
2071  }
2072  const std::string* get_table() const { return table.get(); }
2073  const std::list<std::unique_ptr<Assignment>>& get_assignment_list() const {
2074  return assignment_list;
2075  }
2076  const Expr* get_where_clause() const { return where_clause.get(); }
2077  void analyze(const Catalog_Namespace::Catalog& catalog,
2078  Analyzer::Query& query) const override;
2079 
2080  private:
2081  std::unique_ptr<std::string> table;
2082  std::list<std::unique_ptr<Assignment>> assignment_list;
2083  std::unique_ptr<Expr> where_clause;
2084 };
2085 
2086 /*
2087  * @type DeleteStmt
2088  * @brief DELETE statement
2089  */
2090 class DeleteStmt : public DMLStmt {
2091  public:
2092  DeleteStmt(std::string* t, Expr* w) : table(t), where_clause(w) {}
2093  const std::string* get_table() const { return table.get(); }
2094  const Expr* get_where_clause() const { return where_clause.get(); }
2095  void analyze(const Catalog_Namespace::Catalog& catalog,
2096  Analyzer::Query& query) const override;
2097 
2098  private:
2099  std::unique_ptr<std::string> table;
2100  std::unique_ptr<Expr> where_clause;
2101 };
2102 
2103 template <typename LITERAL_TYPE>
2105 
2106 template <>
2108  template <typename T>
2109  decltype(auto) operator()(T t) {
2110  const std::string property_name(boost::to_upper_copy<std::string>(*t->get_name()));
2111  if (!dynamic_cast<const IntLiteral*>(t->get_value())) {
2112  throw std::runtime_error(property_name + " must be an integer literal.");
2113  }
2114  const auto val = static_cast<const IntLiteral*>(t->get_value())->get_intval();
2115  if (val <= 0) {
2116  throw std::runtime_error(property_name + " must be a positive number.");
2117  }
2118  return val;
2119  }
2120 };
2121 
2123  template <typename T>
2124  decltype(auto) operator()(T t) {
2125  const std::string property_name(boost::to_upper_copy<std::string>(*t->get_name()));
2126  if (!dynamic_cast<const IntLiteral*>(t->get_value())) {
2127  throw std::runtime_error(property_name + " must be an integer literal.");
2128  }
2129  const auto val = static_cast<const IntLiteral*>(t->get_value())->get_intval();
2130  if (val < 0) {
2131  throw std::runtime_error(property_name + " must be greater than or equal to 0.");
2132  }
2133  return val;
2134  }
2135 };
2136 
2137 template <>
2139  template <typename T>
2140  decltype(auto) operator()(T t) {
2141  const auto val = static_cast<const StringLiteral*>(t->get_value())->get_stringval();
2142  CHECK(val);
2143  const auto val_upper = boost::to_upper_copy<std::string>(*val);
2144  return val_upper;
2145  }
2146 };
2147 
2149  template <typename T>
2150  decltype(auto) operator()(T t) {
2151  const auto val = static_cast<const StringLiteral*>(t->get_value())->get_stringval();
2152  CHECK(val);
2153  return *val;
2154  }
2155 };
2156 
2157 template <typename T>
2158 struct ShouldInvalidateSessionsByDB : public std::false_type {};
2159 template <typename T>
2160 struct ShouldInvalidateSessionsByUser : public std::false_type {};
2161 
2162 template <>
2163 struct ShouldInvalidateSessionsByDB<DropDBStmt> : public std::true_type {};
2164 template <>
2165 struct ShouldInvalidateSessionsByUser<DropUserStmt> : public std::true_type {};
2166 template <>
2167 struct ShouldInvalidateSessionsByDB<RenameDatabaseStmt> : public std::true_type {};
2168 template <>
2169 struct ShouldInvalidateSessionsByUser<RenameUserStmt> : public std::true_type {};
2170 
2177 void execute_calcite_ddl(
2178  const std::string& plan_result,
2179  std::shared_ptr<Catalog_Namespace::SessionInfo const> session_ptr);
2180 
2181 } // namespace Parser
2182 
2183 #endif // PARSERNODE_H_
const std::string * get_table() const
Definition: ParserNode.h:2072
std::list< std::unique_ptr< ColumnDef > > coldefs
Definition: ParserNode.h:1319
OperExpr(SQLOps t, SQLQualifier q, Expr *l, Expr *r)
Definition: ParserNode.h:300
ExistsExpr(QuerySpec *q)
Definition: ParserNode.h:584
const std::string foreign_column_
Definition: ParserNode.h:910
bool get_is_not() const
Definition: ParserNode.h:560
import_export::CopyParams _geo_copy_from_copy_params
Definition: ParserNode.h:1495
std::unique_ptr< std::string > table_name
Definition: ParserNode.h:705
CopyTableStmt(std::string *t, std::string *f, std::list< NameValueAssign *> *o)
Definition: ParserNode.h:1449
std::unique_ptr< std::string > username_
Definition: ParserNode.h:1272
std::unique_ptr< std::string > name
Definition: ParserNode.h:938
std::unique_ptr< std::string > view_name
Definition: ParserNode.h:1892
std::string filename(char const *path)
Definition: Logger.cpp:62
LikelihoodExpr(bool n, Expr *a, float l)
Definition: ParserNode.h:559
std::unique_ptr< std::string > table
Definition: ParserNode.h:1344
std::unique_ptr< std::string > role
Definition: ParserNode.h:1524
const std::string & get_view_name() const
Definition: ParserNode.h:1869
UniqueDef(bool p, std::list< std::string *> *cl)
Definition: ParserNode.h:825
std::list< std::unique_ptr< ExprPair > > when_then_list
Definition: ParserNode.h:688
std::unique_ptr< std::string > table
Definition: ParserNode.h:2013
const std::string & get_select_query() const
Definition: ParserNode.h:1870
IntLiteral(int64_t i)
Definition: ParserNode.h:154
std::unique_ptr< Expr > select_expr
Definition: ParserNode.h:1687
const Expr * get_arg() const
Definition: ParserNode.h:530
const std::string * get_table() const
Definition: ParserNode.h:2093
std::unique_ptr< Expr > where_clause
Definition: ParserNode.h:1742
int64_t get_intval() const
Definition: ParserNode.h:155
std::unique_ptr< Expr > arg
Definition: ParserNode.h:483
std::unique_ptr< std::string > foreign_column
Definition: ParserNode.h:777
std::list< std::unique_ptr< TableRef > > from_clause
Definition: ParserNode.h:1741
const std::string * get_table() const override
Definition: ParserNode.h:980
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1072
const std::vector< std::string > & get_grantees() const
Definition: ParserNode.h:1623
SQLOps get_optype() const
Definition: ParserNode.h:302
std::unique_ptr< std::string > table
Definition: ParserNode.h:1297
class for a per-database catalog. also includes metadata for the current database and the current use...
Definition: Catalog.h:101
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
SQLTypes
Definition: sqltypes.h:37
const std::string * get_new_table() const
Definition: ParserNode.h:1282
std::unique_ptr< std::string > column
Definition: ParserNode.h:614
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1973
std::unique_ptr< SQLType > target_type
Definition: ParserNode.h:654
std::unique_ptr< std::string > table
Definition: ParserNode.h:1317
bool get_success() const
Definition: ParserNode.h:1472
SQLType * get_column_type() const
Definition: ParserNode.h:798
std::unique_ptr< std::string > table
Definition: ParserNode.h:2081
std::vector< std::string > roles
Definition: ParserNode.h:1627
const std::vector< std::string > & get_grantees() const
Definition: ParserNode.h:1583
const std::list< std::unique_ptr< TableElement > > & get_table_element_list() const override
Definition: ParserNode.h:1061
std::unique_ptr< Expr > arg
Definition: ParserNode.h:356
std::list< std::unique_ptr< TableElement > > table_element_list_
Definition: ParserNode.h:994
const std::string * get_table() const
Definition: ParserNode.h:604
CastExpr(Expr *a, SQLType *t)
Definition: ParserNode.h:643
std::list< std::unique_ptr< NameValueAssign > > options
Definition: ParserNode.h:1491
std::unique_ptr< Expr > lower
Definition: ParserNode.h:442
DropViewStmt(std::string *v, bool i)
Definition: ParserNode.h:1885
const std::string & get_role() const
Definition: ParserNode.h:1506
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:1204
SQLQualifier
Definition: sqldefs.h:69
auto const & getPreviousDatabaseName()
Definition: ParserNode.h:1254
std::unique_ptr< QuerySpec > query
Definition: ParserNode.h:341
const QuerySpec * get_query() const
Definition: ParserNode.h:333
const std::string column_
Definition: ParserNode.h:908
const std::list< std::unique_ptr< Expr > > & get_value_list() const
Definition: ParserNode.h:281
const Expr * get_arg() const
Definition: ParserNode.h:454
std::unique_ptr< std::string > alias
Definition: ParserNode.h:1688
std::unique_ptr< std::string > return_message
Definition: ParserNode.h:1465
const std::vector< std::string > & get_privs() const
Definition: ParserNode.h:1552
StringLiteral(std::string *s)
Definition: ParserNode.h:135
const std::list< std::unique_ptr< Expr > > & get_groupby_clause() const
Definition: ParserNode.h:1730
DoubleLiteral(double d)
Definition: ParserNode.h:216
SQLOps
Definition: sqldefs.h:29
const std::string getType() const
Definition: ParserNode.h:1240
const std::vector< std::string > & get_grantees() const
Definition: ParserNode.h:1642
std::string to_string() const override
Definition: ParserNode.h:648
auto const & getNewDatabaseName()
Definition: ParserNode.h:1255
std::vector< std::string > grantees
Definition: ParserNode.h:1590
const Expr * get_arg() const
Definition: ParserNode.h:495
const Expr * get_upper() const
Definition: ParserNode.h:432
InsertIntoTableAsSelectStmt(const std::string *table_name, const std::string *select_query, std::list< std::string *> *c)
Definition: ParserNode.h:1082
std::unique_ptr< Expr > arg
Definition: ParserNode.h:463
std::unique_ptr< std::string > object
Definition: ParserNode.h:1608
std::unique_ptr< Expr > check_condition
Definition: ParserNode.h:775
const std::string * get_column() const
Definition: ParserNode.h:605
std::unique_ptr< std::string > table
Definition: ParserNode.h:613
const std::list< std::unique_ptr< Expr > > & get_value_list() const
Definition: ParserNode.h:2031
const SubqueryExpr * get_subquery() const
Definition: ParserNode.h:386
std::string to_string() const override
Definition: ParserNode.h:184
std::list< std::unique_ptr< std::string > > column_list
Definition: ParserNode.h:839
bool get_is_primarykey() const
Definition: ParserNode.h:764
std::string & get_table() const
Definition: ParserNode.h:1467
std::unique_ptr< std::string > path
Definition: ParserNode.h:1419
#define UNREACHABLE()
Definition: Logger.h:241
bool get_is_unionall() const
Definition: ParserNode.h:1667
std::unique_ptr< std::string > object
Definition: ParserNode.h:1561
std::unique_ptr< std::string > new_username_
Definition: ParserNode.h:1273
DropDBStmt(std::string *n, bool if_exists)
Definition: ParserNode.h:1925
const Expr * get_where_clause() const
Definition: ParserNode.h:2094
std::unique_ptr< Expr > where_clause
Definition: ParserNode.h:2100
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1952
const std::string getCompression() const
Definition: ParserNode.h:1415
std::unique_ptr< Expr > assignment
Definition: ParserNode.h:2055
const std::list< std::unique_ptr< std::string > > & get_foreign_column_list() const
Definition: ParserNode.h:866
std::unique_ptr< std::string > table
Definition: ParserNode.h:1488
QuerySpec(bool d, std::list< SelectEntry *> *s, std::list< TableRef *> *f, Expr *w, std::list< Expr *> *g, Expr *h)
Definition: ParserNode.h:1697
const std::list< std::unique_ptr< OrderSpec > > & get_orderby_clause() const
Definition: ParserNode.h:1793
DropRoleStmt(std::string *r)
Definition: ParserNode.h:1519
const std::string * get_fixedptval() const
Definition: ParserNode.h:176
const Expr * get_assignment() const
Definition: ParserNode.h:2051
const Expr * get_check_condition() const
Definition: ParserNode.h:883
bool shouldVacuumDeletedRows() const
Definition: ParserNode.h:1189
ShardKeyDef(const std::string &column)
Definition: ParserNode.h:919
const std::string * get_table() const
Definition: ParserNode.h:1314
const std::string & get_object() const
Definition: ParserNode.h:1582
const QuerySpec * get_query() const
Definition: ParserNode.h:585
std::unique_ptr< Literal > defaultval
Definition: ParserNode.h:774
const std::string & get_object_type() const
Definition: ParserNode.h:1581
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1069
std::unique_ptr< std::string > table
Definition: ParserNode.h:1155
size_t leafCount() override
Definition: ParserNode.h:1027
std::unique_ptr< std::string > new_column_name
Definition: ParserNode.h:1299
const Expr * get_escape_string() const
Definition: ParserNode.h:497
std::unique_ptr< ColumnConstraintDef > column_constraint
Definition: ParserNode.h:808
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:1340
std::unique_ptr< std::string > object_type
Definition: ParserNode.h:1607
bool get_is_primarykey() const
Definition: ParserNode.h:832
TableRef(std::string *t, std::string *r)
Definition: ParserNode.h:699
std::unique_ptr< Expr > arg
Definition: ParserNode.h:441
std::unique_ptr< std::string > object_type
Definition: ParserNode.h:1588
DumpTableStmt(std::string *tab, std::string *path, std::list< NameValueAssign *> *options)
Definition: ParserNode.h:1425
SQLType(SQLTypes t, bool a, int array_size)
Definition: ParserNode.h:79
std::unique_ptr< Expr > arg
Definition: ParserNode.h:376
name
Definition: setup.py:35
void parser_slistval_to_vector(std::list< std::string *> *l, std::vector< std::string > &v)
Definition: ParserNode.h:1527
ColumnConstraintDef(bool n, bool u, bool p, Literal *d)
Definition: ParserNode.h:752
const std::vector< std::string > & get_grantees() const
Definition: ParserNode.h:1555
bool get_is_not() const
Definition: ParserNode.h:366
const Expr * get_expr1() const
Definition: ParserNode.h:660
std::unique_ptr< std::string > file_path
Definition: ParserNode.h:1843
ColumnRef(std::string *n1, std::string *n2)
Definition: ParserNode.h:603
std::string to_string(char const *&&v)
SQLType(SQLTypes t)
Definition: ParserNode.h:74
double get_doubleval() const
Definition: ParserNode.h:217
const Expr * get_right() const
Definition: ParserNode.h:304
std::unique_ptr< std::string > column
Definition: ParserNode.h:2054
InsertValuesStmt(std::string *t, std::list< std::string *> *c, std::list< Expr *> *v)
Definition: ParserNode.h:2023
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1914
IsNullExpr(bool n, Expr *a)
Definition: ParserNode.h:346
std::vector< std::string > roles
Definition: ParserNode.h:1646
CaseExpr(std::list< ExprPair *> *w, Expr *e)
Definition: ParserNode.h:670
std::list< std::unique_ptr< Expr > > value_list
Definition: ParserNode.h:418
std::vector< std::string > privs
Definition: ParserNode.h:1587
std::list< std::unique_ptr< std::string > > columns
Definition: ParserNode.h:1335
std::string to_string() const override
Definition: ParserNode.h:142
CreateDataframeStmt(std::string *tab, std::list< TableElement *> *table_elems, std::string *filename, std::list< NameValueAssign *> *s)
Definition: ParserNode.h:1043
std::unique_ptr< std::string > table
Definition: ParserNode.h:1418
std::list< std::unique_ptr< std::string > > foreign_column_list
Definition: ParserNode.h:873
const std::string & get_role() const
Definition: ParserNode.h:1603
std::string to_string() const override
Definition: ParserNode.h:264
const std::string * get_name() const
Definition: ParserNode.h:626
InSubquery(bool n, Expr *a, SubqueryExpr *q)
Definition: ParserNode.h:385
const std::vector< std::string > & get_privs() const
Definition: ParserNode.h:1580
CreateRoleStmt(std::string *r)
Definition: ParserNode.h:1505
const std::string * get_prev_table() const
Definition: ParserNode.h:1281
std::unique_ptr< Expr > expr2
Definition: ParserNode.h:665
std::unique_ptr< Expr > arg
Definition: ParserNode.h:638
std::list< std::unique_ptr< SelectEntry > > select_clause
Definition: ParserNode.h:1740
const QueryExpr * get_left() const
Definition: ParserNode.h:1668
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1915
Definition: ParserNode.h:1679
const Expr * get_having_clause() const
Definition: ParserNode.h:1733
std::list< std::unique_ptr< Expr > > value_list
Definition: ParserNode.h:289
std::string to_string() const override
Definition: ParserNode.h:242
const std::string * get_foreign_column() const
Definition: ParserNode.h:768
ExprPair(Expr *e1, Expr *e2)
Definition: ParserNode.h:659
const Expr * get_where_clause() const
Definition: ParserNode.h:1729
const std::string * get_column_name() const
Definition: ParserNode.h:797
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:1139
std::unique_ptr< ColumnRef > column
Definition: ParserNode.h:1772
bool get_is_not() const
Definition: ParserNode.h:529
std::unique_ptr< Expr > where_clause
Definition: ParserNode.h:2083
std::unique_ptr< std::string > type_
Definition: ParserNode.h:1245
std::unique_ptr< std::string > foreign_table
Definition: ParserNode.h:872
std::vector< std::string > grantees
Definition: ParserNode.h:1562
const std::string & get_foreign_column() const
Definition: ParserNode.h:905
std::unique_ptr< SQLType > column_type
Definition: ParserNode.h:806
const QueryExpr * get_query_expr() const
Definition: ParserNode.h:1792
std::unique_ptr< Expr > expr1
Definition: ParserNode.h:664
AddColumnStmt(std::string *tab, std::list< ColumnDef *> *coldefs)
Definition: ParserNode.h:1305
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1974
const std::vector< std::string > & get_roles() const
Definition: ParserNode.h:1622
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
SelectStmt(QueryExpr *q, std::list< OrderSpec *> *o, int64_t l, int64_t f)
Definition: ParserNode.h:1783
const std::string * get_range_var() const
Definition: ParserNode.h:701
auto const & getUserName()
Definition: ParserNode.h:1984
std::unique_ptr< std::string > role
Definition: ParserNode.h:1510
ColumnDef(std::string *c, SQLType *t, CompressDef *cp, ColumnConstraintDef *cc)
Definition: ParserNode.h:795
std::string select_query_
Definition: ParserNode.h:1875
AlterUserStmt(std::string *n, std::list< NameValueAssign *> *l)
Definition: ParserNode.h:1962
std::string _geo_copy_from_partitions
Definition: ParserNode.h:1496
RevokeRoleStmt(std::list< std::string *> *r, std::list< std::string *> *g)
Definition: ParserNode.h:1637
const Expr * get_expr2() const
Definition: ParserNode.h:661
const Expr * get_lower() const
Definition: ParserNode.h:431
const ColumnConstraintDef * get_column_constraint() const
Definition: ParserNode.h:800
std::unique_ptr< std::string > table
Definition: ParserNode.h:2099
bool get_calc_encoded_length() const
Definition: ParserNode.h:455
std::list< std::unique_ptr< std::string > > column_list
Definition: ParserNode.h:2014
const std::list< std::unique_ptr< std::string > > & get_column_list() const
Definition: ParserNode.h:833
bool get_is_distinct() const
Definition: ParserNode.h:1722
const std::list< std::unique_ptr< Assignment > > & get_assignment_list() const
Definition: ParserNode.h:2073
const std::string & get_object() const
Definition: ParserNode.h:1602
FunctionRef(std::string *n, Expr *a)
Definition: ParserNode.h:624
DropUserStmt(std::string *n)
Definition: ParserNode.h:1983
int get_colno() const
Definition: ParserNode.h:1765
std::unique_ptr< QueryExpr > right
Definition: ParserNode.h:1676
std::unique_ptr< Expr > escape_string
Definition: ParserNode.h:514
specifies the content in-memory of a row in the column metadata table
UpdateStmt(std::string *t, std::list< Assignment *> *a, Expr *w)
Definition: ParserNode.h:2064
RevokePrivilegesStmt(std::list< std::string *> *p, std::string *t, std::string *o, std::list< std::string *> *g)
Definition: ParserNode.h:1571
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:1205
std::string to_string() const override
Definition: ParserNode.h:202
const std::string * get_name() const
Definition: ParserNode.h:934
const std::string foreign_table_
Definition: ParserNode.h:909
float get_likelihood() const
Definition: ParserNode.h:562
float get_floatval() const
Definition: ParserNode.h:197
AddColumnStmt(std::string *tab, ColumnDef *coldef)
Definition: ParserNode.h:1304
const std::list< std::unique_ptr< std::string > > & get_column_list() const
Definition: ParserNode.h:862
const std::string * get_foreign_table() const
Definition: ParserNode.h:865
std::unique_ptr< Expr > pattern_string
Definition: ParserNode.h:546
const std::string & get_object_type() const
Definition: ParserNode.h:1601
const std::string & get_role() const
Definition: ParserNode.h:1520
SQLType(SQLTypes t, int p1, int p2, bool a, int array_size)
Definition: ParserNode.h:77
std::unique_ptr< std::string > database_name_
Definition: ParserNode.h:1259
const Literal * get_defaultval() const
Definition: ParserNode.h:765
TruncateTableStmt(std::string *tab)
Definition: ParserNode.h:1165
std::unique_ptr< std::string > new_table_name
Definition: ParserNode.h:1287
std::unique_ptr< std::string > user_name
Definition: ParserNode.h:1988
UnionQuery(bool u, QueryExpr *l, QueryExpr *r)
Definition: ParserNode.h:1666
const std::string * get_column() const
Definition: ParserNode.h:2050
SQLQualifier opqualifier
Definition: ParserNode.h:318
const std::list< std::unique_ptr< std::string > > & get_column_list() const
Definition: ParserNode.h:2006
std::list< std::unique_ptr< Expr > > groupby_clause
Definition: ParserNode.h:1743
const Expr * get_like_string() const
Definition: ParserNode.h:496
std::unique_ptr< Expr > left
Definition: ParserNode.h:319
virtual ~Node()
Definition: ParserNode.h:65
bool get_distinct() const
Definition: ParserNode.h:627
void execute(const Catalog_Namespace::SessionInfo &session) override
Definition: ParserNode.h:1242
std::unique_ptr< Expr > arg
Definition: ParserNode.h:574
const std::string & get_object() const
Definition: ParserNode.h:1554
bool get_is_not() const
Definition: ParserNode.h:494
std::unique_ptr< std::string > column_name
Definition: ParserNode.h:805
const std::list< std::unique_ptr< Expr > > & get_value_list() const
Definition: ParserNode.h:410
void execute_calcite_ddl(const std::string &ddl_statement, std::shared_ptr< Catalog_Namespace::SessionInfo const > session_ptr)
Definition: sqldefs.h:69
const std::string & get_column() const
Definition: ParserNode.h:901
GrantPrivilegesStmt(std::list< std::string *> *p, std::string *t, std::string *o, std::list< std::string *> *g)
Definition: ParserNode.h:1543
RenameDatabaseStmt(std::string *database_name, std::string *new_database_name)
Definition: ParserNode.h:1251
const std::string & get_object_type() const
Definition: ParserNode.h:1553
const std::list< std::unique_ptr< TableElement > > & get_table_element_list() const override
Definition: ParserNode.h:981
ValidateStmt(std::string *type, std::list< NameValueAssign *> *with_opts)
Definition: ParserNode.h:1210
Expr * get_arg() const
Definition: ParserNode.h:628
std::unique_ptr< Literal > value
Definition: ParserNode.h:939
std::list< std::unique_ptr< Assignment > > assignment_list
Definition: ParserNode.h:2082
std::unique_ptr< QueryExpr > left
Definition: ParserNode.h:1675
const std::string * get_view_name() const
Definition: ParserNode.h:1888
std::unique_ptr< std::string > column
Definition: ParserNode.h:1298
InExpr(bool n, Expr *a)
Definition: ParserNode.h:365
std::unique_ptr< QueryExpr > query_expr
Definition: ParserNode.h:1800
CreateDBStmt(std::string *n, std::list< NameValueAssign *> *l, const bool if_not_exists)
Definition: ParserNode.h:1902
const Expr * get_arg() const
Definition: ParserNode.h:561
DropTableStmt(std::string *tab, bool i)
Definition: ParserNode.h:1148
std::unique_ptr< Expr > like_string
Definition: ParserNode.h:513
CompressDef(std::string *n, int p)
Definition: ParserNode.h:786
RestoreTableStmt(std::string *tab, std::string *path, std::list< NameValueAssign *> *options)
Definition: ParserNode.h:1436
std::list< std::unique_ptr< NameValueAssign > > options
Definition: ParserNode.h:1844
const QueryExpr * get_right() const
Definition: ParserNode.h:1669
std::unique_ptr< std::string > table
Definition: ParserNode.h:1334
const std::string & get_foreign_table() const
Definition: ParserNode.h:903
Definition: Catalog.h:63
std::unique_ptr< std::string > range_var
Definition: ParserNode.h:706
std::string to_string() const override
Definition: ParserNode.h:161
NameValueAssign(std::string *n, Literal *v)
Definition: ParserNode.h:933
std::list< std::unique_ptr< NameValueAssign > > storage_options_
Definition: ParserNode.h:997
const std::string column_
Definition: ParserNode.h:924
const std::list< std::unique_ptr< SelectEntry > > & get_select_clause() const
Definition: ParserNode.h:1723
std::unique_ptr< std::string > object
Definition: ParserNode.h:1589
CharLengthExpr(Expr *a, bool e)
Definition: ParserNode.h:453
const std::string * getPath() const
Definition: ParserNode.h:1414
auto const & getNewUserName()
Definition: ParserNode.h:1268
ExportQueryStmt(std::string *q, std::string *p, std::list< NameValueAssign *> *o)
Definition: ParserNode.h:1827
CreateViewStmt(const std::string &view_name, const std::string &select_query, const bool if_not_exists)
Definition: ParserNode.h:1860
std::vector< std::string > privs
Definition: ParserNode.h:1559
InValues(bool n, Expr *a, std::list< Expr *> *v)
Definition: ParserNode.h:403
const Expr * get_arg() const
Definition: ParserNode.h:475
const Expr * get_arg() const
Definition: ParserNode.h:367
std::vector< std::unique_ptr< std::string > > column_list_
Definition: ParserNode.h:1107
DropColumnStmt(std::string *tab, std::list< std::string *> *cols)
Definition: ParserNode.h:1324
TableRef(std::string *t)
Definition: ParserNode.h:698
std::unique_ptr< std::string > table_
Definition: ParserNode.h:1817
const std::list< std::unique_ptr< TableRef > > & get_from_clause() const
Definition: ParserNode.h:1726
const Expr * get_left() const
Definition: ParserNode.h:303
std::unique_ptr< QuerySpec > query
Definition: ParserNode.h:593
RenameUserStmt(std::string *username, std::string *new_username)
Definition: ParserNode.h:1265
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:1476
std::unique_ptr< ColumnDef > coldef
Definition: ParserNode.h:1318
std::unique_ptr< NameValueAssign > param
Definition: ParserNode.h:1345
std::unique_ptr< std::string > name
Definition: ParserNode.h:636
std::unique_ptr< std::string > fixedptval
Definition: ParserNode.h:187
const std::string * get_table() const
Definition: ParserNode.h:1166
std::unique_ptr< std::string > role
Definition: ParserNode.h:1609
std::unique_ptr< std::string > file_pattern
Definition: ParserNode.h:1489
std::unique_ptr< Expr > arg
Definition: ParserNode.h:653
#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:2049
const std::string * get_table() const
Definition: ParserNode.h:1151
const std::string * get_table() const
Definition: ParserNode.h:2005
ShowCreateTableStmt(std::string *tab)
Definition: ParserNode.h:1812
bool was_geo_copy_from() const
Definition: ParserNode.h:1474
std::string to_string() const override
Definition: ParserNode.h:222
ColumnConstraintDef(std::string *t, std::string *c)
Definition: ParserNode.h:756
SubqueryExpr(QuerySpec *q)
Definition: ParserNode.h:332
std::string to_string() const override
Definition: ParserNode.h:126
The data to be inserted using the fragment manager.
Definition: Fragmenter.h:59
std::unique_ptr< std::string > stringval
Definition: ParserNode.h:145
std::unique_ptr< std::string > table
Definition: ParserNode.h:1170
InsertStmt(std::string *t, std::list< std::string *> *c)
Definition: ParserNode.h:1997
const Expr * get_arg() const
Definition: ParserNode.h:430
std::list< std::unique_ptr< Expr > > value_list
Definition: ParserNode.h:2040
CreateUserStmt(std::string *n, std::list< NameValueAssign *> *l)
Definition: ParserNode.h:1941
ForeignKeyDef(std::list< std::string *> *cl, std::string *t, std::list< std::string *> *fcl)
Definition: ParserNode.h:848
std::unique_ptr< std::string > object_type
Definition: ParserNode.h:1560
const std::vector< std::string > & get_roles() const
Definition: ParserNode.h:1641
bool isRepairTypeRemove() const
Definition: ParserNode.h:1238
const Expr * get_pattern_string() const
Definition: ParserNode.h:531
const std::string * get_table() const override
Definition: ParserNode.h:1060
auto const & getOldUserName()
Definition: ParserNode.h:1267
OptimizeTableStmt(std::string *table, std::list< NameValueAssign *> *o)
Definition: ParserNode.h:1175
std::unique_ptr< Expr > having_clause
Definition: ParserNode.h:1744
const Expr * get_where_clause() const
Definition: ParserNode.h:2076
const std::string & get_column() const
Definition: ParserNode.h:921
const std::string * get_alias() const
Definition: ParserNode.h:1683
std::unique_ptr< std::string > db_name
Definition: ParserNode.h:1931
ColumnRef(std::string *n1)
Definition: ParserNode.h:602
bool get_nulls_first() const
Definition: ParserNode.h:1768
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:1874
bool get_is_desc() const
Definition: ParserNode.h:1767
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::string _geo_copy_from_file_name
Definition: ParserNode.h:1494
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:1070
std::unique_ptr< std::string > foreign_table
Definition: ParserNode.h:776
RenameColumnStmt(std::string *tab, std::string *col, std::string *new_col_name)
Definition: ParserNode.h:1292
const Expr * get_check_condition() const
Definition: ParserNode.h:766
bool get_is_not() const
Definition: ParserNode.h:347
GrantRoleStmt(std::list< std::string *> *r, std::list< std::string *> *g)
Definition: ParserNode.h:1618
const ColumnRef * get_column() const
Definition: ParserNode.h:1766
std::vector< std::string > grantees
Definition: ParserNode.h:1628
bool is_distinct(const size_t input_idx, const RelAlgNode *node)
FunctionRef(std::string *n, bool d, Expr *a)
Definition: ParserNode.h:625
std::unique_ptr< std::string > select_stmt
Definition: ParserNode.h:1842
const std::string get_select_stmt() const
Definition: ParserNode.h:1837
std::unique_ptr< std::string > table_
Definition: ParserNode.h:993
ArrayLiteral(std::list< Expr *> *v)
Definition: ParserNode.h:274
const std::string * get_foreign_table() const
Definition: ParserNode.h:767
void execute(const Catalog_Namespace::SessionInfo &session) override
Definition: ParserNode.h:1198
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:1118
std::list< std::unique_ptr< NameValueAssign > > name_value_list
Definition: ParserNode.h:1953
std::vector< std::string > grantees
Definition: ParserNode.h:1647
const Expr * get_escape_string() const
Definition: ParserNode.h:532
OrderSpec(int n, ColumnRef *c, bool d, bool f)
Definition: ParserNode.h:1763
const std::string * get_table() const
Definition: ParserNode.h:1331
RegexpExpr(bool n, Expr *a, Expr *p, Expr *e)
Definition: ParserNode.h:527
std::unique_ptr< std::string > table
Definition: ParserNode.h:1286
std::unique_ptr< std::string > filename_
Definition: ParserNode.h:1071
const CompressDef * get_compression() const
Definition: ParserNode.h:799
ShowPrivilegesStmt(std::string *t, std::string *o, std::string *r)
Definition: ParserNode.h:1599
const Expr * get_select_expr() const
Definition: ParserNode.h:1682
SelectEntry(Expr *e, std::string *r)
Definition: ParserNode.h:1681
const Literal * get_value() const
Definition: ParserNode.h:935
bool get_is_not() const
Definition: ParserNode.h:429
const std::string getTableName() const
Definition: ParserNode.h:1187
const std::string * get_table_name() const
Definition: ParserNode.h:700
std::unique_ptr< Expr > arg
Definition: ParserNode.h:512
std::list< std::unique_ptr< OrderSpec > > orderby_clause
Definition: ParserNode.h:1801
const std::string * get_stringval() const
Definition: ParserNode.h:136
DumpRestoreTableStmtBase(std::string *tab, std::string *path, std::list< NameValueAssign *> *options, const bool is_restore)
Definition: ParserNode.h:1354
std::unique_ptr< Expr > check_condition
Definition: ParserNode.h:886
const std::string * getTable() const
Definition: ParserNode.h:1413
RenameTableStmt(std::string *tab, std::string *new_tab_name)
Definition: ParserNode.h:1278
auto const & getDatabaseName()
Definition: ParserNode.h:1927
DeleteStmt(std::string *t, Expr *w)
Definition: ParserNode.h:2092
std::unique_ptr< std::string > new_database_name_
Definition: ParserNode.h:1260