forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] (nereids)implement adminSetPartitionVersionCommand in n…
…ereids
- Loading branch information
Showing
6 changed files
with
196 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...n/java/org/apache/doris/nereids/trees/plans/commands/AdminSetPartitionVersionCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// 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.nereids.trees.plans.commands; | ||
|
||
import org.apache.doris.catalog.Env; | ||
import org.apache.doris.common.AnalysisException; | ||
import org.apache.doris.common.DdlException; | ||
import org.apache.doris.common.ErrorCode; | ||
import org.apache.doris.common.ErrorReport; | ||
import org.apache.doris.common.util.PropertyAnalyzer; | ||
import org.apache.doris.common.util.Util; | ||
import org.apache.doris.mysql.privilege.PrivPredicate; | ||
import org.apache.doris.nereids.trees.plans.PlanType; | ||
import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo; | ||
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor; | ||
import org.apache.doris.qe.ConnectContext; | ||
import org.apache.doris.qe.StmtExecutor; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* admin set partition version command | ||
*/ | ||
public class AdminSetPartitionVersionCommand extends Command implements ForwardNoSync { | ||
long partitionId = -1; | ||
long visibleVersion = -1; | ||
private final TableNameInfo tableName; | ||
private final Map<String, String> properties; | ||
|
||
/** | ||
* constructor | ||
*/ | ||
public AdminSetPartitionVersionCommand(TableNameInfo tableName, Map<String, String> properties) { | ||
super(PlanType.ADMIN_SET_PARTITION_VERSION); | ||
this.tableName = tableName; | ||
this.properties = properties; | ||
} | ||
|
||
@Override | ||
public void run(ConnectContext ctx, StmtExecutor executor) throws Exception { | ||
|
||
tableName.analyze(ctx); | ||
|
||
// check auth | ||
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) { | ||
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN"); | ||
} | ||
|
||
Util.prohibitExternalCatalog(tableName.getCtl(), this.getClass().getSimpleName()); | ||
|
||
checkProperties(); | ||
|
||
String database = tableName.getDb(); | ||
String table = tableName.getTbl(); | ||
|
||
int setSuccess = Env.getCurrentEnv().setPartitionVersionInternal(database, table, partitionId, visibleVersion, | ||
false); | ||
if (setSuccess == -1) { | ||
throw new DdlException("Failed to set partition visible version to " + visibleVersion + ". " + "Partition " | ||
+ partitionId + " not exists. Database " + database + ", Table " + table + "."); | ||
} | ||
|
||
} | ||
|
||
private void checkProperties() throws AnalysisException { | ||
partitionId = PropertyAnalyzer.analyzePartitionId(properties); | ||
if (partitionId == -1) { | ||
throw new AnalysisException("Should specify 'partition_id' property."); | ||
} | ||
visibleVersion = PropertyAnalyzer.analyzeVisibleVersion(properties); | ||
if (visibleVersion == -1) { | ||
throw new AnalysisException("Should specify 'visible_version' property."); | ||
} | ||
if (properties != null && !properties.isEmpty()) { | ||
throw new AnalysisException("Unknown properties: " + properties.keySet()); | ||
} | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) { | ||
return visitor.visitAdminSetPartitionVersionCommand(this, context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...ion-test/suites/nereids_p0/select_tablets/test_nereids_admin_set_partition_version.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package select_tablets | ||
// 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. | ||
|
||
|
||
suite("test_nereids_admin_set_partition_version") { | ||
def table = "test_nereids_admin_set_partition_version" | ||
|
||
// create table and insert data | ||
String dbName = 'test_nereids_admin_set_partition_version' | ||
try_sql """drop database if exists ${dbName}""" | ||
sql """create database ${dbName}""" | ||
sql """ drop table if exists ${dbName}.${table} force""" | ||
|
||
sql """ | ||
create table ${dbName}.${table} ( | ||
`id` int(11), | ||
`name` varchar(128), | ||
`da` date | ||
) | ||
engine=olap | ||
duplicate key(id) | ||
partition by range(da)( | ||
PARTITION p3 VALUES LESS THAN ('2023-01-01'), | ||
PARTITION p4 VALUES LESS THAN ('2024-01-01'), | ||
PARTITION p5 VALUES LESS THAN ('2025-01-01') | ||
) | ||
distributed by hash(id) buckets 2 | ||
properties( | ||
"replication_num"="1", | ||
"light_schema_change"="true" | ||
); | ||
""" | ||
|
||
def result = sql_return_maparray "show partitions from ${dbName}.${table}" | ||
logger.info("${result}") | ||
def partitionId; | ||
for (def partition : result) { | ||
//get any partition ID. | ||
partitionId = partition.PartitionId; | ||
break; | ||
} | ||
|
||
checkNereidsExecute("ADMIN SET TABLE ${dbName}.${table} PARTITION VERSION PROPERTIES ('partition_id' = '${partitionId}', 'visible_version' = '100');") | ||
sql """ use ${dbName}""" | ||
checkNereidsExecute("ADMIN SET TABLE ${table} PARTITION VERSION PROPERTIES ('partition_id' = '${partitionId}', 'visible_version' = '100');") | ||
|
||
String catalog_name = "es" | ||
|
||
sql """drop catalog if exists ${catalog_name}""" | ||
sql """create catalog if not exists ${catalog_name} properties ( | ||
"type"="es", | ||
"hosts"="http://127.0.0.1:9200" | ||
);""" | ||
|
||
sql """switch ${catalog_name};""" | ||
|
||
checkNereidsExecute("ADMIN SET TABLE ${dbName}.${table} PARTITION VERSION PROPERTIES ('partition_id' = '${partitionId}', 'visible_version' = '100');") | ||
|
||
} | ||
|