Skip to content

Commit

Permalink
[Refactor] rename work group to resource group (#8527)
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeiatwork committed Jul 16, 2022
1 parent 5ab5166 commit e6e17f4
Show file tree
Hide file tree
Showing 37 changed files with 505 additions and 504 deletions.
24 changes: 12 additions & 12 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ import com.starrocks.analysis.AlterDatabaseQuotaStmt.QuotaType;
import com.starrocks.analysis.SetOperationStmt.Qualifier;
import com.starrocks.analysis.SetOperationStmt.Operation;
import com.starrocks.analysis.SetOperationStmt.SetOperand;
import com.starrocks.analysis.CreateWorkGroupStmt;
import com.starrocks.analysis.AlterWorkGroupStmt;
import com.starrocks.analysis.DropWorkGroupStmt;
import com.starrocks.analysis.ShowWorkGroupStmt;
import com.starrocks.sql.ast.CreateResourceGroupStmt;
import com.starrocks.sql.ast.AlterResourceGroupStmt;
import com.starrocks.sql.ast.DropResourceGroupStmt;
import com.starrocks.sql.ast.ShowResourceGroupStmt;
import com.starrocks.catalog.AccessPrivilege;
import com.starrocks.catalog.AggregateType;
import com.starrocks.catalog.ArrayType;
Expand Down Expand Up @@ -774,19 +774,19 @@ alter_stmt ::=
alter_resource_group_stmt ::=
KW_ALTER KW_RESOURCE KW_GROUP ident:name KW_ADD classifier_list:list
{:
RESULT = new AlterWorkGroupStmt(name, new AlterWorkGroupStmt.AddClassifiers(list));
RESULT = new AlterResourceGroupStmt(name, new AlterResourceGroupStmt.AddClassifiers(list));
:}
|KW_ALTER KW_RESOURCE KW_GROUP ident:name KW_DROP LPAREN integer_list:list RPAREN
{:
RESULT = new AlterWorkGroupStmt(name, new AlterWorkGroupStmt.DropClassifiers(list));
RESULT = new AlterResourceGroupStmt(name, new AlterResourceGroupStmt.DropClassifiers(list));
:}
|KW_ALTER KW_RESOURCE KW_GROUP ident:name KW_DROP KW_ALL
{:
RESULT = new AlterWorkGroupStmt(name, new AlterWorkGroupStmt.DropAllClassifiers());
RESULT = new AlterResourceGroupStmt(name, new AlterResourceGroupStmt.DropAllClassifiers());
:}
|KW_ALTER KW_RESOURCE KW_GROUP ident:name KW_WITH LPAREN key_value_map:properties RPAREN
{:
RESULT = new AlterWorkGroupStmt(name, new AlterWorkGroupStmt.AlterProperties(properties));
RESULT = new AlterResourceGroupStmt(name, new AlterResourceGroupStmt.AlterProperties(properties));
:}
;

Expand Down Expand Up @@ -1165,7 +1165,7 @@ create_stmt ::=
KW_TO classifier_list:classifiers
KW_WITH LPAREN key_value_map:properties RPAREN
{:
RESULT = new CreateWorkGroupStmt(name, if_not_exists, or_replace, classifiers, properties);
RESULT = new CreateResourceGroupStmt(name, if_not_exists, or_replace, classifiers, properties);
:}
;

Expand Down Expand Up @@ -1713,7 +1713,7 @@ drop_stmt ::=
:}
| KW_DROP KW_RESOURCE KW_GROUP ident:name
{:
RESULT = new DropWorkGroupStmt(name);
RESULT = new DropResourceGroupStmt(name);
:}
;

Expand Down Expand Up @@ -2481,11 +2481,11 @@ show_param ::=
:}
| KW_RESOURCE KW_GROUPS opt_all:list_all
{:
RESULT = new ShowWorkGroupStmt(null, list_all);
RESULT = new ShowResourceGroupStmt(null, list_all);
:}
| KW_RESOURCE KW_GROUP ident:name
{:
RESULT = new ShowWorkGroupStmt(name, false);
RESULT = new ShowResourceGroupStmt(name, false);
:}
;

Expand Down
4 changes: 2 additions & 2 deletions fe/fe-core/src/main/java/com/starrocks/analysis/SetVar.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
package com.starrocks.analysis;

import com.google.common.base.Strings;
import com.starrocks.catalog.WorkGroup;
import com.starrocks.catalog.ResourceGroup;
import com.starrocks.common.ErrorCode;
import com.starrocks.common.ErrorReport;
import com.starrocks.common.UserException;
Expand Down Expand Up @@ -161,7 +161,7 @@ public void analyze() {
if (getVariable().equalsIgnoreCase(SessionVariable.RESOURCE_GROUP)) {
String wgName = getValue().getStringValue();
if (!StringUtils.isEmpty(wgName)) {
WorkGroup wg = GlobalStateMgr.getCurrentState().getWorkGroupMgr().chooseWorkGroupByName(wgName);
ResourceGroup wg = GlobalStateMgr.getCurrentState().getResourceGroupMgr().chooseResourceGroupByName(wgName);
if (wg == null) {
throw new SemanticException("resource group not exists: " + wgName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import java.util.Objects;
import java.util.stream.Collectors;

public class WorkGroup implements Writable {
public class ResourceGroup implements Writable {
public static final String GROUP_TYPE = "type";
public static final String USER = "user";
public static final String ROLE = "role";
public static final String QUERY_TYPE = "query_type";
Expand All @@ -30,8 +31,7 @@ public class WorkGroup implements Writable {
public static final String BIG_QUERY_SCAN_ROWS_LIMIT = "big_query_scan_rows_limit";
public static final String BIG_QUERY_CPU_SECOND_LIMIT = "big_query_cpu_second_limit";
public static final String CONCURRENCY_LIMIT = "concurrency_limit";
public static final String WORKGROUP_TYPE = "type";
public static final String DEFAULT_WORKGROUP_NAME = "default_wg";
public static final String DEFAULT_RESOURCE_GROUP_NAME = "default_wg";

public static final ShowResultSetMetaData META_DATA =
ShowResultSetMetaData.builder()
Expand All @@ -45,10 +45,9 @@ public class WorkGroup implements Writable {
.addColumn(new Column("concurrency_limit", ScalarType.createVarchar(200)))
.addColumn(new Column("type", ScalarType.createVarchar(200)))
.addColumn(new Column("classifiers", ScalarType.createVarchar(1024)))
.build();

.build();
@SerializedName(value = "classifiers")
List<WorkGroupClassifier> classifiers;
List<ResourceGroupClassifier> classifiers;
@SerializedName(value = "name")
private String name;
@SerializedName(value = "id")
Expand All @@ -66,19 +65,19 @@ public class WorkGroup implements Writable {
@SerializedName(value = "concurrencyLimit")
private Integer concurrencyLimit;
@SerializedName(value = "workGroupType")
private TWorkGroupType workGroupType;
private TWorkGroupType resourceGroupType;
@SerializedName(value = "version")
private long version;

public WorkGroup() {
public ResourceGroup() {
}

public static WorkGroup read(DataInput in) throws IOException {
public static ResourceGroup read(DataInput in) throws IOException {
String json = Text.readString(in);
return GsonUtils.GSON.fromJson(json, WorkGroup.class);
return GsonUtils.GSON.fromJson(json, ResourceGroup.class);
}

private List<String> showClassifier(WorkGroupClassifier classifier) {
private List<String> showClassifier(ResourceGroupClassifier classifier) {
List<String> row = new ArrayList<>();
row.add(this.name);
row.add("" + this.id);
Expand All @@ -100,7 +99,7 @@ private List<String> showClassifier(WorkGroupClassifier classifier) {
row.add("" + 0);
}
row.add("" + concurrencyLimit);
row.add("" + workGroupType.name().substring("WG_".length()));
row.add("" + resourceGroupType.name().substring("WG_".length()));
row.add(classifier.toString());
return row;
}
Expand Down Expand Up @@ -169,8 +168,8 @@ public TWorkGroup toThrift() {
if (concurrencyLimit != null) {
twg.setConcurrency_limit(concurrencyLimit);
}
if (workGroupType != null) {
twg.setWorkgroup_type(workGroupType);
if (resourceGroupType != null) {
twg.setWorkgroup_type(resourceGroupType);
}
twg.setVersion(version);
return twg;
Expand Down Expand Up @@ -224,19 +223,19 @@ public void setConcurrencyLimit(int concurrencyLimit) {
this.concurrencyLimit = concurrencyLimit;
}

public TWorkGroupType getWorkGroupType() {
return workGroupType;
public TWorkGroupType getResourceGroupType() {
return resourceGroupType;
}

public void setWorkGroupType(TWorkGroupType workGroupType) {
this.workGroupType = workGroupType;
public void setResourceGroupType(TWorkGroupType workGroupType) {
this.resourceGroupType = workGroupType;
}

public List<WorkGroupClassifier> getClassifiers() {
public List<ResourceGroupClassifier> getClassifiers() {
return classifiers;
}

public void setClassifiers(List<WorkGroupClassifier> classifiers) {
public void setClassifiers(List<ResourceGroupClassifier> classifiers) {
this.classifiers = classifiers;
}

Expand All @@ -248,8 +247,8 @@ public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) {
return false;
}
WorkGroup workGroup = (WorkGroup) o;
return id == workGroup.id && version == workGroup.version;
ResourceGroup resourceGroup = (ResourceGroup) o;
return id == resourceGroup.id && version == resourceGroup.version;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class WorkGroupClassifier implements Writable {
public class ResourceGroupClassifier implements Writable {
public static final Pattern UseRolePattern = Pattern.compile("^\\w+$");
public static final Set<String> QUERY_TYPES =
Arrays.stream(QueryType.values()).map(Enum::name).collect(Collectors.toSet());
Expand All @@ -40,21 +40,21 @@ public class WorkGroupClassifier implements Writable {
@SerializedName(value = "sourceIp")
private String sourceIp;
@SerializedName(value = "workgroupId")
private long workgroupId;
private long resourceGroupId;
@SerializedName(value = "databaseIds")
private Set<Long> databaseIds;

public static WorkGroupClassifier read(DataInput in) throws IOException {
public static ResourceGroupClassifier read(DataInput in) throws IOException {
String json = Text.readString(in);
return GsonUtils.GSON.fromJson(json, WorkGroupClassifier.class);
return GsonUtils.GSON.fromJson(json, ResourceGroupClassifier.class);
}

public long getWorkgroupId() {
return workgroupId;
public long getResourceGroupId() {
return resourceGroupId;
}

public void setWorkgroupId(long workgroupId) {
this.workgroupId = workgroupId;
public void setResourceGroupId(long resourceGroupId) {
this.resourceGroupId = resourceGroupId;
}

public long getId() {
Expand Down

0 comments on commit e6e17f4

Please sign in to comment.