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