001package gudusoft.gsqlparser.stmt;
002
003import gudusoft.gsqlparser.EDbVendor;
004import gudusoft.gsqlparser.ESqlStatementType;
005import gudusoft.gsqlparser.TCustomSqlStatement;
006import gudusoft.gsqlparser.nodes.*;
007
008/**
009 * Statement class for StarRocks SHOW RESOURCE GROUP / SHOW RESOURCE GROUPS.
010 *
011 * Syntax:
012 * SHOW RESOURCE GROUPS [ALL]
013 * SHOW RESOURCE GROUP resource_group_name
014 */
015public class TStarrocksShowResourceGroupStmt extends TCustomSqlStatement {
016
017    private boolean showAll;        // SHOW RESOURCE GROUPS (plural) vs singular
018    private boolean includeAll;     // ALL keyword present
019    private TObjectName resourceGroupName;
020
021    public TStarrocksShowResourceGroupStmt(EDbVendor dbvendor) {
022        super(dbvendor);
023        sqlstatementtype = ESqlStatementType.sststarrocksShowResourceGroup;
024    }
025
026    @Override
027    public int doParseStatement(TCustomSqlStatement psql) {
028        if (rootNode == null) return -1;
029
030        super.doParseStatement(psql);
031
032        TShowResourceGroupSqlNode node = (TShowResourceGroupSqlNode) rootNode;
033
034        this.showAll = node.isShowAll();
035        this.includeAll = node.isIncludeAll();
036        this.resourceGroupName = node.getResourceGroupName();
037
038        return 0;
039    }
040
041    /**
042     * Returns true if this is SHOW RESOURCE GROUPS (plural) command.
043     * When false, it's SHOW RESOURCE GROUP (singular) with a specific name.
044     */
045    public boolean isShowAll() {
046        return showAll;
047    }
048
049    /**
050     * Returns true if ALL keyword is present (SHOW RESOURCE GROUPS ALL).
051     */
052    public boolean isIncludeAll() {
053        return includeAll;
054    }
055
056    /**
057     * Returns the resource group name for SHOW RESOURCE GROUP name command.
058     * Returns null for SHOW RESOURCE GROUPS command.
059     */
060    public TObjectName getResourceGroupName() {
061        return resourceGroupName;
062    }
063
064    @Override
065    public void accept(TParseTreeVisitor v) {
066        v.preVisit(this);
067        v.postVisit(this);
068    }
069
070    @Override
071    public void acceptChildren(TParseTreeVisitor v) {
072        v.preVisit(this);
073        v.postVisit(this);
074    }
075}