001package gudusoft.gsqlparser.stmt;
002
003import gudusoft.gsqlparser.EDbVendor;
004import gudusoft.gsqlparser.ESqlStatementType;
005import gudusoft.gsqlparser.TCustomSqlStatement;
006import gudusoft.gsqlparser.nodes.*;
007import gudusoft.gsqlparser.nodes.flink.TFlinkTableProperty;
008
009/**
010 * BACKUP SNAPSHOT statement for StarRocks.
011 *
012 * Syntax (v3.4.0+):
013 * BACKUP [DATABASE <db_name>] SNAPSHOT [<db_name>.]<snapshot_name>
014 * TO <repository_name>
015 * [ON ( backup_object [, ...] )]
016 * [PROPERTIES ("key"="value" [, ...])]
017 *
018 * This statement creates a backup of database objects to a repository.
019 * The operation is asynchronous - use SHOW BACKUP to monitor progress.
020 */
021public class TStarrocksBackupStmt extends TCustomSqlStatement {
022
023    // DATABASE clause - optional database name for explicit DATABASE keyword
024    private TObjectName databaseName;
025
026    // Has explicit DATABASE keyword
027    private boolean hasDatabase;
028
029    // SNAPSHOT name (may be qualified as db.snapshot_name)
030    private TObjectName snapshotName;
031
032    // TO clause - repository name
033    private TObjectName repositoryName;
034
035    // Flags for ALL object types
036    private boolean allTables;
037    private boolean allMaterializedViews;
038    private boolean allViews;
039    private boolean allFunctions;
040
041    // Object type for ON clause (tables, materialized_views, views, functions)
042    private String objectType;
043
044    // List of specific objects (tables, views, mvs, functions)
045    private TObjectNameList objectList;
046
047    // Table name for partition backup
048    private TObjectName partitionTableName;
049
050    // Partition list for specific table backup
051    private TObjectNameList partitionList;
052
053    // PROPERTIES clause
054    private TPTNodeList<TFlinkTableProperty> properties;
055
056    public TStarrocksBackupStmt(EDbVendor dbvendor) {
057        super(dbvendor);
058        sqlstatementtype = ESqlStatementType.sststarrocksBackup;
059    }
060
061    // Getters
062    public TObjectName getDatabaseName() {
063        return databaseName;
064    }
065
066    public boolean hasDatabase() {
067        return hasDatabase;
068    }
069
070    public TObjectName getSnapshotName() {
071        return snapshotName;
072    }
073
074    public TObjectName getRepositoryName() {
075        return repositoryName;
076    }
077
078    public boolean isAllTables() {
079        return allTables;
080    }
081
082    public boolean isAllMaterializedViews() {
083        return allMaterializedViews;
084    }
085
086    public boolean isAllViews() {
087        return allViews;
088    }
089
090    public boolean isAllFunctions() {
091        return allFunctions;
092    }
093
094    public String getObjectType() {
095        return objectType;
096    }
097
098    public TObjectNameList getObjectList() {
099        return objectList;
100    }
101
102    public TObjectName getPartitionTableName() {
103        return partitionTableName;
104    }
105
106    public TObjectNameList getPartitionList() {
107        return partitionList;
108    }
109
110    public TPTNodeList<TFlinkTableProperty> getProperties() {
111        return properties;
112    }
113
114    @Override
115    public int doParseStatement(TCustomSqlStatement psql) {
116        if (rootNode == null) return -1;
117        super.doParseStatement(psql);
118
119        TBackupSnapshotSqlNode node = (TBackupSnapshotSqlNode) rootNode;
120
121        this.databaseName = node.getDatabaseName();
122        this.hasDatabase = node.hasDatabase();
123        this.snapshotName = node.getSnapshotName();
124        this.repositoryName = node.getRepositoryName();
125        this.allTables = node.isAllTables();
126        this.allMaterializedViews = node.isAllMaterializedViews();
127        this.allViews = node.isAllViews();
128        this.allFunctions = node.isAllFunctions();
129        this.objectType = node.getObjectType();
130        this.objectList = node.getObjectList();
131        this.partitionTableName = node.getPartitionTableName();
132        this.partitionList = node.getPartitionList();
133        this.properties = node.getProperties();
134
135        return 0;
136    }
137
138    @Override
139    public void accept(TParseTreeVisitor v) {
140        v.preVisit(this);
141        v.postVisit(this);
142    }
143
144    @Override
145    public void acceptChildren(TParseTreeVisitor v) {
146        v.preVisit(this);
147        v.postVisit(this);
148    }
149}