001package gudusoft.gsqlparser.stmt;
002
003import gudusoft.gsqlparser.EAlterIndexOption;
004import gudusoft.gsqlparser.EDbObjectType;
005import gudusoft.gsqlparser.EDbVendor;
006import gudusoft.gsqlparser.ESqlStatementType;
007import gudusoft.gsqlparser.TCustomSqlStatement;
008import gudusoft.gsqlparser.nodes.*;
009import gudusoft.gsqlparser.nodes.hive.THiveKeyValueProperty;
010
011/**
012 * SQL alter index statement.
013 *<br>{@link #getIndexName()} returns the name of index.
014 *
015 */
016public class TAlterIndexStmt extends TCustomSqlStatement {
017
018    private TObjectName onIndexName;
019    private EAlterIndexOption alterIndexOption;
020    private TPTNodeList<THiveKeyValueProperty> indexProperties;
021    private TPartitionExtensionClause partitionSpec;
022
023    private TObjectName indexName;
024    private TObjectName tableName;
025
026    private TObjectName tablespaceName;
027    private TObjectName partitionName;
028
029    private TObjectName newIndexName;
030
031    public TObjectName getTablespaceName() {
032        return tablespaceName;
033    }
034
035    public TObjectName getPartitionName() {
036        return partitionName;
037    }
038
039    public TObjectName getNewIndexName() {
040        return newIndexName;
041    }
042
043    /**
044     * The name of the table or view associated with the index
045     *
046     * @return The name of the table or view associated with the index
047     */
048    public TObjectName getTableName() {
049        return tableName;
050    }
051
052    /**
053     * Name of the index
054     * @return Name of the index
055     */
056    public TObjectName getIndexName() {
057        return indexName;
058    }
059
060    public TAlterIndexStmt(EDbVendor dbvendor) {
061        super(dbvendor);
062        sqlstatementtype = ESqlStatementType.sstalterindex;
063    }
064
065    /**
066     * @deprecated  since 1.9.7.4, use {@link  #getTableName()} instead.
067     * The name of the table or view associated with the index
068     *
069     * @return The name of the table or view associated with the index
070     */
071    public TObjectName getOnIndexName() {
072        return onIndexName;
073    }
074
075    /**
076     * Various option about how this index is altered such as rebuild, disable and etc.
077     * <br>
078     * Always check this value before fetching other values of this class.
079     *
080     * @return various option about how this index is altered such as rebuild, disable and etc.
081     */
082    public EAlterIndexOption getAlterIndexOption() {
083        return alterIndexOption;
084    }
085
086    /**
087     * Hive, index properties of SET IDXPROPERTIES clause
088     *
089     * @return index properties of SET IDXPROPERTIES clause.
090     */
091    public TPTNodeList<THiveKeyValueProperty> getIndexProperties() {
092        return indexProperties;
093    }
094
095    /**
096     * Hive, partition spec of {@link #getTableName}
097     *
098     * @return partition spec
099     */
100    public TPartitionExtensionClause getPartitionSpec() {
101        return partitionSpec;
102    }
103
104    public int doParseStatement(TCustomSqlStatement psql) {
105        if (rootNode == null) return -1;
106        super.doParseStatement(psql);
107
108        TAlterIndexSqlNode node = (TAlterIndexSqlNode)rootNode;
109        indexName = node.getIndexName();
110        onIndexName = node.getOnIndexName();
111        tableName = node.getOnIndexName();
112        if (tableName != null){
113            analyzeTablename(tableName);
114        }
115        partitionSpec = node.getPartitionSpec();
116        indexProperties = node.getIndexProperties();
117        alterIndexOption = node.getAlterIndexOption();
118        tablespaceName = node.getTablespaceName();
119        if (tablespaceName != null){
120            tablespaceName.setDbObjectType(EDbObjectType.tablespace);
121        }
122        partitionName = node.getPartitionName();
123        if (partitionName != null){
124            partitionName.setDbObjectType(EDbObjectType.partition);
125        }
126        newIndexName = node.getNewIndexName();
127        if (newIndexName != null){
128            newIndexName.setDbObjectType(EDbObjectType.index);
129        }
130        return 0;
131    }
132
133    public void accept(TParseTreeVisitor v){
134        v.preVisit(this);
135        v.postVisit(this);
136    }
137
138    public void setOnIndexName(TObjectName onIndexName) {
139        this.onIndexName = onIndexName;
140    }
141
142    public void setAlterIndexOption(EAlterIndexOption alterIndexOption) {
143        this.alterIndexOption = alterIndexOption;
144    }
145
146    public void setIndexProperties(TPTNodeList<THiveKeyValueProperty> indexProperties) {
147        this.indexProperties = indexProperties;
148    }
149
150    public void setPartitionSpec(TPartitionExtensionClause partitionSpec) {
151        this.partitionSpec = partitionSpec;
152    }
153
154    public void setIndexName(TObjectName indexName) {
155        this.indexName = indexName;
156    }
157
158    public void acceptChildren(TParseTreeVisitor v){
159        v.preVisit(this);
160        v.postVisit(this);
161    }
162
163}