#pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace NKikimr::NMiniKQL { class IFunctionRegistry; } namespace NYql { class TFileStorageConfig; class TGatewaysConfig; } namespace NYql::NProto { class TPgExtensions; } namespace NYqlMountConfig { class TMountConfig; } namespace NYql { enum class ERunMode { Parse /* "parse" */, Compile /* "compile" */, Validate /* "validate" */, Optimize /* "optimize" */, Peephole /* "peephole" */, Lineage /* "lineage" */, Discover /* "discover" */, Run /* "run" */, }; enum class EProgramType { SExpr /* "s-expr" */, Sql /* "sql" */, Pg /* "pg" */, }; enum class EQPlayerMode { None /* "none" */, Capture /* "capture" */, Replay /* "replay" */, }; class TFacadeRunOptions { public: TFacadeRunOptions(); ~TFacadeRunOptions(); EProgramType ProgramType = EProgramType::SExpr; NYson::EYsonFormat ResultsFormat = NYson::EYsonFormat::Text; ERunMode Mode = ERunMode::Run; TString ProgramFile; TString ProgramText; TString User; TString Token; ui64 MemLimit = 0; EQPlayerMode QPlayerMode = EQPlayerMode::None; TString OperationId; TQContext QPlayerContext; THashSet SqlFlags; ui16 SyntaxVersion = 1; bool AnsiLexer = false; bool TestAntlr4 = false; bool AssumeYdbOnClusterWithSlash = false; bool PrintAst = false; bool FullExpr = false; bool WithTypes = false; bool FullStatistics = false; int Verbosity = TLOG_ERR; bool ShowLog = false; bool WithFinalIssues = false; IOutputStream* TraceOptStream = nullptr; IOutputStream* ErrStream = &Cerr; IOutputStream* PlanStream = nullptr; IOutputStream* ExprStream = nullptr; IOutputStream* ResultStream = nullptr; IOutputStream* StatStream = nullptr; NYql::TUserDataTable DataTable; TVector UdfsPaths; TString Params; NUdf::EValidateMode ValidateMode = NUdf::EValidateMode::Greedy; TCredentials::TPtr Credentials = MakeIntrusive(); THashSet GatewayTypes; TString UdfResolverPath; bool UdfResolverFilterSyscalls = false; bool ScanUdfs = false; THolder MountConfig; THolder GatewaysConfig; THolder FsConfig; THolder PgExtConfig; // No command line options for these settings. Should be configured in the inherited class bool NoDebug = false; bool PgSupport = true; bool FailureInjectionSupport = false; bool UseRepeatableRandomAndTimeProviders = false; bool UseMetaFromGrpah = false; bool TestSqlFormat = false; bool ValidateResultFormat = false; bool EnableResultPosition = false; bool EnableCredentials = false; bool EnableQPlayer = false; bool OptimizeLibs = true; void Parse(int argc, const char *argv[]); void AddOptExtension(std::function optExtender) { OptExtenders_.push_back(std::move(optExtender)); } void AddOptHandler(std::function optHandler) { OptHandlers_.push_back(std::move(optHandler)); } void SetSupportedGateways(std::initializer_list gateways) { SupportedGateways_.insert(gateways); } void InitLogger(); void PrintInfo(const TString& msg); private: std::vector> OptExtenders_; std::vector> OptHandlers_; THashSet SupportedGateways_; THolder ErrStreamHolder_; THolder PlanStreamHolder_; THolder ExprStreamHolder_; THolder ResultStreamHolder_; THolder StatStreamHolder_; IQStoragePtr QPlayerStorage_; }; class TFacadeRunner { public: TFacadeRunner(TString name); ~TFacadeRunner(); int Main(int argc, const char *argv[]); void AddFsDownloadFactory(std::function factory) { FsDownloadFactories_.push_back(std::move(factory)); } void AddProviderFactory(std::function factory) { ProviderFactories_.push_back(std::move(factory)); } void AddUrlListerFactory(std::function factory) { UrlListerFactories_.push_back(std::move(factory)); } void AddClusterMapping(TString name, TString provider) { ClusterMapping_[name] = std::move(provider); } template void FillClusterMapping(const TPbConfig& config, const TString& provider) { for (auto& cluster: config.GetClusterMapping()) { ClusterMapping_.emplace(to_lower(cluster.GetName()), provider); } } void SetOperationProgressWriter(TOperationProgressWriter writer) { ProgressWriter_ = std::move(writer); } void SetOptPipelineConfigurator(IPipelineConfigurator* configurator) { OptPipelineConfigurator_ = configurator; } void SetPeepholePipelineConfigurator(IPipelineConfigurator* configurator) { PeepholePipelineConfigurator_ = configurator; } TFileStoragePtr GetFileStorage() const { return FileStorage_; } TIntrusivePtr GetFuncRegistry(); TFacadeRunOptions& GetRunOptions() { return RunOptions_; } protected: virtual int DoMain(int argc, const char *argv[]); virtual int DoRun(TProgramFactory& factory); virtual TProgram::TStatus DoRunProgram(TProgramPtr program); private: TString Name_; std::vector> FsDownloadFactories_; std::vector> ProviderFactories_; std::vector> UrlListerFactories_; THashMap ClusterMapping_; THolder FileStorageConfig_; TFileStoragePtr FileStorage_; TIntrusivePtr FuncRegistry_; TOperationProgressWriter ProgressWriter_; IPipelineConfigurator* OptPipelineConfigurator_ = nullptr; IPipelineConfigurator* PeepholePipelineConfigurator_ = nullptr; TFacadeRunOptions RunOptions_; }; } // NYql