001package gudusoft.gsqlparser.stmt;
002
003
004import gudusoft.gsqlparser.EDbObjectType;
005import gudusoft.gsqlparser.EDbVendor;
006import gudusoft.gsqlparser.ESqlStatementType;
007import gudusoft.gsqlparser.TCustomSqlStatement;
008import gudusoft.gsqlparser.nodes.*;
009
010import java.util.ArrayList;
011
012public class TDropFunctionStmt extends TCustomSqlStatement {
013
014    public TDropFunctionStmt(EDbVendor dbvendor) {
015        super(dbvendor);
016        sqlstatementtype = ESqlStatementType.sstdropfunction;
017    }
018
019    private boolean ifExists = false;
020
021    public boolean isIfExists() {
022        return ifExists;
023    }
024
025    private TObjectName functionName = null;
026
027    public TObjectName getFunctionName() {
028        return functionName;
029    }
030
031    // StarRocks-specific: DROP [GLOBAL] FUNCTION name(arg_types)
032    private boolean starrocksGlobal = false;
033    private TPTNodeList starrocksArgTypes = null;
034
035    public boolean isStarrocksGlobal() {
036        return starrocksGlobal;
037    }
038
039    public TPTNodeList getStarrocksArgTypes() {
040        return starrocksArgTypes;
041    }
042
043    public int doParseStatement(TCustomSqlStatement psql) {
044        if (rootNode == null) return -1;
045        super.doParseStatement(psql);
046        if (rootNode instanceof TDummy){
047            TDummy node = (TDummy) rootNode;
048            this.functionName = (TObjectName) node.node1;
049            if (this.functionName != null){
050                this.functionName.setDbObjectType(EDbObjectType.function);
051            }
052            this.ifExists = node.ifExists;
053        }else if (rootNode instanceof TDropFunctionSqlNode){
054            // sql server,presto
055            TDropFunctionSqlNode sqlNode = (TDropFunctionSqlNode)rootNode;
056            if (sqlNode.getFunctionNameList() != null){
057                this.functionName = sqlNode.getFunctionNameList().getObjectName(0);
058            }else{
059                this.functionName = sqlNode.getFunctionName();
060            }
061            // postgresql
062            functions = sqlNode.getFunctions();
063            if (functions != null){
064                this.functionName = functions.get(0).getFunctionName();
065            }
066
067            if (this.functionName != null){
068                this.functionName.setDbObjectType(EDbObjectType.function);
069            }
070
071            // StarRocks-specific fields
072            this.starrocksGlobal = sqlNode.isStarrocksGlobal();
073            this.starrocksArgTypes = sqlNode.getStarrocksArgTypes();
074        }
075
076
077
078        return 0;
079    }
080
081    public ArrayList<TFunctionHeader> getFunctions() {
082        return functions;
083    }
084
085    private ArrayList<TFunctionHeader> functions;
086
087    public void accept(TParseTreeVisitor v) {
088        v.preVisit(this);
089        v.postVisit(this);
090    }
091
092    public void acceptChildren(TParseTreeVisitor v) {
093        v.preVisit(this);
094        v.postVisit(this);
095    }
096}