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 alterIndexOption = node.getAlterIndexOption(); 111 onIndexName = node.getOnIndexName(); 112 if (alterIndexOption != EAlterIndexOption.rename) { 113 tableName = node.getOnIndexName(); 114 if (tableName != null) { 115 analyzeTablename(tableName); 116 } 117 } 118 partitionSpec = node.getPartitionSpec(); 119 indexProperties = node.getIndexProperties(); 120 alterIndexOption = node.getAlterIndexOption(); 121 tablespaceName = node.getTablespaceName(); 122 if (tablespaceName != null){ 123 tablespaceName.setDbObjectType(EDbObjectType.tablespace); 124 } 125 partitionName = node.getPartitionName(); 126 if (partitionName != null){ 127 partitionName.setDbObjectType(EDbObjectType.partition); 128 } 129 newIndexName = node.getNewIndexName(); 130 if (newIndexName != null){ 131 newIndexName.setDbObjectType(EDbObjectType.index); 132 } 133 return 0; 134 } 135 136 public void accept(TParseTreeVisitor v){ 137 v.preVisit(this); 138 v.postVisit(this); 139 } 140 141 public void setOnIndexName(TObjectName onIndexName) { 142 this.onIndexName = onIndexName; 143 } 144 145 public void setAlterIndexOption(EAlterIndexOption alterIndexOption) { 146 this.alterIndexOption = alterIndexOption; 147 } 148 149 public void setIndexProperties(TPTNodeList<THiveKeyValueProperty> indexProperties) { 150 this.indexProperties = indexProperties; 151 } 152 153 public void setPartitionSpec(TPartitionExtensionClause partitionSpec) { 154 this.partitionSpec = partitionSpec; 155 } 156 157 public void setIndexName(TObjectName indexName) { 158 this.indexName = indexName; 159 } 160 161 public void acceptChildren(TParseTreeVisitor v){ 162 v.preVisit(this); 163 v.postVisit(this); 164 } 165 166}