Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
{
"title": "ALTER-COLOCATE-GROUP",
"language": "en"
}
---

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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

http://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.
-->

## ALTER-COLOCATE-GROUP

### Name

ALTER COLOCATE GROUP

<version since="dev"></version>

### Description

This statement is used to modify the colocation group.

Syntax:

```sql
ALTER COLOCATE GROUP [database.]group
SET (
property_list
);
```

NOTE:

1. If the colocate group is global, that is, its name starts with `__global__`, then it does not belong to any database;

2. property_list is a colocation group attribute, currently only supports modifying `replication_num` and `replication_allocation`. After modifying these two attributes of the colocation group, at the same time, change the attribute `default.replication_allocation`, the attribute `dynamic.replication_allocation` of the table of the group, and the `replication_allocation` of the existing partition to be the same as it.

### Example

1. Modify the number of copies of a global group

```sql
# Set "colocate_with" = "__global__foo" when creating the table

ALTER COLOCATE GROUP __global__foo
SET (
"replication_num"="1"
);
```

2. Modify the number of copies of a non-global group

```sql
# Set "colocate_with" = "bar" when creating the table, and the Database is "example_db"

ALTER COLOCATE GROUP example_db.bar
SET (
"replication_num"="1"
);
```

### Keywords

```sql
ALTER, COLOCATE, GROUP
```

### Best Practice
1 change: 1 addition & 0 deletions docs/sidebars.json
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,7 @@
"sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-VIEW",
"sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-STORAGE-POLICY",
"sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-RESOURCE",
"sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-COLOCATE-GROUP",
"sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-WORKLOAD-GROUP",
"sql-manual/sql-reference/Data-Definition-Statements/Alter/ALTER-SQL-BLOCK-RULE",
"sql-manual/sql-reference/Data-Definition-Statements/Alter/PAUSE-JOB",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
{
"title": "ALTER-COLOCATE-GROUP",
"language": "zh-CN"
}
---

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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

http://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.
-->

## ALTER-COLOCATE-GROUP

### Name

ALTER COLOCATE GROUP

<version since="dev"></version>

### Description

该语句用于修改 Colocation Group 的属性。

语法:

```sql
ALTER COLOCATE GROUP [database.]group
SET (
property_list
);
```

注意:

1. 如果colocate group是全局的,即它的名称是以 `__global__` 开头的,那它不属于任何一个Database;

2. property_list 是colocation group属性,目前只支持修改`replication_num` 和 `replication_allocation`。
修改colocation group的这两个属性修改之后,同时把该group的表的属性`default.replication_allocation` 、
属性`dynamic.replication_allocation `、以及已有分区的`replication_allocation`改成跟它一样。



### Example

1. 修改一个全局group的副本数

```sql
# 建表时设置 "colocate_with" = "__global__foo"

ALTER COLOCATE GROUP __global__foo
SET (
"replication_num"="1"
);
```

2. 修改一个非全局group的副本数

```sql
# 建表时设置 "colocate_with" = "bar",且表属于Database example_db

ALTER COLOCATE GROUP example_db.bar
SET (
"replication_num"="1"
);
```

### Keywords

```sql
ALTER, COLOCATE , GROUP
```

### Best Practice
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
{
"title": "ALTER-WORKLOAD -GROUP",
"title": "ALTER-WORKLOAD-GROUP",
"language": "zh-CN"
}
---
Expand All @@ -24,7 +24,7 @@ specific language governing permissions and limitations
under the License.
-->

## ALTER-WORKLOAD -GROUP
## ALTER-WORKLOAD-GROUP

### Name

Expand Down
17 changes: 17 additions & 0 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ terminal String
KW_CLUSTERS,
KW_COLLATE,
KW_COLLATION,
KW_COLOCATE,
KW_COLUMN,
KW_COLUMNS,
KW_COMMENT,
Expand Down Expand Up @@ -812,6 +813,7 @@ nonterminal ArrayList<String> opt_common_hints;
nonterminal String optional_on_ident;
nonterminal String opt_job_starts;
nonterminal String opt_job_ends;
nonterminal ColocateGroupName colocate_group_name;

nonterminal LoadTask.MergeType opt_merge_type, opt_with_merge_type;

Expand Down Expand Up @@ -1347,6 +1349,10 @@ alter_stmt ::=
{:
RESULT = new AlterResourceStmt(resourceName, properties);
:}
| KW_ALTER KW_COLOCATE KW_GROUP colocate_group_name:colocateGroupName KW_SET LPAREN key_value_map:properties RPAREN
{:
RESULT = new AlterColocateGroupStmt(colocateGroupName, properties);
:}
| KW_ALTER KW_WORKLOAD KW_GROUP ident_or_text:workloadGroupName opt_properties:properties
{:
RESULT = new AlterWorkloadGroupStmt(workloadGroupName, properties);
Expand Down Expand Up @@ -5642,6 +5648,17 @@ table_name ::=
{: RESULT = new TableName(ctl, db, tbl); :}
;

colocate_group_name ::=
ident:group
{:
RESULT = new ColocateGroupName(null, group);
:}
| ident:db DOT ident:group
{:
RESULT = new ColocateGroupName(db, group);
:}
;

encryptkey_name ::=
ident:name
{:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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
//
// http://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 org.apache.doris.analysis;

import org.apache.doris.catalog.Env;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.UserException;
import org.apache.doris.common.util.PrintableMap;
import org.apache.doris.mysql.privilege.PrivPredicate;
import org.apache.doris.qe.ConnectContext;

import com.google.common.base.Strings;

import java.util.Map;

public class AlterColocateGroupStmt extends DdlStmt {
private final ColocateGroupName colocateGroupName;
private final Map<String, String> properties;

public AlterColocateGroupStmt(ColocateGroupName colocateGroupName, Map<String, String> properties) {
this.colocateGroupName = colocateGroupName;
this.properties = properties;
}

public ColocateGroupName getColocateGroupName() {
return colocateGroupName;
}

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

@Override
public void analyze(Analyzer analyzer) throws UserException {
super.analyze(analyzer);
colocateGroupName.analyze(analyzer);

String dbName = colocateGroupName.getDb();
if (Strings.isNullOrEmpty(dbName)) {
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(
ConnectContext.get(), PrivPredicate.ADMIN)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN");
}
} else {
if (!Env.getCurrentEnv().getAccessManager().checkDbPriv(
ConnectContext.get(), dbName, PrivPredicate.ADMIN)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_DBACCESS_DENIED_ERROR,
ConnectContext.get().getQualifiedUser(), dbName);
}
}

if (properties == null || properties.isEmpty()) {
throw new AnalysisException("Colocate group properties can't be null");
}
}

@Override
public String toSql() {
StringBuilder sb = new StringBuilder();
sb.append("ALTER COLOCATE GROUP ").append(colocateGroupName.toSql()).append(" ");
sb.append("PROPERTIES(").append(new PrintableMap<>(properties, " = ", true, false)).append(")");
return sb.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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
//
// http://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 org.apache.doris.analysis;

import org.apache.doris.catalog.ColocateTableIndex.GroupId;
import org.apache.doris.cluster.ClusterNamespace;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;

import com.google.common.base.Strings;

public class ColocateGroupName {
private String db;
private String group;

public ColocateGroupName(String db, String group) {
this.db = db;
this.group = group;
}

public String getDb() {
return db;
}

public String getGroup() {
return group;
}

public void analyze(Analyzer analyzer) throws AnalysisException {
if (GroupId.isGlobalGroupName(group)) {
if (!Strings.isNullOrEmpty(db)) {
throw new AnalysisException("group that name starts with `" + GroupId.GLOBAL_COLOCATE_PREFIX + "`"
+ " is a global group, it doesn't belong to any specific database");
}
} else {
if (Strings.isNullOrEmpty(db)) {
if (Strings.isNullOrEmpty(analyzer.getDefaultDb())) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DB_ERROR);
}
db = analyzer.getDefaultDb();
}
db = ClusterNamespace.getFullName(analyzer.getClusterName(), db);
}
}

public String toSql() {
StringBuilder sb = new StringBuilder();
if (!Strings.isNullOrEmpty(db)) {
sb.append("`").append(db).append("`.");
}
sb.append("`").append(group).append("`");
return sb.toString();
}
}
Loading