Skip to content

Commit

Permalink
feat(partition-plan): add api and storage layer (#1374)
Browse files Browse the repository at this point in the history
* fix issue #1337

* update submodule

* add api for partition plan

* add storage layer

* rename field

* rename class

* corrent i18n

* corrent i18n

* corrent method name

* fix several errors

* remove timeunit

* add more time unit

* rename script

* rename unique index

* move partition plan type to task plugin

* response to cr comments

* trigger git action

* response to cr comments

* response to cr comments
  • Loading branch information
yhilmare committed Jan 12, 2024
1 parent 9bf406b commit ecb9d27
Show file tree
Hide file tree
Showing 32 changed files with 1,357 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2023 OceanBase.
*
* 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
*
* 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 com.oceanbase.odc.metadb.partitionplan;

import java.util.Optional;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.oceanbase.odc.ServiceTestEnv;
import com.oceanbase.odc.test.tool.TestRandom;

/**
* Test cases for {@link PartitionPlanRepository}
*
* @author yh263208
* @date 2024-01-10 16:57
* @since ODC-release_4.2.4
*/
public class PartitionPlanRepositoryTest extends ServiceTestEnv {

@Autowired
private PartitionPlanRepository repository;

@Before
public void setUp() throws Exception {
repository.deleteAll();
}

@Test
public void save_saveOne_saveSucceed() {
PartitionPlanEntity actual = createRoleEntity();
actual.setId(null);
actual = this.repository.save(actual);
Optional<PartitionPlanEntity> expect = this.repository.findById(actual.getId());
Assert.assertEquals(expect.get(), actual);
}

private PartitionPlanEntity createRoleEntity() {
return TestRandom.nextObject(PartitionPlanEntity.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2023 OceanBase.
*
* 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
*
* 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 com.oceanbase.odc.metadb.partitionplan;

import java.util.Optional;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.oceanbase.odc.ServiceTestEnv;
import com.oceanbase.odc.test.tool.TestRandom;

/**
* Test cases for {@link PartitionPlanTablePartitionKeyRepository}
*
* @author yh263208
* @date 2024-01-10 17:08
* @since ODC_release_4.2.4
*/
public class PartitionPlanTablePartitionKeyRepositoryTest extends ServiceTestEnv {

@Autowired
private PartitionPlanTablePartitionKeyRepository repository;

@Before
public void setUp() throws Exception {
repository.deleteAll();
}

@Test
public void save_saveOne_saveSucceed() {
PartitionPlanTablePartitionKeyEntity actual = createRoleEntity();
actual.setId(null);
actual = this.repository.save(actual);
Optional<PartitionPlanTablePartitionKeyEntity> expect = this.repository.findById(actual.getId());
Assert.assertEquals(expect.get(), actual);
}

private PartitionPlanTablePartitionKeyEntity createRoleEntity() {
return TestRandom.nextObject(PartitionPlanTablePartitionKeyEntity.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2023 OceanBase.
*
* 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
*
* 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 com.oceanbase.odc.metadb.partitionplan;

import java.util.Optional;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import com.oceanbase.odc.ServiceTestEnv;
import com.oceanbase.odc.test.tool.TestRandom;

/**
* Test cases for {@link PartitionPlanTableRepositoryTest}
*
* @author yh263208
* @date 2024-01-10 17:08
* @since ODC_release_4.2.4
*/
public class PartitionPlanTableRepositoryTest extends ServiceTestEnv {

@Autowired
private PartitionPlanTableRepository repository;

@Before
public void setUp() throws Exception {
repository.deleteAll();
}

@Test
public void save_saveOne_saveSucceed() {
PartitionPlanTableEntity actual = createRoleEntity();
actual.setId(null);
actual = this.repository.save(actual);
Optional<PartitionPlanTableEntity> expect = this.repository.findById(actual.getId());
Assert.assertEquals(expect.get(), actual);
}

private PartitionPlanTableEntity createRoleEntity() {
return TestRandom.nextObject(PartitionPlanTableEntity.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -799,3 +799,7 @@ com.oceanbase.odc.generate-update-table-ddl-check.drop-and-create-index.message=
com.oceanbase.odc.DatabasePermissionType.QUERY=Query
com.oceanbase.odc.DatabasePermissionType.CHANGE=Change
com.oceanbase.odc.DatabasePermissionType.EXPORT=Export

com.oceanbase.odc.PartitionPlanVariableKey.INTERVAL=interval
com.oceanbase.odc.PartitionPlanVariableKey.LAST_PARTITION_VALUE=The value of the positional expression corresponding to the last partition rule

Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,7 @@ com.oceanbase.odc.generate-update-table-ddl-check.drop-and-create-index.message=
com.oceanbase.odc.DatabasePermissionType.QUERY=查询
com.oceanbase.odc.DatabasePermissionType.CHANGE=变更
com.oceanbase.odc.DatabasePermissionType.EXPORT=导出

com.oceanbase.odc.PartitionPlanVariableKey.INTERVAL=间隔
com.oceanbase.odc.PartitionPlanVariableKey.LAST_PARTITION_VALUE=最后一个分区规则对应位置表达式的值

Original file line number Diff line number Diff line change
Expand Up @@ -803,3 +803,6 @@ com.oceanbase.odc.generate-update-table-ddl-check.drop-and-create-index.message=
com.oceanbase.odc.DatabasePermissionType.QUERY=查詢
com.oceanbase.odc.DatabasePermissionType.CHANGE=變更
com.oceanbase.odc.DatabasePermissionType.EXPORT=導出

com.oceanbase.odc.PartitionPlanVariableKey.INTERVAL=間隔
com.oceanbase.odc.PartitionPlanVariableKey.LAST_PARTITION_VALUE=最後一個分區規則對應位置表達式的值
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
CREATE TABLE IF NOT EXISTS `partitionplan` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Id for partition plan task',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Record insertion time',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Record modification time',
`flow_instance_id` bigint(20) NOT NULL COMMENT 'Related flow instance id, reference flow_instance(id)',
`is_enabled` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Flag bit, mark whether the partition plan task is enabled',
`creator_id` bigint(20) NOT NULL COMMENT 'Creator id, references odc_user_info(id)',
`last_modifier_id` bigint(20) DEFAULT NULL COMMENT 'Last modifier id, references odc_user_info(id)',
`database_id` bigint(20) NOT NULL COMMENT 'Related database id, reference connect_database(id)',
CONSTRAINT `pk_partitionplan_id` PRIMARY KEY (`id`),
UNIQUE KEY `uk_partitionplan_flow_instance_id` (`flow_instance_id`)
);

CREATE TABLE IF NOT EXISTS `partitionplan_table` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Id for partition plan table',
`table_name` varchar(512) NOT NULL COMMENT 'Target table name',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Record insertion time',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Record modification time',
`is_enabled` tinyint(1) NOT NULL DEFAULT 1 COMMENT 'Flag bit, mark whether the partition plan task is enabled',
`partition_name_invoker` varchar(64) NOT NULL COMMENT 'The name of the specific executor of the partition strategy needs to match invoker_input',
`partition_name_invoker_parameters` varchar(1024) NOT NULL COMMENT 'The input of the specific executor of the partition strategy invoker',
`schedule_id` bigint(20) NOT NULL COMMENT 'Related schedule id, reference schedule_schedule(id)',
`partitionplan_id` bigint(20) NOT NULL COMMENT 'Related partition plan id, reference partitionplan(id)',
CONSTRAINT `pk_partitionplan_table_id` PRIMARY KEY (`id`),
UNIQUE KEY `uk_partitionplan_table_schedule_id_partitionplan_id_table_name` (`schedule_id`, `partitionplan_id`, `table_name`)
);

CREATE TABLE IF NOT EXISTS `partitionplan_table_partitionkey` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Id for partition plan table',
`partition_key` varchar(2048) NOT NULL COMMENT 'Target partition key',
`strategy` varchar(64) NOT NULL COMMENT 'Partition strategy type, enumeration values: CREATE, DROP',
`partition_key_invoker` varchar(64) NOT NULL COMMENT 'The name of the specific executor of the partition strategy needs to match invoker_input',
`partition_key_invoker_parameters` varchar(1024) NOT NULL COMMENT 'The input of the specific executor of the partition strategy invoker',
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Record insertion time',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Record modification time',
`partitionplan_table_id` bigint(20) NOT NULL COMMENT 'Related partition plan table id, reference partitionplan_table(id)',
CONSTRAINT `pk_partitionplan_table_partitionkey` PRIMARY KEY (`id`),
UNIQUE KEY `uk_ptp_ptid_strategy_partition_key` (`partitionplan_table_id`, `strategy`, `partition_key`)
);
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -38,6 +39,7 @@
import org.springframework.web.multipart.MultipartFile;

import com.oceanbase.odc.core.session.ConnectionSession;
import com.oceanbase.odc.core.shared.exception.NotImplementedException;
import com.oceanbase.odc.service.common.response.ListResponse;
import com.oceanbase.odc.service.common.response.Responses;
import com.oceanbase.odc.service.common.response.SuccessResponse;
Expand All @@ -49,6 +51,8 @@
import com.oceanbase.odc.service.db.session.KillSessionOrQueryReq;
import com.oceanbase.odc.service.db.session.KillSessionResult;
import com.oceanbase.odc.service.dml.ValueEncodeType;
import com.oceanbase.odc.service.partitionplan.model.PartitionPlanPreViewResp;
import com.oceanbase.odc.service.partitionplan.model.PartitionPlanTableConfig;
import com.oceanbase.odc.service.session.ConnectConsoleService;
import com.oceanbase.odc.service.session.ConnectSessionService;
import com.oceanbase.odc.service.session.model.BinaryContent;
Expand Down Expand Up @@ -229,4 +233,11 @@ public SuccessResponse<SqlExecuteResult> queryTableOrViewData(@PathVariable Stri
public SuccessResponse<DBSessionResp> currentSessionStatus(@PathVariable String sessionId) {
return Responses.success(sessionService.currentDBSession(sessionId));
}

@PostMapping(value = "/sessions/{sessionId}/partitionPlans/latest/preview")
public ListResponse<PartitionPlanPreViewResp> getPreView(@RequestBody List<PartitionPlanTableConfig> tableConfigs,
@RequestParam(name = "onlyForPartitionName", defaultValue = "false") Boolean onlyForPartitionName) {
throw new NotImplementedException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import org.springframework.web.bind.annotation.RestController;

import com.oceanbase.odc.core.session.ConnectionSession;
import com.oceanbase.odc.core.shared.exception.NotImplementedException;
import com.oceanbase.odc.service.common.response.ListResponse;
import com.oceanbase.odc.service.common.response.Responses;
import com.oceanbase.odc.service.common.response.SuccessResponse;
import com.oceanbase.odc.service.db.DBTableService;
import com.oceanbase.odc.service.db.model.GenerateTableDDLResp;
import com.oceanbase.odc.service.db.model.GenerateUpdateTableDDLReq;
import com.oceanbase.odc.service.partitionplan.model.PartitionPlanDBTable;
import com.oceanbase.odc.service.session.ConnectSessionService;
import com.oceanbase.tools.dbbrowser.model.DBSchema;
import com.oceanbase.tools.dbbrowser.model.DBTable;
Expand Down Expand Up @@ -88,4 +90,10 @@ public SuccessResponse<GenerateTableDDLResp> generateUpdateTableDDL(@PathVariabl
return Responses.success(tableService.generateUpdateDDL(session, req));
}

@GetMapping(value = "/{sessionId}/databases/{databaseName}/candidatePartitionPlanTables")
public ListResponse<PartitionPlanDBTable> listTables(@PathVariable String sessionId,
@PathVariable String databaseName) {
throw new NotImplementedException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -41,6 +42,7 @@
import com.oceanbase.odc.core.shared.constant.OrganizationType;
import com.oceanbase.odc.core.shared.constant.ResourceType;
import com.oceanbase.odc.core.shared.constant.TaskType;
import com.oceanbase.odc.core.shared.exception.NotImplementedException;
import com.oceanbase.odc.service.common.response.ListResponse;
import com.oceanbase.odc.service.common.response.PaginatedResponse;
import com.oceanbase.odc.service.common.response.Responses;
Expand All @@ -55,6 +57,7 @@
import com.oceanbase.odc.service.flow.model.FlowMetaInfo;
import com.oceanbase.odc.service.flow.model.QueryFlowInstanceParams;
import com.oceanbase.odc.service.iam.auth.AuthenticationFacade;
import com.oceanbase.odc.service.partitionplan.model.PartitionPlanConfig;
import com.oceanbase.odc.service.session.model.SqlExecuteResult;
import com.oceanbase.odc.service.task.model.OdcTaskLogLevel;

Expand Down Expand Up @@ -216,4 +219,10 @@ public ListResponse<SqlExecuteResult> getQueryResult(@PathVariable Long id) thro
public ListResponse<String> getDownloadUrl(@PathVariable Long id, @RequestBody List<String> objectId) {
return Responses.list(flowTaskInstanceService.getAsyncDownloadUrl(id, objectId));
}

@GetMapping(value = "/{id:[\\d]+}/tasks/partitionPlans/getDetail")
public SuccessResponse<PartitionPlanConfig> getPartitionPlan(@PathVariable Long flowInstanceId) {
throw new NotImplementedException();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
package com.oceanbase.odc.server.web.controller.v2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.oceanbase.odc.core.shared.exception.NotImplementedException;
import com.oceanbase.odc.service.common.response.ListResponse;
import com.oceanbase.odc.service.common.response.Responses;
import com.oceanbase.odc.service.common.response.SuccessResponse;
import com.oceanbase.odc.service.partitionplan.PartitionPlanService;
import com.oceanbase.odc.service.partitionplan.model.DatabasePartitionPlan;
import com.oceanbase.odc.service.partitionplan.model.PartitionPlanVariable;

/**
* @Author:tianke
Expand All @@ -50,4 +54,9 @@ public SuccessResponse<Boolean> exist(@RequestParam("databaseId") Long databaseI
return Responses.success(partitionPlanService.hasConnectionPartitionPlan(databaseId));
}

@GetMapping(value = "/supportedVariables")
public ListResponse<PartitionPlanVariable> getSupportedVariables() {
throw new NotImplementedException();
}

}
Loading

0 comments on commit ecb9d27

Please sign in to comment.