001package gudusoft.gsqlparser.stmt;
002
003import gudusoft.gsqlparser.EDbVendor;
004import gudusoft.gsqlparser.ESqlStatementType;
005import gudusoft.gsqlparser.TCustomSqlStatement;
006import gudusoft.gsqlparser.TSourceToken;
007import gudusoft.gsqlparser.nodes.*;
008import gudusoft.gsqlparser.nodes.flink.TFlinkTableProperty;
009
010/**
011 * CREATE STORAGE VOLUME statement for StarRocks.
012 *
013 * Syntax:
014 * CREATE STORAGE VOLUME [IF NOT EXISTS] <storage_volume_name>
015 * TYPE = { S3 | HDFS | AZBLOB | ADLS2 | GS }
016 * LOCATIONS = ('<remote_storage_path>')
017 * [ COMMENT '<comment_string>' ]
018 * PROPERTIES ("key" = "value",...)
019 *
020 * This statement creates a storage volume for external data sources in
021 * shared-data StarRocks clusters.
022 */
023public class TStarrocksCreateStorageVolumeStmt extends TCustomSqlStatement {
024
025    // Storage volume name
026    private TObjectName volumeName;
027
028    // IF NOT EXISTS flag
029    private boolean ifNotExists;
030
031    // Storage type (S3, HDFS, AZBLOB, ADLS2, GS)
032    private String storageType;
033
034    // Locations list
035    private TPTNodeList<TSourceToken> locationsList;
036
037    // Optional comment
038    private String comment;
039
040    // Properties
041    private TPTNodeList<TFlinkTableProperty> properties;
042
043    public TStarrocksCreateStorageVolumeStmt(EDbVendor dbvendor) {
044        super(dbvendor);
045        sqlstatementtype = ESqlStatementType.sststarrocksCreateStorageVolume;
046    }
047
048    // Getters
049    public TObjectName getVolumeName() {
050        return volumeName;
051    }
052
053    public boolean isIfNotExists() {
054        return ifNotExists;
055    }
056
057    public String getStorageType() {
058        return storageType;
059    }
060
061    public TPTNodeList<TSourceToken> getLocationsList() {
062        return locationsList;
063    }
064
065    public String getComment() {
066        return comment;
067    }
068
069    public TPTNodeList<TFlinkTableProperty> getProperties() {
070        return properties;
071    }
072
073    @Override
074    public int doParseStatement(TCustomSqlStatement psql) {
075        if (rootNode == null) return -1;
076        super.doParseStatement(psql);
077
078        TCreateStorageVolumeSqlNode node = (TCreateStorageVolumeSqlNode) rootNode;
079
080        this.volumeName = node.getVolumeName();
081        this.ifNotExists = node.isIfNotExists();
082
083        if (node.getStorageType() != null) {
084            this.storageType = node.getStorageType().toString();
085        }
086
087        this.locationsList = node.getLocationsList();
088
089        if (node.getComment() != null) {
090            this.comment = node.getComment().toString();
091        }
092
093        this.properties = node.getProperties();
094
095        return 0;
096    }
097
098    @Override
099    public void accept(TParseTreeVisitor v) {
100        v.preVisit(this);
101        v.postVisit(this);
102    }
103
104    @Override
105    public void acceptChildren(TParseTreeVisitor v) {
106        v.preVisit(this);
107        v.postVisit(this);
108    }
109}