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 * RESTORE SNAPSHOT statement for StarRocks.
011 *
012 * Syntax (v3.4.0+):
013 * RESTORE SNAPSHOT [<db_name>.]<snapshot_name>
014 * FROM <repository_name>
015 * [DATABASE <db_name_in_snapshot> [AS <target_db>]]
016 * [ON ( restore_object [, ...] )]
017 * [PROPERTIES ("key"="value" [, ...])]
018 *
019 * This statement restores database objects from a repository backup.
020 * The operation is asynchronous - use SHOW RESTORE to monitor progress.
021 */
022public class TStarrocksRestoreStmt extends TCustomSqlStatement {
023
024    // SNAPSHOT name (may be qualified as db.snapshot_name)
025    private TObjectName snapshotName;
026
027    // FROM clause - repository name
028    private TObjectName repositoryName;
029
030    // DATABASE clause - source database name in snapshot
031    private TObjectName sourceDatabaseName;
032
033    // DATABASE ... AS clause - target database name for restore
034    private TObjectName targetDatabaseName;
035
036    // Has explicit DATABASE keyword
037    private boolean hasDatabase;
038
039    // Flags for ALL object types
040    private boolean allTables;
041    private boolean allMaterializedViews;
042    private boolean allViews;
043    private boolean allFunctions;
044
045    // Object type for ON clause (tables, materialized_views, views, functions)
046    private String objectType;
047
048    // List of specific objects (tables, views, mvs, functions)
049    private TObjectNameList objectList;
050
051    // Alias for object list (AS clause)
052    private TObjectName objectAlias;
053
054    // Table name for partition restore
055    private TObjectName partitionTableName;
056
057    // Partition list for specific table restore
058    private TObjectNameList partitionList;
059
060    // Alias for partition table (AS clause)
061    private TObjectName partitionTableAlias;
062
063    // PROPERTIES clause
064    private TPTNodeList<TFlinkTableProperty> properties;
065
066    public TStarrocksRestoreStmt(EDbVendor dbvendor) {
067        super(dbvendor);
068        sqlstatementtype = ESqlStatementType.sststarrocksRestore;
069    }
070
071    // Getters
072    public TObjectName getSnapshotName() {
073        return snapshotName;
074    }
075
076    public TObjectName getRepositoryName() {
077        return repositoryName;
078    }
079
080    public TObjectName getSourceDatabaseName() {
081        return sourceDatabaseName;
082    }
083
084    public TObjectName getTargetDatabaseName() {
085        return targetDatabaseName;
086    }
087
088    public boolean hasDatabase() {
089        return hasDatabase;
090    }
091
092    public boolean isAllTables() {
093        return allTables;
094    }
095
096    public boolean isAllMaterializedViews() {
097        return allMaterializedViews;
098    }
099
100    public boolean isAllViews() {
101        return allViews;
102    }
103
104    public boolean isAllFunctions() {
105        return allFunctions;
106    }
107
108    public String getObjectType() {
109        return objectType;
110    }
111
112    public TObjectNameList getObjectList() {
113        return objectList;
114    }
115
116    public TObjectName getObjectAlias() {
117        return objectAlias;
118    }
119
120    public TObjectName getPartitionTableName() {
121        return partitionTableName;
122    }
123
124    public TObjectNameList getPartitionList() {
125        return partitionList;
126    }
127
128    public TObjectName getPartitionTableAlias() {
129        return partitionTableAlias;
130    }
131
132    public TPTNodeList<TFlinkTableProperty> getProperties() {
133        return properties;
134    }
135
136    @Override
137    public int doParseStatement(TCustomSqlStatement psql) {
138        if (rootNode == null) return -1;
139        super.doParseStatement(psql);
140
141        TRestoreSnapshotSqlNode node = (TRestoreSnapshotSqlNode) rootNode;
142
143        this.snapshotName = node.getSnapshotName();
144        this.repositoryName = node.getRepositoryName();
145        this.sourceDatabaseName = node.getSourceDatabaseName();
146        this.targetDatabaseName = node.getTargetDatabaseName();
147        this.hasDatabase = node.hasDatabase();
148        this.allTables = node.isAllTables();
149        this.allMaterializedViews = node.isAllMaterializedViews();
150        this.allViews = node.isAllViews();
151        this.allFunctions = node.isAllFunctions();
152        this.objectType = node.getObjectType();
153        this.objectList = node.getObjectList();
154        this.objectAlias = node.getObjectAlias();
155        this.partitionTableName = node.getPartitionTableName();
156        this.partitionList = node.getPartitionList();
157        this.partitionTableAlias = node.getPartitionTableAlias();
158        this.properties = node.getProperties();
159
160        return 0;
161    }
162
163    @Override
164    public void accept(TParseTreeVisitor v) {
165        v.preVisit(this);
166        v.postVisit(this);
167    }
168
169    @Override
170    public void acceptChildren(TParseTreeVisitor v) {
171        v.preVisit(this);
172        v.postVisit(this);
173    }
174}