sql_query.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma once
  2. #include "sql_translation.h"
  3. #include <yql/essentials/parser/proto_ast/gen/v1_proto_split/SQLv1Parser.pb.main.h>
  4. #include <util/string/split.h>
  5. namespace NSQLTranslationV1 {
  6. using namespace NSQLv1Generated;
  7. class TSqlQuery: public TSqlTranslation {
  8. public:
  9. TSqlQuery(TContext& ctx, NSQLTranslation::ESqlMode mode, bool topLevel)
  10. : TSqlTranslation(ctx, mode)
  11. , TopLevel(topLevel)
  12. {
  13. }
  14. TNodePtr Build(const TSQLv1ParserAST& ast);
  15. TNodePtr Build(const std::vector<::NSQLv1Generated::TRule_sql_stmt_core>& ast);
  16. bool Statement(TVector<TNodePtr>& blocks, const TRule_sql_stmt_core& core, size_t statementNumber);
  17. private:
  18. bool DeclareStatement(const TRule_declare_stmt& stmt);
  19. bool ExportStatement(const TRule_export_stmt& stmt);
  20. bool AlterTableAction(const TRule_alter_table_action& node, TAlterTableParameters& params);
  21. bool AlterExternalTableAction(const TRule_alter_external_table_action& node, TAlterTableParameters& params);
  22. bool AlterTableAddColumn(const TRule_alter_table_add_column& node, TAlterTableParameters& params);
  23. bool AlterTableDropColumn(const TRule_alter_table_drop_column& node, TAlterTableParameters& params);
  24. bool AlterTableAlterColumn(const TRule_alter_table_alter_column& node, TAlterTableParameters& params);
  25. bool AlterTableAddFamily(const TRule_family_entry& node, TAlterTableParameters& params);
  26. bool AlterTableAlterFamily(const TRule_alter_table_alter_column_family& node, TAlterTableParameters& params);
  27. bool AlterTableSetTableSetting(const TRule_alter_table_set_table_setting_uncompat& node, TTableSettings& tableSettings, ETableType tableType);
  28. bool AlterTableSetTableSetting(const TRule_alter_table_set_table_setting_compat& node, TTableSettings& tableSettings, ETableType tableType);
  29. bool AlterTableResetTableSetting(const TRule_alter_table_reset_table_setting& node, TTableSettings& tableSettings, ETableType tableType);
  30. bool AlterTableAddIndex(const TRule_alter_table_add_index& node, TAlterTableParameters& params);
  31. void AlterTableDropIndex(const TRule_alter_table_drop_index& node, TAlterTableParameters& params);
  32. void AlterTableRenameTo(const TRule_alter_table_rename_to& node, TAlterTableParameters& params);
  33. bool AlterTableAddChangefeed(const TRule_alter_table_add_changefeed& node, TAlterTableParameters& params);
  34. bool AlterTableAlterChangefeed(const TRule_alter_table_alter_changefeed& node, TAlterTableParameters& params);
  35. void AlterTableDropChangefeed(const TRule_alter_table_drop_changefeed& node, TAlterTableParameters& params);
  36. void AlterTableRenameIndexTo(const TRule_alter_table_rename_index_to& node, TAlterTableParameters& params);
  37. bool AlterTableAlterIndex(const TRule_alter_table_alter_index& node, TAlterTableParameters& params);
  38. bool AlterSequenceAction(const TRule_alter_sequence_action& node, TSequenceParameters& params);
  39. TNodePtr PragmaStatement(const TRule_pragma_stmt& stmt, bool& success);
  40. void AddStatementToBlocks(TVector<TNodePtr>& blocks, TNodePtr node);
  41. bool ParseTableStoreFeatures(std::map<TString, TDeferredAtom> & result, const TRule_alter_table_store_action & actions);
  42. bool AlterTableAlterColumnDropNotNull(const TRule_alter_table_alter_column_drop_not_null& node, TAlterTableParameters& params);
  43. TNodePtr Build(const TRule_delete_stmt& stmt);
  44. TNodePtr Build(const TRule_update_stmt& stmt);
  45. TSourcePtr Build(const TRule_set_clause_choice& stmt);
  46. bool FillSetClause(const TRule_set_clause& node, TVector<TString>& targetList, TVector<TNodePtr>& values);
  47. TSourcePtr Build(const TRule_set_clause_list& stmt);
  48. TSourcePtr Build(const TRule_multiple_column_assignment& stmt);
  49. template<class TNode>
  50. void ParseStatementName(const TNode& node, TString& internalStatementName, TString& humanStatementName) {
  51. internalStatementName.clear();
  52. humanStatementName.clear();
  53. const auto& descr = AltDescription(node);
  54. TVector<TString> parts;
  55. if (!Ctx.Settings.Antlr4Parser) {
  56. const auto pos = descr.find(": ");
  57. Y_DEBUG_ABORT_UNLESS(pos != TString::npos);
  58. Split(TString(descr.begin() + pos + 2, descr.end()), "_", parts);
  59. } else {
  60. Split(descr, "_", parts);
  61. }
  62. Y_DEBUG_ABORT_UNLESS(parts.size() > 1);
  63. parts.pop_back();
  64. for (auto& part: parts) {
  65. part.to_upper(0, 1);
  66. internalStatementName += part;
  67. if (!humanStatementName.empty()) {
  68. humanStatementName += ' ';
  69. }
  70. humanStatementName += to_upper(part);
  71. }
  72. }
  73. const bool TopLevel;
  74. };
  75. } // namespace NSQLTranslationV1