diff --git a/fe/fe-core/src/main/java/com/starrocks/lake/StarOSAgent.java b/fe/fe-core/src/main/java/com/starrocks/lake/StarOSAgent.java index 86b09104e4162..ba3fadbd910cb 100644 --- a/fe/fe-core/src/main/java/com/starrocks/lake/StarOSAgent.java +++ b/fe/fe-core/src/main/java/com/starrocks/lake/StarOSAgent.java @@ -734,7 +734,7 @@ private void tryRemovePreviousWorkerGroup(long workerGroupId) { } } - public long createWorkerGroup(String size) throws DdlException { + public long createWorkerGroup(String size, int replicaNumber) throws DdlException { prepare(); // size should be x0, x1, x2, x4... @@ -744,7 +744,7 @@ public long createWorkerGroup(String size) throws DdlException { WorkerGroupDetailInfo result = null; try { result = client.createWorkerGroup(serviceId, owner, spec, Collections.emptyMap(), - Collections.emptyMap()); + Collections.emptyMap(), replicaNumber); } catch (StarClientException e) { LOG.warn("Failed to create worker group. error: {}", e.getMessage()); throw new DdlException("Failed to create worker group. error: " + e.getMessage()); @@ -752,6 +752,16 @@ public long createWorkerGroup(String size) throws DdlException { return result.getGroupId(); } + public void updateWorkerGroup(long workerGroupId, int replicaNumber) throws DdlException { + prepare(); + try { + client.updateWorkerGroup(serviceId, workerGroupId, null, null, replicaNumber); + } catch (StarClientException e) { + LOG.warn("Failed to update worker group. error: {}", e.getMessage()); + throw new DdlException("Failed to update worker group. error: " + e.getMessage()); + } + } + public void deleteWorkerGroup(long groupId) throws DdlException { prepare(); try { diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/DDLStmtExecutor.java b/fe/fe-core/src/main/java/com/starrocks/qe/DDLStmtExecutor.java index 1de93fcd2657b..cbf96b9f8d7ec 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/DDLStmtExecutor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/DDLStmtExecutor.java @@ -137,6 +137,7 @@ import com.starrocks.sql.ast.pipe.AlterPipeStmt; import com.starrocks.sql.ast.pipe.CreatePipeStmt; import com.starrocks.sql.ast.pipe.DropPipeStmt; +import com.starrocks.sql.ast.warehouse.AlterWarehouseStmt; import com.starrocks.sql.ast.warehouse.CreateWarehouseStmt; import com.starrocks.sql.ast.warehouse.DropWarehouseStmt; import com.starrocks.sql.ast.warehouse.ResumeWarehouseStmt; @@ -1174,6 +1175,15 @@ public ShowResultSet visitDropWarehouseStatement(DropWarehouseStmt stmt, Connect }); return null; } + + @Override + public ShowResultSet visitAlterWarehouseStatement(AlterWarehouseStmt stmt, ConnectContext context) { + ErrorReport.wrapWithRuntimeException(() -> { + WarehouseManager warehouseMgr = context.getGlobalStateMgr().getWarehouseMgr(); + warehouseMgr.alterWarehouse(stmt); + }); + return null; + } } } diff --git a/fe/fe-core/src/main/java/com/starrocks/server/WarehouseManager.java b/fe/fe-core/src/main/java/com/starrocks/server/WarehouseManager.java index 3e3183f544bc7..727f9b60a997a 100644 --- a/fe/fe-core/src/main/java/com/starrocks/server/WarehouseManager.java +++ b/fe/fe-core/src/main/java/com/starrocks/server/WarehouseManager.java @@ -33,6 +33,7 @@ import com.starrocks.persist.metablock.SRMetaBlockEOFException; import com.starrocks.persist.metablock.SRMetaBlockException; import com.starrocks.persist.metablock.SRMetaBlockReader; +import com.starrocks.sql.ast.warehouse.AlterWarehouseStmt; import com.starrocks.sql.ast.warehouse.CreateWarehouseStmt; import com.starrocks.sql.ast.warehouse.DropWarehouseStmt; import com.starrocks.sql.ast.warehouse.ResumeWarehouseStmt; @@ -323,6 +324,10 @@ public void resumeWarehouse(ResumeWarehouseStmt stmt) throws DdlException { throw new DdlException("Multi-Warehouse is not implemented"); } + public void alterWarehouse(AlterWarehouseStmt stmt) throws DdlException { + throw new DdlException("Multi-Warehouse is not implemented"); + } + public Set getAllWarehouseNames() { return Sets.newHashSet(DEFAULT_WAREHOUSE_NAME); } diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/Analyzer.java b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/Analyzer.java index 7275406149372..2599d0a0caed8 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/Analyzer.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/Analyzer.java @@ -151,6 +151,7 @@ import com.starrocks.sql.ast.pipe.DescPipeStmt; import com.starrocks.sql.ast.pipe.DropPipeStmt; import com.starrocks.sql.ast.pipe.ShowPipeStmt; +import com.starrocks.sql.ast.warehouse.AlterWarehouseStmt; import com.starrocks.sql.ast.warehouse.CreateWarehouseStmt; import com.starrocks.sql.ast.warehouse.DropWarehouseStmt; import com.starrocks.sql.ast.warehouse.ResumeWarehouseStmt; @@ -1071,5 +1072,11 @@ public Void visitSetWarehouseStatement(SetWarehouseStmt statement, ConnectContex public Void visitShowNodesStatement(ShowNodesStmt statement, ConnectContext context) { return null; } + + @Override + public Void visitAlterWarehouseStatement(AlterWarehouseStmt statement, ConnectContext context) { + WarehouseAnalyzer.analyze(statement, context); + return null; + } } } diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AuthorizerStmtVisitor.java b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AuthorizerStmtVisitor.java index ed34d22ea4c37..9232fc52c39df 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AuthorizerStmtVisitor.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/AuthorizerStmtVisitor.java @@ -213,6 +213,7 @@ import com.starrocks.sql.ast.pipe.DropPipeStmt; import com.starrocks.sql.ast.pipe.PipeName; import com.starrocks.sql.ast.pipe.ShowPipeStmt; +import com.starrocks.sql.ast.warehouse.AlterWarehouseStmt; import com.starrocks.sql.ast.warehouse.CreateWarehouseStmt; import com.starrocks.sql.ast.warehouse.DropWarehouseStmt; import com.starrocks.sql.ast.warehouse.ResumeWarehouseStmt; @@ -2781,4 +2782,17 @@ private void checkWarehouseUsagePrivilege(String warehouseName, ConnectContext c PrivilegeType.USAGE.name(), ObjectType.WAREHOUSE.name(), warehouseName); } } + + @Override + public Void visitAlterWarehouseStatement(AlterWarehouseStmt statement, ConnectContext context) { + try { + Authorizer.checkWarehouseAction(context.getCurrentUserIdentity(), + context.getCurrentRoleIds(), statement.getWarehouseName(), PrivilegeType.ALTER); + } catch (AccessDeniedException e) { + AccessDeniedException.reportAccessDenied(InternalCatalog.DEFAULT_INTERNAL_CATALOG_NAME, + context.getCurrentUserIdentity(), context.getCurrentRoleIds(), + PrivilegeType.ALTER.name(), ObjectType.WAREHOUSE.name(), statement.getWarehouseName()); + } + return null; + } } diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/WarehouseAnalyzer.java b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/WarehouseAnalyzer.java index 238d6163cbe38..afa5005e06262 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/WarehouseAnalyzer.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/analyzer/WarehouseAnalyzer.java @@ -22,6 +22,7 @@ import com.starrocks.sql.ast.AstVisitor; import com.starrocks.sql.ast.ShowStmt; import com.starrocks.sql.ast.StatementBase; +import com.starrocks.sql.ast.warehouse.AlterWarehouseStmt; import com.starrocks.sql.ast.warehouse.CreateWarehouseStmt; import com.starrocks.sql.ast.warehouse.DropWarehouseStmt; import com.starrocks.sql.ast.warehouse.ResumeWarehouseStmt; @@ -94,6 +95,16 @@ public Void visitSetWarehouseStatement(SetWarehouseStmt statement, ConnectContex public Void visitShowWarehousesStatement(ShowWarehousesStmt node, ConnectContext context) { return null; } + + @Override + public Void visitAlterWarehouseStatement(AlterWarehouseStmt statement, ConnectContext context) { + String whName = statement.getWarehouseName(); + if (Strings.isNullOrEmpty(whName)) { + ErrorReport.reportSemanticException(ErrorCode.ERR_INVALID_WAREHOUSE_NAME); + } + + return null; + } } } \ No newline at end of file diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/ast/AstVisitor.java b/fe/fe-core/src/main/java/com/starrocks/sql/ast/AstVisitor.java index 68921a1188f2f..3c204b3480607 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/ast/AstVisitor.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/ast/AstVisitor.java @@ -65,6 +65,7 @@ import com.starrocks.sql.ast.pipe.DropPipeStmt; import com.starrocks.sql.ast.pipe.PipeName; import com.starrocks.sql.ast.pipe.ShowPipeStmt; +import com.starrocks.sql.ast.warehouse.AlterWarehouseStmt; import com.starrocks.sql.ast.warehouse.CreateWarehouseStmt; import com.starrocks.sql.ast.warehouse.DropWarehouseStmt; import com.starrocks.sql.ast.warehouse.ResumeWarehouseStmt; @@ -1024,6 +1025,10 @@ default R visitShowNodesStatement(ShowNodesStmt statement, C context) { return visitShowStatement(statement, context); } + default R visitAlterWarehouseStatement(AlterWarehouseStmt statement, C context) { + return visitDDLStatement(statement, context); + } + // ------------------------------------------- Unsupported statement --------------------------------------------------------- default R visitUnsupportedStatement(UnsupportedStmt statement, C context) { diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/ast/warehouse/AlterWarehouseStmt.java b/fe/fe-core/src/main/java/com/starrocks/sql/ast/warehouse/AlterWarehouseStmt.java new file mode 100644 index 0000000000000..13c7e5880176c --- /dev/null +++ b/fe/fe-core/src/main/java/com/starrocks/sql/ast/warehouse/AlterWarehouseStmt.java @@ -0,0 +1,67 @@ +// Copyright 2021-present StarRocks, Inc. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.starrocks.sql.ast.warehouse; + +import com.starrocks.common.util.PrintableMap; +import com.starrocks.sql.ast.AstVisitor; +import com.starrocks.sql.ast.DdlStmt; +import com.starrocks.sql.parser.NodePosition; + +import java.util.Map; + +public class AlterWarehouseStmt extends DdlStmt { + private String warehouseName; + private Map properties; + + public AlterWarehouseStmt(String warehouseName, + Map properties) { + this(warehouseName, properties, NodePosition.ZERO); + } + + public AlterWarehouseStmt(String warehouseName, + Map properties, + NodePosition pos) { + super(pos); + this.warehouseName = warehouseName; + this.properties = properties; + } + + public String getWarehouseName() { + return warehouseName; + } + + public Map getProperties() { + return this.properties; + } + + public void setProperties(Map properties) { + this.properties = properties; + } + + @Override + public R accept(AstVisitor visitor, C context) { + return visitor.visitAlterWarehouseStatement(this, context); + } + + @Override + public String toSql() { + StringBuilder sb = new StringBuilder(); + sb.append("ALTER WAREHOUSE "); + sb.append("'").append(warehouseName).append("' "); + sb.append("SET (").append(new PrintableMap<>(properties, " = ", true, false)).append(")"); + return sb.toString(); + } +} + diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java b/fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java index ff29f966bf265..82ddf44fcbdb4 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java @@ -480,6 +480,7 @@ import com.starrocks.sql.ast.pipe.DropPipeStmt; import com.starrocks.sql.ast.pipe.PipeName; import com.starrocks.sql.ast.pipe.ShowPipeStmt; +import com.starrocks.sql.ast.warehouse.AlterWarehouseStmt; import com.starrocks.sql.ast.warehouse.CreateWarehouseStmt; import com.starrocks.sql.ast.warehouse.DropWarehouseStmt; import com.starrocks.sql.ast.warehouse.ResumeWarehouseStmt; @@ -5062,6 +5063,18 @@ public ParseNode visitShowNodesStatement(StarRocksParser.ShowNodesStatementConte return new ShowNodesStmt(warehouseName, pattern, createPos(context)); } + @Override + public ParseNode visitAlterWarehouseStatement(StarRocksParser.AlterWarehouseStatementContext context) { + Identifier identifier = (Identifier) visit(context.identifierOrString()); + String whName = identifier.getValue(); + Map properties = new HashMap<>(); + if (context.modifyPropertiesClause() != null) { + ModifyTablePropertiesClause clause = (ModifyTablePropertiesClause) visit(context.modifyPropertiesClause()); + properties = clause.getProperties(); + } + return new AlterWarehouseStmt(whName, properties, createPos(context)); + } + // ------------------------------------------- Query Statement ----------------------------------------------------- @Override diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/parser/StarRocks.g4 b/fe/fe-core/src/main/java/com/starrocks/sql/parser/StarRocks.g4 index ba1f85648944d..470b905762a32 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/parser/StarRocks.g4 +++ b/fe/fe-core/src/main/java/com/starrocks/sql/parser/StarRocks.g4 @@ -316,6 +316,7 @@ statement | showWarehousesStatement | showClustersStatement | showNodesStatement + | alterWarehouseStatement // Unsupported Statement | unsupportedStatement @@ -2037,6 +2038,10 @@ showNodesStatement | SHOW NODES FROM WAREHOUSE identifier ; +alterWarehouseStatement + : ALTER WAREHOUSE warehouseName=identifierOrString modifyPropertiesClause + ; + // ------------------------------------------- Query Statement --------------------------------------------------------- queryStatement