@@ -3259,4 +3259,182 @@ TNodePtr BuildAnalyze(TPosition pos, const TString& service, const TDeferredAtom
32593259 return new TAnalyzeNode (pos, service, cluster, params, scoped);
32603260}
32613261
3262+ class TBaseBackupCollectionNode
3263+ : public TAstListNode
3264+ , public TObjectOperatorContext
3265+ {
3266+ using TBase = TAstListNode;
3267+ public:
3268+ TBaseBackupCollectionNode (
3269+ TPosition pos,
3270+ const TString& objectId,
3271+ const TObjectOperatorContext& context)
3272+ : TBase(pos)
3273+ , TObjectOperatorContext(context)
3274+ , Id(objectId)
3275+ {}
3276+
3277+ bool DoInit (TContext& ctx, ISource* src) final {
3278+ auto keys = Y (" Key" );
3279+ keys = L (keys, Q (Y (Q (" backupCollection" ), Y (" String" , BuildQuotedAtom (Pos, Id)))));
3280+ auto options = this ->FillOptions (ctx, Y ());
3281+
3282+ Add (" block" , Q (Y (
3283+ Y (" let" , " sink" , Y (" DataSink" , BuildQuotedAtom (Pos, ServiceId), Scoped->WrapCluster (Cluster, ctx))),
3284+ Y (" let" , " world" , Y (TString (WriteName), " world" , " sink" , keys, Y (" Void" ), Q (options))),
3285+ Y (" return" , ctx.PragmaAutoCommit ? Y (TString (CommitName), " world" , " sink" ) : AstNode (" world" ))
3286+ )));
3287+
3288+ return TAstListNode::DoInit (ctx, src);
3289+ }
3290+
3291+ virtual INode::TPtr FillOptions (TContext& ctx, INode::TPtr options) const = 0;
3292+
3293+ private:
3294+ TString Id;
3295+ };
3296+
3297+ class TCreateBackupCollectionNode
3298+ : public TBaseBackupCollectionNode
3299+ {
3300+ using TBase = TBaseBackupCollectionNode;
3301+ public:
3302+ TCreateBackupCollectionNode (
3303+ TPosition pos,
3304+ const TString& objectId,
3305+ const TCreateBackupCollectionParameters& params,
3306+ const TObjectOperatorContext& context)
3307+ : TBase(pos, objectId, context)
3308+ , Params(params)
3309+ {}
3310+
3311+ virtual INode::TPtr FillOptions (TContext& ctx, INode::TPtr options) const final {
3312+ options->Add (Q (Y (Q (" mode" ), Q (" create" ))));
3313+
3314+ auto settings = Y ();
3315+ for (auto & [key, value] : Params.Settings ) {
3316+ settings->Add (Q (Y (BuildQuotedAtom (Pos, key), value.Build ())));
3317+ }
3318+ options->Add (Q (Y (Q (" settings" ), Q (settings))));
3319+
3320+ auto entries = Y ();
3321+ if (Params.Database ) {
3322+ entries->Add (Q (Y (Q (Y (Q (" type" ), Q (" database" ))))));
3323+ }
3324+ for (auto & table : Params.Tables ) {
3325+ auto path = ctx.GetPrefixedPath (ServiceId, Cluster, table);
3326+ entries->Add (Q (Y (Q (Y (Q (" type" ), Q (" table" ))), Q (Y (Q (" path" ), path)))));
3327+ }
3328+ options->Add (Q (Y (Q (" entries" ), Q (entries))));
3329+
3330+ return options;
3331+ }
3332+
3333+ TPtr DoClone () const final {
3334+ return {};
3335+ }
3336+
3337+ private:
3338+ TCreateBackupCollectionParameters Params;
3339+ };
3340+
3341+ class TAlterBackupCollectionNode
3342+ : public TBaseBackupCollectionNode
3343+ {
3344+ using TBase = TBaseBackupCollectionNode;
3345+ public:
3346+ TAlterBackupCollectionNode (
3347+ TPosition pos,
3348+ const TString& objectId,
3349+ const TAlterBackupCollectionParameters& params,
3350+ const TObjectOperatorContext& context)
3351+ : TBase(pos, objectId, context)
3352+ , Params(params)
3353+ {}
3354+
3355+ virtual INode::TPtr FillOptions (TContext& ctx, INode::TPtr options) const final {
3356+ options->Add (Q (Y (Q (" mode" ), Q (" alter" ))));
3357+
3358+ auto settings = Y ();
3359+ for (auto & [key, value] : Params.Settings ) {
3360+ settings->Add (Q (Y (BuildQuotedAtom (Pos, key), value.Build ())));
3361+ }
3362+ options->Add (Q (Y (Q (" settings" ), Q (settings))));
3363+
3364+ auto resetSettings = Y ();
3365+ for (auto & key : Params.SettingsToReset ) {
3366+ resetSettings->Add (BuildQuotedAtom (Pos, key));
3367+ }
3368+ options->Add (Q (Y (Q (" resetSettings" ), Q (resetSettings))));
3369+
3370+ auto entries = Y ();
3371+ if (Params.Database != TAlterBackupCollectionParameters::EDatabase::Unchanged) {
3372+ entries->Add (Q (Y (Q (Y (Q (" type" ), Q (" database" ))), Q (Y (Q (" action" ), Q (Params.Database == TAlterBackupCollectionParameters::EDatabase::Add ? " add" : " drop" ))))));
3373+ }
3374+ for (auto & table : Params.TablesToAdd ) {
3375+ auto path = ctx.GetPrefixedPath (ServiceId, Cluster, table);
3376+ entries->Add (Q (Y (Q (Y (Q (" type" ), Q (" table" ))), Q (Y (Q (" path" ), path)), Q (Y (Q (" action" ), Q (" add" ))))));
3377+ }
3378+ for (auto & table : Params.TablesToDrop ) {
3379+ auto path = ctx.GetPrefixedPath (ServiceId, Cluster, table);
3380+ entries->Add (Q (Y (Q (Y (Q (" type" ), Q (" table" ))), Q (Y (Q (" path" ), path)), Q (Y (Q (" action" ), Q (" drop" ))))));
3381+ }
3382+ options->Add (Q (Y (Q (" alterEntries" ), Q (entries))));
3383+
3384+ return options;
3385+ }
3386+
3387+ TPtr DoClone () const final {
3388+ return {};
3389+ }
3390+
3391+ private:
3392+ TAlterBackupCollectionParameters Params;
3393+ };
3394+
3395+ class TDropBackupCollectionNode
3396+ : public TBaseBackupCollectionNode
3397+ {
3398+ using TBase = TBaseBackupCollectionNode;
3399+ public:
3400+ TDropBackupCollectionNode (
3401+ TPosition pos,
3402+ const TString& objectId,
3403+ const TDropBackupCollectionParameters&,
3404+ const TObjectOperatorContext& context)
3405+ : TBase(pos, objectId, context)
3406+ {}
3407+
3408+ virtual INode::TPtr FillOptions (TContext&, INode::TPtr options) const final {
3409+ options->Add (Q (Y (Q (" mode" ), Q (" drop" ))));
3410+
3411+ return options;
3412+ }
3413+
3414+ TPtr DoClone () const final {
3415+ return {};
3416+ }
3417+ };
3418+
3419+ TNodePtr BuildCreateBackupCollection (TPosition pos, const TString& id,
3420+ const TCreateBackupCollectionParameters& params,
3421+ const TObjectOperatorContext& context)
3422+ {
3423+ return new TCreateBackupCollectionNode (pos, id, params, context);
3424+ }
3425+
3426+ TNodePtr BuildAlterBackupCollection (TPosition pos, const TString& id,
3427+ const TAlterBackupCollectionParameters& params,
3428+ const TObjectOperatorContext& context)
3429+ {
3430+ return new TAlterBackupCollectionNode (pos, id, params, context);
3431+ }
3432+
3433+ TNodePtr BuildDropBackupCollection (TPosition pos, const TString& id,
3434+ const TDropBackupCollectionParameters& params,
3435+ const TObjectOperatorContext& context)
3436+ {
3437+ return new TDropBackupCollectionNode (pos, id, params, context);
3438+ }
3439+
32623440} // namespace NSQLTranslationV1
0 commit comments