You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by xx...@apache.org on 2023/02/27 08:00:52 UTC
[kylin] 12/34: KYLIN-5450 check if shard by columns included in col orders
This is an automated email from the ASF dual-hosted git repository.
xxyu pushed a commit to branch kylin5
in repository https://gitbox.apache.org/repos/asf/kylin.git
commit 5b41bca2aebfefdc7563ef19110c6ef7ec8c2dc6
Author: Dorris Zhang <ru...@kyligence.io>
AuthorDate: Mon Dec 26 19:16:29 2022 +0800
KYLIN-5450 check if shard by columns included in col orders
---
.../common/exception/code/ErrorCodeServer.java | 1 +
.../resources/kylin_error_msg_conf_cn.properties | 1 +
.../resources/kylin_error_msg_conf_en.properties | 1 +
.../main/resources/kylin_errorcode_conf.properties | 1 +
.../kylin/rest/controller/NIndexPlanController.java | 10 ++++++++++
.../rest/controller/IndexPlanControllerTest.java | 21 ++++++++++++++++++---
6 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/src/core-common/src/main/java/org/apache/kylin/common/exception/code/ErrorCodeServer.java b/src/core-common/src/main/java/org/apache/kylin/common/exception/code/ErrorCodeServer.java
index b5eb0fd98c..54f81183e7 100644
--- a/src/core-common/src/main/java/org/apache/kylin/common/exception/code/ErrorCodeServer.java
+++ b/src/core-common/src/main/java/org/apache/kylin/common/exception/code/ErrorCodeServer.java
@@ -107,6 +107,7 @@ public enum ErrorCodeServer implements ErrorCodeProducer {
RULE_BASED_INDEX_METADATA_INCONSISTENT("KE-010012201"),
INDEX_DUPLICATE("KE-010012202"),
INDEX_PARAMETER_INVALID("KE-010012203"),
+ SHARD_BY_COLUMN_NOT_IN_INDEX("KE-010012204"),
// 10043XX parameter check
REQUEST_PARAMETER_EMPTY_OR_VALUE_EMPTY("KE-010043201"),
diff --git a/src/core-common/src/main/resources/kylin_error_msg_conf_cn.properties b/src/core-common/src/main/resources/kylin_error_msg_conf_cn.properties
index be8bca221a..2768232b9d 100644
--- a/src/core-common/src/main/resources/kylin_error_msg_conf_cn.properties
+++ b/src/core-common/src/main/resources/kylin_error_msg_conf_cn.properties
@@ -109,6 +109,7 @@ KE-010010205=可计算列名和表达式不能为空。请检查后重试。
KE-010012201=索引元数据不一致。请尝试刷新下列模型的所有 Segment:项目[%s],模型[%s]。
KE-010012202=因为存在相同的索引,无法新建该索引。请修改。
KE-010012203=参数 “%s” 仅支持 “%s”。
+KE-010012204=ShardBy 列不在索引包含的列中,请修改后重试。
## 10043XX parameter check
KE-010043201=请求参数 “%s” 为空或值为空。请检查请求参数是否正确填写。
diff --git a/src/core-common/src/main/resources/kylin_error_msg_conf_en.properties b/src/core-common/src/main/resources/kylin_error_msg_conf_en.properties
index b44c0ef422..fc75aa0610 100644
--- a/src/core-common/src/main/resources/kylin_error_msg_conf_en.properties
+++ b/src/core-common/src/main/resources/kylin_error_msg_conf_en.properties
@@ -107,6 +107,7 @@ KE-010010205=Computed column names and expressions cannot be empty. Please check
KE-010012201=Index metadata might be inconsistent. Please try refreshing all segments in the following model: Project [%s], Model [%s].
KE-010012202=Can't add this index, as the same index already exists. Please modify.
KE-010012203=The parameter "%s" only supports "%s".
+KE-010012204=The ShardBy column is not included in the index. Please fix and try again.
## 10043XX parameter check
KE-010043201=Request parameter "%s" is empty or value is empty. Please check the request parameters.
diff --git a/src/core-common/src/main/resources/kylin_errorcode_conf.properties b/src/core-common/src/main/resources/kylin_errorcode_conf.properties
index 074fb6550e..976e342cc9 100644
--- a/src/core-common/src/main/resources/kylin_errorcode_conf.properties
+++ b/src/core-common/src/main/resources/kylin_errorcode_conf.properties
@@ -113,6 +113,7 @@ KE-010010205
KE-010012201
KE-010012202
KE-010012203
+KE-010012204
## 10043XX parameter check
KE-010043201
diff --git a/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NIndexPlanController.java b/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NIndexPlanController.java
index 24124071a5..3bca9f0ecf 100644
--- a/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NIndexPlanController.java
+++ b/src/metadata-server/src/main/java/org/apache/kylin/rest/controller/NIndexPlanController.java
@@ -21,6 +21,7 @@ package org.apache.kylin.rest.controller;
import static org.apache.kylin.common.constant.HttpConstant.HTTP_VND_APACHE_KYLIN_JSON;
import static org.apache.kylin.common.constant.HttpConstant.HTTP_VND_APACHE_KYLIN_V4_PUBLIC_JSON;
import static org.apache.kylin.common.exception.code.ErrorCodeServer.LAYOUT_LIST_EMPTY;
+import static org.apache.kylin.common.exception.code.ErrorCodeServer.SHARD_BY_COLUMN_NOT_IN_INDEX;
import java.util.List;
import java.util.Set;
@@ -143,10 +144,19 @@ public class NIndexPlanController extends NBasicController {
checkRequiredArg(MODEL_ID, request.getModelId());
checkRequiredArg("id", request.getId());
modelService.validateCCType(request.getModelId(), request.getProject());
+ List<String> shardByColumns = request.getShardByColumns();
+ List<String> colOrder = request.getColOrder();
+ checkShardbyCol(shardByColumns, colOrder);
val response = fusionIndexService.updateTableIndex(request.getProject(), request);
return new EnvelopeResponse<>(KylinException.CODE_SUCCESS, response, "");
}
+ private void checkShardbyCol(List<String> shardByColumns, List<String> colOrder) {
+ if (!colOrder.containsAll(shardByColumns)) {
+ throw new KylinException(SHARD_BY_COLUMN_NOT_IN_INDEX);
+ }
+ }
+
@Deprecated
@ApiOperation(value = "deleteTableIndex", tags = { "AI" }, notes = "Update URL: {project}, Update Param: project")
@DeleteMapping(value = "/table_index/{id:.+}")
diff --git a/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/IndexPlanControllerTest.java b/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/IndexPlanControllerTest.java
index 1acfb539ea..bcb9ef7ec1 100644
--- a/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/IndexPlanControllerTest.java
+++ b/src/metadata-server/src/test/java/org/apache/kylin/rest/controller/IndexPlanControllerTest.java
@@ -18,21 +18,25 @@
package org.apache.kylin.rest.controller;
import static org.apache.kylin.common.constant.HttpConstant.HTTP_VND_APACHE_KYLIN_JSON;
+import static org.apache.kylin.common.exception.code.ErrorCodeServer.SHARD_BY_COLUMN_NOT_IN_INDEX;
+import org.apache.kylin.common.exception.KylinException;
import org.apache.kylin.common.util.JsonUtil;
-import org.apache.kylin.common.util.Pair;
-import org.apache.kylin.rest.constant.Constant;
-import org.apache.kylin.rest.response.DiffRuleBasedIndexResponse;
import org.apache.kylin.common.util.NLocalFileMetadataTestCase;
+import org.apache.kylin.common.util.Pair;
import org.apache.kylin.metadata.cube.model.IndexEntity;
import org.apache.kylin.metadata.cube.model.IndexPlan;
+import org.apache.kylin.rest.constant.Constant;
import org.apache.kylin.rest.request.CreateBaseIndexRequest;
+import org.apache.kylin.rest.request.CreateTableIndexRequest;
import org.apache.kylin.rest.request.UpdateRuleBasedCuboidRequest;
import org.apache.kylin.rest.response.BuildIndexResponse;
+import org.apache.kylin.rest.response.DiffRuleBasedIndexResponse;
import org.apache.kylin.rest.service.FusionIndexService;
import org.apache.kylin.rest.service.IndexPlanService;
import org.apache.kylin.rest.service.ModelService;
import org.junit.After;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
@@ -156,4 +160,15 @@ public class IndexPlanControllerTest extends NLocalFileMetadataTestCase {
.accept(MediaType.parseMediaType(HTTP_VND_APACHE_KYLIN_JSON)))
.andExpect(MockMvcResultMatchers.status().isOk());
}
+
+ @Test
+ public void testUpdateTableIndex() {
+ CreateTableIndexRequest tableIndexRequest = CreateTableIndexRequest.builder().project("default")
+ .modelId("89af4ee2-2cdb-4b07-b39e-4c29856309aa").id(20000010000L)
+ .colOrder(Lists.newArrayList("1", "0", "2")).shardByColumns(Lists.newArrayList("4"))
+ .sortByColumns(Lists.newArrayList("0", "2")).build();
+ Assert.assertThrows(SHARD_BY_COLUMN_NOT_IN_INDEX.getMsg(), KylinException.class, () -> {
+ indexPlanController.updateTableIndex(tableIndexRequest);
+ });
+ }
}