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