Skip to content

Commit

Permalink
[Enhancement] support dummy alter warehouse
Browse files Browse the repository at this point in the history
Signed-off-by: starrocks-xupeng <[email protected]>
  • Loading branch information
starrocks-xupeng committed Nov 20, 2024
1 parent 803e254 commit 897650e
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 2 deletions.
14 changes: 12 additions & 2 deletions fe/fe-core/src/main/java/com/starrocks/lake/StarOSAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand All @@ -744,14 +744,24 @@ 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());
}
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 {
Expand Down
10 changes: 10 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/qe/DDLStmtExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String> getAllWarehouseNames() {
return Sets.newHashSet(DEFAULT_WAREHOUSE_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> properties;

public AlterWarehouseStmt(String warehouseName,
Map<String, String> properties) {
this(warehouseName, properties, NodePosition.ZERO);
}

public AlterWarehouseStmt(String warehouseName,
Map<String, String> properties,
NodePosition pos) {
super(pos);
this.warehouseName = warehouseName;
this.properties = properties;
}

public String getWarehouseName() {
return warehouseName;
}

public Map<String, String> getProperties() {
return this.properties;
}

public void setProperties(Map<String, String> properties) {
this.properties = properties;
}

@Override
public <R, C> R accept(AstVisitor<R, C> 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();
}
}

13 changes: 13 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ statement
| showWarehousesStatement
| showClustersStatement
| showNodesStatement
| alterWarehouseStatement

// Unsupported Statement
| unsupportedStatement
Expand Down Expand Up @@ -2037,6 +2038,10 @@ showNodesStatement
| SHOW NODES FROM WAREHOUSE identifier
;

alterWarehouseStatement
: ALTER WAREHOUSE warehouseName=identifierOrString modifyPropertiesClause
;

// ------------------------------------------- Query Statement ---------------------------------------------------------

queryStatement
Expand Down

0 comments on commit 897650e

Please sign in to comment.