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            this.ifExists = sqlNode.isIfExists();
057            if (sqlNode.getFunctionNameList() != null){
058                this.functionName = sqlNode.getFunctionNameList().getObjectName(0);
059            }else{
060                this.functionName = sqlNode.getFunctionName();
061            }
062            // postgresql
063            functions = sqlNode.getFunctions();
064            if (functions != null){
065                this.functionName = functions.get(0).getFunctionName();
066            }
067
068            if (this.functionName != null){
069                this.functionName.setDbObjectType(EDbObjectType.function);
070            }
071
072            // StarRocks-specific fields
073            this.starrocksGlobal = sqlNode.isStarrocksGlobal();
074            this.starrocksArgTypes = sqlNode.getStarrocksArgTypes();
075        }
076
077
078
079        return 0;
080    }
081
082    public ArrayList<TFunctionHeader> getFunctions() {
083        return functions;
084    }
085
086    private ArrayList<TFunctionHeader> functions;
087
088    public void accept(TParseTreeVisitor v) {
089        v.preVisit(this);
090        v.postVisit(this);
091    }
092
093    public void acceptChildren(TParseTreeVisitor v) {
094        v.preVisit(this);
095        v.postVisit(this);
096    }
097}