From b1557176bf550e526bbeab6aa386d6059c24d6c8 Mon Sep 17 00:00:00 2001 From: IL MARE Date: Fri, 12 Jan 2024 11:57:42 +0800 Subject: [PATCH] feat(partition-plan): add api and storage layer (#1374) * 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 --- .../PartitionPlanRepositoryTest.java | 58 ++++++++ ...onPlanTablePartitionKeyRepositoryTest.java | 58 ++++++++ .../PartitionPlanTableRepositoryTest.java | 58 ++++++++ .../i18n/BusinessMessages.properties | 4 + .../i18n/BusinessMessages_zh_CN.properties | 4 + .../i18n/BusinessMessages_zh_TW.properties | 3 + .../common/V_4_2_4_4__alter_partitionplan.sql | 39 ++++++ .../v2/ConnectSessionController.java | 11 ++ .../web/controller/v2/DBTableController.java | 8 ++ .../controller/v2/FlowInstanceController.java | 9 ++ .../v2/PartitionPlanController.java | 9 ++ .../partitionplan/PartitionPlanEntity.java | 80 +++++++++++ .../PartitionPlanRepository.java | 30 ++++ .../PartitionPlanTableEntity.java | 74 ++++++++++ .../PartitionPlanTablePartitionKeyEntity.java | 80 +++++++++++ ...titionPlanTablePartitionKeyRepository.java | 31 +++++ .../PartitionPlanTableRepository.java | 30 ++++ .../odc/service/db/DBTableService.java | 17 +-- .../model/PartitionPlanConfig.java | 53 +++++++ .../model/PartitionPlanDBTable.java | 131 ++++++++++++++++++ .../model/PartitionPlanDBTablePartition.java | 42 ++++++ .../model/PartitionPlanKeyConfig.java | 44 ++++++ .../model/PartitionPlanPreViewResp.java | 40 ++++++ .../model/PartitionPlanStrategy.java | 34 +++++ .../model/PartitionPlanTableConfig.java | 57 ++++++++ .../model/PartitionPlanVariable.java | 45 ++++++ .../model/PartitionPlanVariableKey.java | 54 ++++++++ .../datatype/PartitionPlanCharType.java | 54 ++++++++ .../datatype/PartitionPlanCustomType.java | 56 ++++++++ .../datatype/PartitionPlanDataType.java | 35 +++++ .../datatype/PartitionPlanNumberType.java | 57 ++++++++ .../datatype/PartitionPlanTimeType.java | 62 +++++++++ 32 files changed, 1357 insertions(+), 10 deletions(-) create mode 100644 server/integration-test/src/test/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanRepositoryTest.java create mode 100644 server/integration-test/src/test/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTablePartitionKeyRepositoryTest.java create mode 100644 server/integration-test/src/test/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTableRepositoryTest.java create mode 100644 server/odc-migrate/src/main/resources/migrate/common/V_4_2_4_4__alter_partitionplan.sql create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanEntity.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanRepository.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTableEntity.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTablePartitionKeyEntity.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTablePartitionKeyRepository.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTableRepository.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanConfig.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanDBTable.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanDBTablePartition.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanKeyConfig.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanPreViewResp.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanStrategy.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanTableConfig.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanVariable.java create mode 100644 server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanVariableKey.java create mode 100644 server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanCharType.java create mode 100644 server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanCustomType.java create mode 100644 server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanDataType.java create mode 100644 server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanNumberType.java create mode 100644 server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanTimeType.java diff --git a/server/integration-test/src/test/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanRepositoryTest.java b/server/integration-test/src/test/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanRepositoryTest.java new file mode 100644 index 0000000000..9ef3186f44 --- /dev/null +++ b/server/integration-test/src/test/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanRepositoryTest.java @@ -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 expect = this.repository.findById(actual.getId()); + Assert.assertEquals(expect.get(), actual); + } + + private PartitionPlanEntity createRoleEntity() { + return TestRandom.nextObject(PartitionPlanEntity.class); + } + +} diff --git a/server/integration-test/src/test/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTablePartitionKeyRepositoryTest.java b/server/integration-test/src/test/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTablePartitionKeyRepositoryTest.java new file mode 100644 index 0000000000..73cfa59d9a --- /dev/null +++ b/server/integration-test/src/test/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTablePartitionKeyRepositoryTest.java @@ -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 expect = this.repository.findById(actual.getId()); + Assert.assertEquals(expect.get(), actual); + } + + private PartitionPlanTablePartitionKeyEntity createRoleEntity() { + return TestRandom.nextObject(PartitionPlanTablePartitionKeyEntity.class); + } + +} diff --git a/server/integration-test/src/test/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTableRepositoryTest.java b/server/integration-test/src/test/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTableRepositoryTest.java new file mode 100644 index 0000000000..7b5cbc4165 --- /dev/null +++ b/server/integration-test/src/test/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTableRepositoryTest.java @@ -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 expect = this.repository.findById(actual.getId()); + Assert.assertEquals(expect.get(), actual); + } + + private PartitionPlanTableEntity createRoleEntity() { + return TestRandom.nextObject(PartitionPlanTableEntity.class); + } + +} diff --git a/server/odc-core/src/main/resources/i18n/BusinessMessages.properties b/server/odc-core/src/main/resources/i18n/BusinessMessages.properties index 6e97d6441c..f7f09ccc8e 100644 --- a/server/odc-core/src/main/resources/i18n/BusinessMessages.properties +++ b/server/odc-core/src/main/resources/i18n/BusinessMessages.properties @@ -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 + diff --git a/server/odc-core/src/main/resources/i18n/BusinessMessages_zh_CN.properties b/server/odc-core/src/main/resources/i18n/BusinessMessages_zh_CN.properties index 8f4f6b93cf..e140ed84b5 100644 --- a/server/odc-core/src/main/resources/i18n/BusinessMessages_zh_CN.properties +++ b/server/odc-core/src/main/resources/i18n/BusinessMessages_zh_CN.properties @@ -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=最后一个分区规则对应位置表达式的值 + diff --git a/server/odc-core/src/main/resources/i18n/BusinessMessages_zh_TW.properties b/server/odc-core/src/main/resources/i18n/BusinessMessages_zh_TW.properties index 2a1c3eb942..3e99459ff2 100644 --- a/server/odc-core/src/main/resources/i18n/BusinessMessages_zh_TW.properties +++ b/server/odc-core/src/main/resources/i18n/BusinessMessages_zh_TW.properties @@ -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=最後一個分區規則對應位置表達式的值 diff --git a/server/odc-migrate/src/main/resources/migrate/common/V_4_2_4_4__alter_partitionplan.sql b/server/odc-migrate/src/main/resources/migrate/common/V_4_2_4_4__alter_partitionplan.sql new file mode 100644 index 0000000000..4889e18fa4 --- /dev/null +++ b/server/odc-migrate/src/main/resources/migrate/common/V_4_2_4_4__alter_partitionplan.sql @@ -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`) +); diff --git a/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/ConnectSessionController.java b/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/ConnectSessionController.java index 4e270abb50..fd207d4dbd 100644 --- a/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/ConnectSessionController.java +++ b/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/ConnectSessionController.java @@ -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; @@ -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; @@ -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; @@ -229,4 +233,11 @@ public SuccessResponse queryTableOrViewData(@PathVariable Stri public SuccessResponse currentSessionStatus(@PathVariable String sessionId) { return Responses.success(sessionService.currentDBSession(sessionId)); } + + @PostMapping(value = "/sessions/{sessionId}/partitionPlans/latest/preview") + public ListResponse getPreView(@RequestBody List tableConfigs, + @RequestParam(name = "onlyForPartitionName", defaultValue = "false") Boolean onlyForPartitionName) { + throw new NotImplementedException(); + } + } diff --git a/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/DBTableController.java b/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/DBTableController.java index de6490cb89..7fb6842a21 100644 --- a/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/DBTableController.java +++ b/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/DBTableController.java @@ -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; @@ -88,4 +90,10 @@ public SuccessResponse generateUpdateTableDDL(@PathVariabl return Responses.success(tableService.generateUpdateDDL(session, req)); } + @GetMapping(value = "/{sessionId}/databases/{databaseName}/candidatePartitionPlanTables") + public ListResponse listTables(@PathVariable String sessionId, + @PathVariable String databaseName) { + throw new NotImplementedException(); + } + } diff --git a/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/FlowInstanceController.java b/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/FlowInstanceController.java index 95698cd19d..5fbccedcdd 100644 --- a/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/FlowInstanceController.java +++ b/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/FlowInstanceController.java @@ -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; @@ -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; @@ -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; @@ -216,4 +219,10 @@ public ListResponse getQueryResult(@PathVariable Long id) thro public ListResponse getDownloadUrl(@PathVariable Long id, @RequestBody List objectId) { return Responses.list(flowTaskInstanceService.getAsyncDownloadUrl(id, objectId)); } + + @GetMapping(value = "/{id:[\\d]+}/tasks/partitionPlans/getDetail") + public SuccessResponse getPartitionPlan(@PathVariable Long flowInstanceId) { + throw new NotImplementedException(); + } + } diff --git a/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/PartitionPlanController.java b/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/PartitionPlanController.java index cf1d52b5ac..c227044d0d 100644 --- a/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/PartitionPlanController.java +++ b/server/odc-server/src/main/java/com/oceanbase/odc/server/web/controller/v2/PartitionPlanController.java @@ -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 @@ -50,4 +54,9 @@ public SuccessResponse exist(@RequestParam("databaseId") Long databaseI return Responses.success(partitionPlanService.hasConnectionPartitionPlan(databaseId)); } + @GetMapping(value = "/supportedVariables") + public ListResponse getSupportedVariables() { + throw new NotImplementedException(); + } + } diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanEntity.java b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanEntity.java new file mode 100644 index 0000000000..25ce071cff --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanEntity.java @@ -0,0 +1,80 @@ +/* + * 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.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.hibernate.annotations.Generated; +import org.hibernate.annotations.GenerationTime; + +import lombok.Data; + +/** + * {@link PartitionPlanEntity} + * + * @author yh263208 + * @date 2024-01-10 16:43 + * @since ODC_release_4.2.4 + */ +@Data +@Entity +@Table(name = "partitionplan") +public class PartitionPlanEntity { + @Id + @Column(name = "id", nullable = false) + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + /** + * Record insertion time + */ + @Generated(GenerationTime.ALWAYS) + @Column(name = "create_time", insertable = false, updatable = false, + columnDefinition = "datetime NOT NULL DEFAULT CURRENT_TIMESTAMP") + private Date createTime; + /** + * Record modification time + */ + @Generated(GenerationTime.ALWAYS) + @Column(name = "update_time", insertable = false, updatable = false, + columnDefinition = "datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") + private Date updateTime; + @Column(name = "flow_instance_id", nullable = false) + private long flowInstanceId; + /** + * Enabled or not + */ + @Column(name = "is_enabled", nullable = false) + private Boolean enabled; + /** + * Creator id, references odc_user_info(id) + */ + @Column(name = "creator_id", updatable = false, nullable = false) + private Long creatorId; + /** + * Last modifier id, references iam_user(id) + */ + @Column(name = "last_modifier_id", nullable = false) + private Long lastModifierId; + @Column(name = "database_id", nullable = false, updatable = false) + private Long databaseId; +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanRepository.java b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanRepository.java new file mode 100644 index 0000000000..d901f655c9 --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanRepository.java @@ -0,0 +1,30 @@ +/* + * 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 org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** + * {@link PartitionPlanRepository} + * + * @author yh263208 + * @date 2024-01-10 16:55 + * @since ODC_release_4.2.4 + */ +public interface PartitionPlanRepository extends JpaRepository, + JpaSpecificationExecutor { +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTableEntity.java b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTableEntity.java new file mode 100644 index 0000000000..b120d211d1 --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTableEntity.java @@ -0,0 +1,74 @@ +/* + * 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.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.hibernate.annotations.Generated; +import org.hibernate.annotations.GenerationTime; + +import lombok.Data; + +/** + * {@link PartitionPlanTableEntity} + * + * @author yh263208 + * @date 2024-01-10 16:47 + * @since ODC_release_4.2.4 + */ +@Data +@Entity +@Table(name = "partitionplan_table") +public class PartitionPlanTableEntity { + @Id + @Column(name = "id", nullable = false) + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + /** + * Record insertion time + */ + @Generated(GenerationTime.ALWAYS) + @Column(name = "create_time", insertable = false, updatable = false, + columnDefinition = "datetime NOT NULL DEFAULT CURRENT_TIMESTAMP") + private Date createTime; + /** + * Record modification time + */ + @Generated(GenerationTime.ALWAYS) + @Column(name = "update_time", insertable = false, updatable = false, + columnDefinition = "datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") + private Date updateTime; + @Column(name = "table_name", nullable = false) + private String tableName; + @Column(name = "partitionplan_id", nullable = false) + private long partitionPlanId; + @Column(name = "schedule_id", updatable = false) + private Long scheduleId; + /** + * Enabled or not + */ + @Column(name = "partition_name_invoker", nullable = false) + private Boolean partitionNameInvoker; + @Column(name = "partition_name_invoker_parameters", nullable = false) + private String partitionNameInvokerParameters; +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTablePartitionKeyEntity.java b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTablePartitionKeyEntity.java new file mode 100644 index 0000000000..a84e6a3df1 --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTablePartitionKeyEntity.java @@ -0,0 +1,80 @@ +/* + * 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.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +import org.hibernate.annotations.Generated; +import org.hibernate.annotations.GenerationTime; + +import com.oceanbase.odc.service.partitionplan.model.PartitionPlanStrategy; + +import lombok.Data; + +/** + * {@link PartitionPlanTablePartitionKeyEntity} + * + * @author yh263208 + * @date 2024-01-10 16:51 + * @since ODC_release_4.2.4 + */ +@Data +@Entity +@Table(name = "partitionplan_table_partitionkey") +public class PartitionPlanTablePartitionKeyEntity { + @Id + @Column(name = "id", nullable = false) + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + /** + * Record insertion time + */ + @Generated(GenerationTime.ALWAYS) + @Column(name = "create_time", insertable = false, updatable = false, + columnDefinition = "datetime NOT NULL DEFAULT CURRENT_TIMESTAMP") + private Date createTime; + /** + * Record modification time + */ + @Generated(GenerationTime.ALWAYS) + @Column(name = "update_time", insertable = false, updatable = false, + columnDefinition = "datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") + private Date updateTime; + @Column(name = "partition_key", nullable = false) + private String partitionKey; + + @Enumerated(value = EnumType.STRING) + @Column(name = "strategy", nullable = false, updatable = false) + private PartitionPlanStrategy strategy; + @Column(name = "partitionplan_table_id", nullable = false) + private long partitionplanTableId; + /** + * Enabled or not + */ + @Column(name = "partition_key_invoker", nullable = false) + private Boolean partitionKeyInvoker; + @Column(name = "partition_key_invoker_parameters", nullable = false) + private String partitionKeyInvokerParameters; +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTablePartitionKeyRepository.java b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTablePartitionKeyRepository.java new file mode 100644 index 0000000000..88f889229b --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTablePartitionKeyRepository.java @@ -0,0 +1,31 @@ +/* + * 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 org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** + * {@link PartitionPlanTablePartitionKeyRepository} + * + * @author yh263208 + * @date 2023-01-10 18:53 + * @since ODC_release_4.2.4 + */ +public interface PartitionPlanTablePartitionKeyRepository + extends JpaRepository, + JpaSpecificationExecutor { +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTableRepository.java b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTableRepository.java new file mode 100644 index 0000000000..19efe2433d --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/metadb/partitionplan/PartitionPlanTableRepository.java @@ -0,0 +1,30 @@ +/* + * 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 org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +/** + * {@link PartitionPlanTableRepository} + * + * @author yh263208 + * @date 2024-01-10 17:04 + * @since ODC_release_4.2.4 + */ +public interface PartitionPlanTableRepository extends JpaRepository, + JpaSpecificationExecutor { +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/db/DBTableService.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/db/DBTableService.java index a0add470e3..229da14cb9 100644 --- a/server/odc-service/src/main/java/com/oceanbase/odc/service/db/DBTableService.java +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/db/DBTableService.java @@ -140,18 +140,15 @@ public List listTables(@NotNull ConnectionSession connectionSession, St } public List listTables(@NotNull ConnectionSession connectionSession, String schemaName) { - return connectionSession.getSyncJdbcExecutor( - ConnectionSessionConstants.BACKEND_DS_KEY) + return connectionSession.getSyncJdbcExecutor(ConnectionSessionConstants.BACKEND_DS_KEY) .execute((ConnectionCallback>) con -> getTableExtensionPoint(connectionSession) .list(con, schemaName)) - .stream().map( - item -> { - DBTable table = new DBTable(); - table.setName(item.getName()); - table.setSchemaName(schemaName); - return table; - }) - .collect(Collectors.toList()); + .stream().map(item -> { + DBTable table = new DBTable(); + table.setName(item.getName()); + table.setSchemaName(schemaName); + return table; + }).collect(Collectors.toList()); } public GenerateTableDDLResp generateCreateDDL(@NotNull ConnectionSession session, @NotNull DBTable table) { diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanConfig.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanConfig.java new file mode 100644 index 0000000000..fd4f151033 --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanConfig.java @@ -0,0 +1,53 @@ +/* + * 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.service.partitionplan.model; + +import java.io.Serializable; +import java.util.List; + +import com.oceanbase.odc.core.flow.model.TaskParameters; +import com.oceanbase.odc.service.schedule.model.TriggerConfig; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * {@link PartitionPlanConfig} + * + * @author yh263208 + * @date 2024-01-09 16:32 + * @since ODC_release_4.2.4 + */ +@Getter +@Setter +@ToString +public class PartitionPlanConfig implements Serializable, TaskParameters { + + private static final long serialVersionUID = 7008051004183574287L; + private Long id; + private boolean enabled; + private Long databaseId; + private Long timeoutMillis; + /** + * (~, 0] -> ignore any errors (0, ~) -> meaningful value + */ + private Integer maxErrors = -1; + private TriggerConfig creationTrigger; + private TriggerConfig droppingTrigger; + private List partitionTableConfigs; + +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanDBTable.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanDBTable.java new file mode 100644 index 0000000000..aa3771729c --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanDBTable.java @@ -0,0 +1,131 @@ +/* + * 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.service.partitionplan.model; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +import org.apache.commons.collections4.CollectionUtils; + +import com.oceanbase.tools.dbbrowser.model.DBTable; +import com.oceanbase.tools.dbbrowser.model.DBTableColumn; +import com.oceanbase.tools.dbbrowser.model.DBTableIndex; +import com.oceanbase.tools.dbbrowser.model.DBTablePartition; +import com.oceanbase.tools.dbbrowser.model.DBTablePartitionOption; +import com.oceanbase.tools.dbbrowser.model.DBTablePartitionType; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; + +/** + * {@link PartitionPlanDBTable} + * + * @author yh263208 + * @date 2024-01-09 11:55 + * @since ODC_release_4.2.4 + * @see DBTable + */ +@Getter +@Setter +@EqualsAndHashCode(callSuper = true) +public class PartitionPlanDBTable extends DBTable { + + private boolean inTablegroup; + private List strategies; + + public boolean isContainsGlobalIndexes() { + List indexList = getIndexes(); + if (CollectionUtils.isEmpty(indexList)) { + return false; + } + return indexList.stream().anyMatch(i -> Boolean.TRUE.equals(i.getGlobal())); + } + + public boolean isContainsCreateStrategy() { + return CollectionUtils.containsAny(this.strategies, PartitionPlanStrategy.CREATE); + } + + public boolean isContainsDropStrategy() { + return CollectionUtils.containsAny(this.strategies, PartitionPlanStrategy.DROP); + } + + public boolean isRangePartitioned() { + DBTablePartition partition = getPartition(); + if (partition == null) { + return false; + } + DBTablePartitionType partitionType = partition.getPartitionOption().getType(); + return Objects.equals(DBTablePartitionType.RANGE, partitionType) + || Objects.equals(DBTablePartitionType.RANGE_COLUMNS, partitionType); + } + + public String getPartitionMode() { + DBTablePartition partition = getPartition(); + if (partition == null) { + return "0"; + } + int mode = 0; + DBTablePartitionOption option = partition.getPartitionOption(); + switch (option.getType()) { + case KEY: + mode |= 0x1; + break; + case HASH: + mode |= 0x2; + break; + case LIST: + mode |= 0x4; + break; + case RANGE: + mode |= 0x8; + break; + case LIST_COLUMNS: + mode |= 0x10; + break; + case RANGE_COLUMNS: + mode |= 0x20; + break; + default: + return "0"; + } + if (Boolean.TRUE.equals(partition.getSubpartitionTemplated())) { + mode |= 0x40; + } + StringBuilder builder = new StringBuilder(mode); + if (option.getExpression() != null) { + builder.insert(0, option.getExpression().hashCode()); + } + if (CollectionUtils.isNotEmpty(option.getColumnNames())) { + List columns = getColumns(); + Map colName2TypeName = new HashMap<>(); + if (CollectionUtils.isNotEmpty(columns)) { + colName2TypeName = columns.stream().collect( + Collectors.toMap(DBTableColumn::getName, DBTableColumn::getTypeName)); + } + StringBuilder tmp = new StringBuilder(); + for (String col : option.getColumnNames()) { + tmp.append(col).append(colName2TypeName.getOrDefault(col, "unknown")); + } + builder.insert(0, tmp.toString().hashCode()); + } + return builder.toString(); + } + +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanDBTablePartition.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanDBTablePartition.java new file mode 100644 index 0000000000..44b2b5cfc8 --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanDBTablePartition.java @@ -0,0 +1,42 @@ +/* + * 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.service.partitionplan.model; + +import java.util.List; + +import com.oceanbase.odc.plugin.task.api.partitionplan.datatype.PartitionPlanDataType; +import com.oceanbase.tools.dbbrowser.model.DBTablePartition; + +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; + +/** + * {@link PartitionPlanDBTablePartition} + * + * @author yh263208 + * @date 2024-01-09 14:12 + * @since ODC_release_4.2.4 + * @see DBTablePartition + */ +@Getter +@Setter +@EqualsAndHashCode(callSuper = true) +public class PartitionPlanDBTablePartition extends DBTablePartition { + + private List partitionKeyTypes; + +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanKeyConfig.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanKeyConfig.java new file mode 100644 index 0000000000..10193755b1 --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanKeyConfig.java @@ -0,0 +1,44 @@ +/* + * 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.service.partitionplan.model; + +import java.io.Serializable; +import java.util.Map; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * {@link PartitionPlanKeyConfig} + * + * @author yh263208 + * @date 2024-01-10 15:36 + * @since ODC_release_4.2.4 + * @see java.io.Serializable + */ +@Getter +@Setter +@ToString +public class PartitionPlanKeyConfig implements Serializable { + + private static final long serialVersionUID = 7176051008183974787L; + private PartitionPlanStrategy strategy; + private String partitionKey; + private String partitionKeyInvoker; + private Map partitionKeyInvokerParameters; + +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanPreViewResp.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanPreViewResp.java new file mode 100644 index 0000000000..cbd0d6ad92 --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanPreViewResp.java @@ -0,0 +1,40 @@ +/* + * 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.service.partitionplan.model; + +import java.util.List; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * {@link PartitionPlanPreViewResp} + * + * @author yh263208 + * @date 2024-01-10 16:13 + * @since ODC_release_4.2.4 + */ +@Getter +@Setter +@ToString +public class PartitionPlanPreViewResp { + + private String tableName; + private List sqls; + private String partitionName; + +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanStrategy.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanStrategy.java new file mode 100644 index 0000000000..a634edc5d4 --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanStrategy.java @@ -0,0 +1,34 @@ +/* + * 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.service.partitionplan.model; + +/** + * {@link PartitionPlanStrategy} + * + * @author yh263208 + * @date 2023-01-09 15:15 + * @since ODC_release_4.2.4 + */ +public enum PartitionPlanStrategy { + /** + * Create partitions + */ + CREATE, + /** + * Drop partitions + */ + DROP +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanTableConfig.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanTableConfig.java new file mode 100644 index 0000000000..14795581c0 --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanTableConfig.java @@ -0,0 +1,57 @@ +/* + * 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.service.partitionplan.model; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +import com.oceanbase.tools.dbbrowser.model.DBTablePartitionType; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; + +/** + * {@link PartitionPlanTableConfig} + * + * @author yh263208 + * @date 2024-01-09 16:49 + * @since ODC_release_4.2.4 + */ +@Getter +@Setter +@ToString +public class PartitionPlanTableConfig implements Serializable { + + private static final long serialVersionUID = 7099051008183574787L; + private Long id; + private boolean enabled; + private String tableName; + private DBTablePartitionType partitionType; + private List partitionKeyConfigs; + private String partitionNameInvoker; + private Map partitionNameInvokerParameters; + + public boolean isContainsCreateStrategy() { + return this.partitionKeyConfigs.stream().anyMatch(i -> i.getStrategy() == PartitionPlanStrategy.CREATE); + } + + public boolean isContainsDropStrategy() { + return this.partitionKeyConfigs.stream().anyMatch(i -> i.getStrategy() == PartitionPlanStrategy.DROP); + } + +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanVariable.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanVariable.java new file mode 100644 index 0000000000..97df0a5f03 --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanVariable.java @@ -0,0 +1,45 @@ +/* + * 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.service.partitionplan.model; + +import org.springframework.context.i18n.LocaleContextHolder; + +import lombok.NonNull; + +/** + * {@link PartitionPlanVariable} + * + * @author yh263208 + * @date 2024-01-09 16:14 + * @since ODC_release_4.2.4 + */ +public class PartitionPlanVariable { + + private final PartitionPlanVariableKey key; + + public PartitionPlanVariable(@NonNull PartitionPlanVariableKey key) { + this.key = key; + } + + public String getLocalizedDescription() { + return this.key.translate(new Object[] {}, LocaleContextHolder.getLocale()); + } + + public String getVariable() { + return this.key.getVariable(); + } + +} diff --git a/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanVariableKey.java b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanVariableKey.java new file mode 100644 index 0000000000..e48b0cd579 --- /dev/null +++ b/server/odc-service/src/main/java/com/oceanbase/odc/service/partitionplan/model/PartitionPlanVariableKey.java @@ -0,0 +1,54 @@ +/* + * 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.service.partitionplan.model; + +import com.oceanbase.odc.common.i18n.Translatable; + +/** + * {@link PartitionPlanVariableKey} + * + * @author yh263208 + * @date 2024-01-09 16:03 + * @since ODC_release_4.2.4 + * @see com.oceanbase.odc.common.i18n.Translatable + */ +public enum PartitionPlanVariableKey implements Translatable { + /** + * the value it depends on user's input + */ + INTERVAL, + /** + * value of last partition, eg. + * CREATE TABLE `range_parti_tbl` ( + * `id` varchar(64) DEFAULT NULL, + * `birthday` date NOT NULL + * ) partition by range columns(birthday)( + * partition p0 values less than ('2020-12-31'), + * partition p1 values less than ('2021-12-31')) + * the last partition's value is {@code '2021-12-31'} + */ + LAST_PARTITION_VALUE; + + @Override + public String code() { + return name(); + } + + public String getVariable() { + return "${" + name() + "}"; + } + +} diff --git a/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanCharType.java b/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanCharType.java new file mode 100644 index 0000000000..b6f7584399 --- /dev/null +++ b/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanCharType.java @@ -0,0 +1,54 @@ +/* + * 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.plugin.task.api.partitionplan.datatype; + +/** + * {@link PartitionPlanCharType} + * + * @author yh263208 + * @date 2024-01-11 20:55 + * @since ODC_release_4.2.4 + * @see PartitionPlanDataType + */ +public class PartitionPlanCharType implements PartitionPlanDataType { + + private final Integer width; + + public PartitionPlanCharType(Integer width) { + this.width = width; + } + + @Override + public String getName() { + return "CHAR"; + } + + @Override + public Integer getPrecision() { + return -1; + } + + @Override + public Integer getScale() { + return -1; + } + + @Override + public Integer getWidth() { + return this.width; + } + +} diff --git a/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanCustomType.java b/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanCustomType.java new file mode 100644 index 0000000000..0cce22e940 --- /dev/null +++ b/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanCustomType.java @@ -0,0 +1,56 @@ +/* + * 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.plugin.task.api.partitionplan.datatype; + +import lombok.NonNull; + +/** + * {@link PartitionPlanCustomType} + * + * @author yh263208 + * @date 2023-01-11 20:58 + * @since ODC_release_4.2.4 + * @see PartitionPlanDataType + */ +public class PartitionPlanCustomType implements PartitionPlanDataType { + + private final String name; + + public PartitionPlanCustomType(@NonNull String name) { + this.name = name; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public Integer getPrecision() { + return -1; + } + + @Override + public Integer getScale() { + return -1; + } + + @Override + public Integer getWidth() { + return -1; + } + +} diff --git a/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanDataType.java b/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanDataType.java new file mode 100644 index 0000000000..a7a3d077b5 --- /dev/null +++ b/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanDataType.java @@ -0,0 +1,35 @@ +/* + * 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.plugin.task.api.partitionplan.datatype; + +/** + * {@link PartitionPlanDataType} + * + * @author yh263208 + * @date 2024-01-09 15:35 + * @since ODC-release_4.2.4 + */ +public interface PartitionPlanDataType { + + String getName(); + + Integer getPrecision(); + + Integer getScale(); + + Integer getWidth(); + +} diff --git a/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanNumberType.java b/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanNumberType.java new file mode 100644 index 0000000000..f708c161ee --- /dev/null +++ b/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanNumberType.java @@ -0,0 +1,57 @@ +/* + * 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.plugin.task.api.partitionplan.datatype; + +import lombok.NonNull; + +/** + * {@link PartitionPlanNumberType} + * + * @author yh263208 + * @date 2024-01-09 15:46 + * @since ODC_release_4.2.4 + */ +public class PartitionPlanNumberType implements PartitionPlanDataType { + + private final Integer scale; + private final Integer precision; + + public PartitionPlanNumberType(@NonNull Integer precision, @NonNull Integer scale) { + this.scale = scale; + this.precision = precision; + } + + @Override + public Integer getScale() { + return this.scale; + } + + @Override + public Integer getWidth() { + return -1; + } + + @Override + public String getName() { + return "NUMBER"; + } + + @Override + public Integer getPrecision() { + return this.precision; + } + +} diff --git a/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanTimeType.java b/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanTimeType.java new file mode 100644 index 0000000000..bc4a1d6d02 --- /dev/null +++ b/server/plugins/task-plugin-api/src/main/java/com/oceanbase/odc/plugin/task/api/partitionplan/datatype/PartitionPlanTimeType.java @@ -0,0 +1,62 @@ +/* + * 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.plugin.task.api.partitionplan.datatype; + +import lombok.NonNull; + +/** + * {@link PartitionPlanTimeType} + * + * @author yh263208 + * @date 2024-01-09 15:38 + * @since ODC_release_4.2.4 + * @see PartitionPlanDataType + */ +public class PartitionPlanTimeType implements PartitionPlanDataType { + + public static final int YEAR = 0x1; + public static final int MONTH = 0x2 | YEAR; + public static final int DAY = 0x4 | MONTH; + public static final int HOUR = 0x8 | DAY; + public static final int MINUTE = 0x10 | HOUR; + public static final int SECOND = 0x20 | MINUTE; + private final int precision; + + public PartitionPlanTimeType(@NonNull int precision) { + this.precision = precision; + } + + @Override + public Integer getScale() { + return -1; + } + + @Override + public Integer getWidth() { + return -1; + } + + @Override + public String getName() { + return "TIME"; + } + + @Override + public Integer getPrecision() { + return this.precision; + } + +}