translation_settings.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #pragma once
  2. #include <yql/essentials/core/pg_settings/guc_settings.h>
  3. #include <util/generic/hash.h>
  4. #include <util/generic/hash_set.h>
  5. #include <util/generic/map.h>
  6. #include <util/generic/maybe.h>
  7. #include <util/generic/vector.h>
  8. namespace google::protobuf {
  9. class Arena;
  10. }
  11. namespace NYql {
  12. class TIssues;
  13. class IAutoParamBuilderFactory;
  14. }
  15. namespace NSQLTranslation {
  16. constexpr const size_t SQL_MAX_PARSER_ERRORS = 100;
  17. enum class ESqlMode {
  18. QUERY = 0,
  19. LIMITED_VIEW = 1,
  20. LIBRARY = 2,
  21. SUBQUERY = 3,
  22. DISCOVERY = 4,
  23. };
  24. enum class EBindingsMode {
  25. // raise error
  26. DISABLED,
  27. // classic support for bindings
  28. ENABLED,
  29. // bindings.my_binding -> current_cluster.my_binding + raise warning
  30. DROP_WITH_WARNING,
  31. // bindings.my_binding -> current_cluster.my_binding
  32. DROP
  33. };
  34. inline bool IsQueryMode(NSQLTranslation::ESqlMode mode) {
  35. return mode == NSQLTranslation::ESqlMode::QUERY || mode == NSQLTranslation::ESqlMode::DISCOVERY;
  36. }
  37. using TIncrementMonCounterFunction = std::function<void(const TString&, const TString&)>;
  38. // persisted
  39. enum class EV0Behavior : ui32 {
  40. Silent = 0,
  41. Report,
  42. Disable
  43. };
  44. class ISqlFeaturePolicy : public TThrRefBase {
  45. public:
  46. virtual ~ISqlFeaturePolicy() = default;
  47. virtual bool Allow() const = 0;
  48. using TPtr = TIntrusivePtr<ISqlFeaturePolicy>;
  49. static TPtr MakeAlwaysDisallow();
  50. static TPtr MakeAlwaysAllow();
  51. static TPtr Make(bool allow);
  52. };
  53. struct TTableBindingSettings {
  54. TString ClusterType;
  55. THashMap<TString, TString> Settings;
  56. };
  57. struct TTranslationSettings
  58. {
  59. TTranslationSettings();
  60. google::protobuf::Arena* Arena = nullptr;
  61. THashMap<TString, TString> ClusterMapping;
  62. TString PathPrefix;
  63. // keys (cluster name) should be normalized
  64. THashMap<TString, TString> ClusterPathPrefixes;
  65. THashMap<TString, TString> ModuleMapping;
  66. THashSet<TString> Libraries;
  67. THashSet<TString> Flags;
  68. EBindingsMode BindingsMode;
  69. THashMap<TString, TTableBindingSettings> Bindings;
  70. bool SaveWorldDependencies = false;
  71. // each (name, type) entry in this map is equivalent to
  72. // DECLARE $name AS type;
  73. // NOTE: DECLARE statement in SQL text overrides entry in DeclaredNamedExprs
  74. TMap<TString, TString> DeclaredNamedExprs;
  75. ESqlMode Mode;
  76. TString DefaultCluster;
  77. TIncrementMonCounterFunction IncrementCounter;
  78. size_t MaxErrors;
  79. bool EndOfQueryCommit;
  80. TString File;
  81. bool EnableGenericUdfs;
  82. ui16 SyntaxVersion;
  83. bool AnsiLexer;
  84. bool Antlr4Parser;
  85. bool PgParser;
  86. bool InferSyntaxVersion;
  87. EV0Behavior V0Behavior;
  88. bool V0ForceDisable;
  89. bool PGDisable;
  90. bool WarnOnV0;
  91. bool TestAntlr4;
  92. ISqlFeaturePolicy::TPtr V0WarnAsError;
  93. ISqlFeaturePolicy::TPtr DqDefaultAuto;
  94. ISqlFeaturePolicy::TPtr BlockDefaultAuto;
  95. bool AssumeYdbOnClusterWithSlash;
  96. TString DynamicClusterProvider;
  97. TString FileAliasPrefix;
  98. TVector<ui32> PgParameterTypeOids;
  99. bool AutoParametrizeEnabled = false;
  100. bool AutoParametrizeValuesStmt = false;
  101. TGUCSettings::TPtr GUCSettings = std::make_shared<TGUCSettings>();
  102. bool UnicodeLiterals = false;
  103. TMaybe<TString> ApplicationName;
  104. bool PgSortNulls = false;
  105. NYql::IAutoParamBuilderFactory* AutoParamBuilderFactory = nullptr;
  106. bool EmitReadsForExists = false;
  107. };
  108. bool ParseTranslationSettings(const TString& query, NSQLTranslation::TTranslationSettings& settings, NYql::TIssues& issues);
  109. } // namespace NSQLTranslation