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