001package gudusoft.gsqlparser.stmt; 002 003import gudusoft.gsqlparser.*; 004import gudusoft.gsqlparser.nodes.*; 005import gudusoft.gsqlparser.nodes.couchbase.TIndexKeyTerm; 006import gudusoft.gsqlparser.nodes.couchbase.TKeyspaceRef; 007import gudusoft.gsqlparser.nodes.hive.THiveIndexProperties; 008import gudusoft.gsqlparser.nodes.hive.THiveRowFormat; 009import gudusoft.gsqlparser.nodes.hive.THiveTableFileFormat; 010import gudusoft.gsqlparser.nodes.hive.THiveTableProperties; 011 012/** 013 * create an index. 014 */ 015public class TCreateIndexSqlStatement extends TCustomSqlStatement { 016 017 private TWhereClause whereCondition; 018 019 public void setWhereCondition(TWhereClause whereCondition) { 020 this.whereCondition = whereCondition; 021 } 022 023 public TWhereClause getWhereCondition() { 024 return whereCondition; 025 } 026 027 private TExpression filterPredicate; 028 029 public void setFilterPredicate(TExpression filterPredicate) { 030 this.filterPredicate = filterPredicate; 031 } 032 033 public TExpression getFilterPredicate() { 034 035 return filterPredicate; 036 } 037 038 public TObjectName getAsTypeName() { 039 return asTypeName; 040 } 041 042 public TCreateIndexSqlNode getCreateIndexNode() { 043 return createIndexNode; 044 } 045 046 public boolean isDeferredRebuildIndex() { 047 return deferredRebuildIndex; 048 } 049 050 public THiveIndexProperties getIndexProperties() { 051 return indexProperties; 052 } 053 054 public TObjectName getIndexComment() { 055 return indexComment; 056 } 057 058 public TObjectName getInTableName() { 059 return inTableName; 060 } 061 062 public THiveTableFileFormat getTableFileFormat() { 063 return tableFileFormat; 064 } 065 066 public TObjectName getTableLocation() { 067 return tableLocation; 068 } 069 070 public THiveTableProperties getTableProperties() { 071 return tableProperties; 072 } 073 074 public THiveRowFormat getTableRowFormat() { 075 return tableRowFormat; 076 } 077 078 private TObjectName asTypeName; //hive 079 private boolean deferredRebuildIndex; 080 private THiveIndexProperties indexProperties; 081 private TObjectName inTableName; 082 private THiveRowFormat tableRowFormat; 083 private THiveTableFileFormat tableFileFormat; 084 private TObjectName tableLocation; 085 private THiveTableProperties tableProperties; 086 private TObjectName indexComment; 087 private boolean isClustered = false; 088 private boolean isNonClustered = false; 089 090 private TObjectName tableName; 091 092 public void setTableName(TObjectName tableName) { 093 this.tableName = tableName; 094 } 095 096 public void setColumnNameList(TOrderByItemList columnNameList) { 097 this.columnNameList = columnNameList; 098 } 099 100 private TOrderByItemList columnNameList; 101 102 public void setClustered(boolean isClustered) { 103 this.isClustered = isClustered; 104 } 105 106 public void setNonClustered(boolean isNonClustered) { 107 this.isNonClustered = isNonClustered; 108 } 109 110 public boolean isClustered() { 111 112 return isClustered; 113 } 114 115 public boolean isNonClustered() { 116 return isNonClustered; 117 } 118 119 public TCreateIndexSqlStatement(EDbVendor dbvendor) { 120 super(dbvendor); 121 sqlstatementtype = ESqlStatementType.sstcreateindex; 122 } 123 124 void buildsql() { 125 } 126 127 void clear() { 128 } 129 130 String getasprettytext() { 131 return ""; 132 } 133 134 void iterate(TVisitorAbs pvisitor) { 135 } 136 137 public int doParseStatement(TCustomSqlStatement psql) { 138 if (rootNode == null) return -1; 139 createIndexNode = (TCreateIndexSqlNode)rootNode; 140 super.doParseStatement(psql); 141 this.indexName = createIndexNode.getIndexName(); 142 if (getSqlEnv().getDefaultCatalogName() != null){ 143 if (indexName.getDatabaseToken() == null){ 144 indexName.setDatabaseToken(new TSourceToken(getSqlEnv().getDefaultCatalogName())); 145 } 146 } 147 tableName = createIndexNode.getTableName(); 148 // tableName.setDbObjectType(EDbObjectType.table); 149 columnNameList = createIndexNode.getColumnNameList(); 150 151 if (tableName != null){ 152 TTable lcTable = new TTable(tableName); 153 lcTable.setPropertyFromObjectName(tableName, ETableEffectType.tetCreateIndexRef); 154 this.addToTables(lcTable); 155 156 if (columnNameList != null){ 157 for(int i=0;i<columnNameList.size();i++){ 158 if (columnNameList.getOrderByItem(i).getSortKey().getExpressionType() == EExpressionType.simple_object_name_t){ 159 lcTable.getLinkedColumns().addObjectName(columnNameList.getOrderByItem(i).getSortKey().getObjectOperand()); 160 } 161 162 } 163 } 164 } 165 166 this.asTypeName = createIndexNode.getAsTypeName(); 167 this.deferredRebuildIndex = createIndexNode.isDeferredRebuildIndex(); 168 this.indexProperties = createIndexNode.getIndexProperties(); 169 this.inTableName = createIndexNode.getInTableName(); 170 if (inTableName != null){ 171 inTableName.setObjectType(TObjectName.ttobjTable); 172 } 173 this.tableRowFormat = createIndexNode.getTableRowFormat(); 174 this.tableFileFormat = createIndexNode.getTableFileFormat(); 175 this.tableLocation = createIndexNode.getTableLocation(); 176 this.tableProperties = createIndexNode.getTableProperties(); 177 this.indexComment = createIndexNode.getIndexComment(); 178 if (createIndexNode.getTableName() != null){ 179 createIndexNode.getTableName().setObjectType(TObjectName.ttobjTable); 180 } 181 182 indexType = createIndexNode.getIndexType(); 183 isClustered = createIndexNode.isClustered(); 184 isNonClustered = createIndexNode.isNonClustered(); 185 186 filterPredicate = createIndexNode.getFilterPredicate(); 187 188 if (createIndexNode.getOptionList() != null) { 189 for(int i=0;i<createIndexNode.getOptionList().size();i++){ 190 TDummy dummy = createIndexNode.getOptionList().getDummyItem(0); 191 switch (dummy.int1){ 192 case 1: 193 includeColumns = (TObjectNameList)dummy.node1; 194 break; 195 case 2: 196 break; 197 case 3: 198 filegroupOrPartitionSchemeName = (TObjectName)dummy.node1; 199 if (dummy.list1 != null){ 200 partitionSchemeColumns = (TObjectNameList)dummy.list1; 201 } 202 break; 203 default: 204 break; 205 } 206 } 207 } 208 209 //couchbase 210 keyspaceRef = createIndexNode.getKeyspaceRef(); 211 indexWith = createIndexNode.getIndexWith(); 212 indexWhere = createIndexNode.getIndexWhere(); 213 indexTerms = createIndexNode.getIndexTerms(); 214 indexPartition = createIndexNode.getIndexPartition(); 215 whereCondition = createIndexNode.getWhereCondition(); 216 if (whereCondition != null){ 217 whereCondition.doParse(this,ESqlClause.where); 218 } 219 220 return 0; 221 } 222 223 private TObjectName filegroupOrPartitionSchemeName; 224 private TObjectNameList partitionSchemeColumns; 225 226 public void setFilegroupOrPartitionSchemeName(TObjectName filegroupOrPartitionSchemeName) { 227 this.filegroupOrPartitionSchemeName = filegroupOrPartitionSchemeName; 228 } 229 230 public void setPartitionSchemeColumns(TObjectNameList partitionSchemeColumns) { 231 this.partitionSchemeColumns = partitionSchemeColumns; 232 } 233 234 public TObjectName getFilegroupOrPartitionSchemeName() { 235 236 return filegroupOrPartitionSchemeName; 237 } 238 239 public TObjectNameList getPartitionSchemeColumns() { 240 return partitionSchemeColumns; 241 } 242 243 private TObjectNameList includeColumns; 244 245 public void setIncludeColumns(TObjectNameList includeColumns) { 246 this.includeColumns = includeColumns; 247 } 248 249 public TObjectNameList getIncludeColumns() { 250 251 return includeColumns; 252 } 253 254 private TObjectName indexName = null; 255 256 private TCreateIndexSqlNode createIndexNode; 257 258 private EIndexType indexType; 259 260 public void setIndexType(EIndexType indexType) { 261 this.indexType = indexType; 262 } 263 264 public EIndexType getIndexType(){ 265 return indexType; 266 //return createIndexNode.getIndexType(); 267 } 268 269 public TObjectName getTableName(){ 270 return tableName; //createIndexNode.getTableName(); 271 } 272 273 public TOrderByItemList getColumnNameList(){ 274 return columnNameList; //createIndexNode.getColumnNameList(); 275 } 276 277 /** 278 * 279 * @return the name of the index to be created. 280 */ 281 public TObjectName getIndexName() { 282 return indexName; 283 } 284 285 public void accept(TParseTreeVisitor v){ 286 v.preVisit(this); 287 v.postVisit(this); 288 } 289 290 public void acceptChildren(TParseTreeVisitor v){ 291 v.preVisit(this); 292 v.postVisit(this); 293 } 294 295 public void setAsTypeName(TObjectName asTypeName) { 296 this.asTypeName = asTypeName; 297 } 298 299 public void setDeferredRebuildIndex(boolean deferredRebuildIndex) { 300 this.deferredRebuildIndex = deferredRebuildIndex; 301 } 302 303 public void setIndexProperties(THiveIndexProperties indexProperties) { 304 this.indexProperties = indexProperties; 305 } 306 307 public void setInTableName(TObjectName inTableName) { 308 this.inTableName = inTableName; 309 } 310 311 public void setTableRowFormat(THiveRowFormat tableRowFormat) { 312 this.tableRowFormat = tableRowFormat; 313 } 314 315 public void setTableFileFormat(THiveTableFileFormat tableFileFormat) { 316 this.tableFileFormat = tableFileFormat; 317 } 318 319 public void setTableLocation(TObjectName tableLocation) { 320 this.tableLocation = tableLocation; 321 } 322 323 public void setTableProperties(THiveTableProperties tableProperties) { 324 this.tableProperties = tableProperties; 325 } 326 327 public void setIndexComment(TObjectName indexComment) { 328 this.indexComment = indexComment; 329 } 330 331 public void setIndexName(TObjectName indexName) { 332 this.indexName = indexName; 333 } 334 335 336 private TKeyspaceRef keyspaceRef;//couchbase 337 338 public void setKeyspaceRef(TKeyspaceRef keyspaceRef) { 339 this.keyspaceRef = keyspaceRef; 340 } 341 342 public TKeyspaceRef getKeyspaceRef() { 343 344 return keyspaceRef; 345 } 346 347 private TPTNodeList<TIndexKeyTerm> indexTerms; 348 349 public void setIndexTerms(TPTNodeList<TIndexKeyTerm> indexTerms) { 350 this.indexTerms = indexTerms; 351 } 352 353 public TPTNodeList<TIndexKeyTerm> getIndexTerms() { 354 355 return indexTerms; 356 } 357 358 private TExpressionList indexPartition; 359 360 public void setIndexPartition(TExpressionList indexPartition) { 361 this.indexPartition = indexPartition; 362 } 363 364 public TExpressionList getIndexPartition() { 365 366 return indexPartition; 367 } 368 369 private TExpression indexWhere; 370 371 public void setIndexWhere(TExpression indexWhere) { 372 this.indexWhere = indexWhere; 373 } 374 375 public TExpression getIndexWhere() { 376 377 return indexWhere; 378 } 379 380 private TExpression indexWith; 381 382 public void setIndexWith(TExpression indexWith) { 383 this.indexWith = indexWith; 384 } 385 386 public TExpression getIndexWith() { 387 388 return indexWith; 389 } 390 391}