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 eeaa487d31f11b628be01846be54ede2cac21aa3
Author: Dorris Zhang <ruixuan.zh...@kyligence.io>
AuthorDate: Tue Dec 13 13:44:04 2022 +0800

    KYLIN-5456 fix duplicate key when exporting tds
---
 .../apache/kylin/rest/service/ModelTdsService.java |  38 +--
 .../apache/kylin/tool/bisync/SyncModelBuilder.java |  12 +-
 .../apache/kylin/tool/bisync/model/ColumnDef.java  |   6 +-
 .../service/ModelTdsServiceColumnNameTest.java     | 128 ++++++++++
 .../kylin/rest/service/ModelTdsServiceTest.java    |   6 +-
 .../metadata/_global/project/test_tds_export.json  |  35 +++
 .../8b6fa01d-1607-9459-81aa-115b9419b830.json      |  93 ++++++++
 .../8b6fa01d-1607-9459-81aa-115b9419b830.json      |  63 +++++
 .../8b6fa01d-1607-9459-81aa-115b9419b830.json      | 262 +++++++++++++++++++++
 .../test_tds_export/table/SSB.LINEORDER.json       | 113 +++++++++
 .../test_tds_export/table/SSB.P_LINEORDER.json     | 118 ++++++++++
 11 files changed, 847 insertions(+), 27 deletions(-)

diff --git 
a/src/modeling-service/src/main/java/org/apache/kylin/rest/service/ModelTdsService.java
 
b/src/modeling-service/src/main/java/org/apache/kylin/rest/service/ModelTdsService.java
index df277831e5..b28fe7a019 100644
--- 
a/src/modeling-service/src/main/java/org/apache/kylin/rest/service/ModelTdsService.java
+++ 
b/src/modeling-service/src/main/java/org/apache/kylin/rest/service/ModelTdsService.java
@@ -57,7 +57,6 @@ import org.apache.kylin.metadata.model.TableRef;
 import org.apache.kylin.metadata.model.TblColRef;
 import org.apache.kylin.metadata.model.util.ComputedColumnUtil;
 import org.apache.kylin.metadata.project.NProjectManager;
-import org.apache.kylin.metadata.project.ProjectInstance;
 import org.apache.kylin.metadata.realization.RealizationStatusEnum;
 import org.apache.kylin.rest.security.MutableAclRecord;
 import org.apache.kylin.rest.util.AclPermissionUtil;
@@ -106,24 +105,27 @@ public class ModelTdsService extends AbstractModelService 
{
     }
 
     public boolean preCheckNameConflict(SyncModel syncModel) {
-        ProjectInstance prjInstance = 
getManager(NProjectManager.class).getProject(syncModel.getProject());
-        boolean skipCheckTds = prjInstance.getConfig().skipCheckTds();
-        Set<String> measureNames = 
syncModel.getMetrics().stream().filter(measureDef -> !measureDef.isHidden())
-                .map(measureDef -> 
measureDef.getMeasure().getName()).collect(Collectors.toSet());
-        Map<String, ColumnDef> nameOfColDefMap = 
syncModel.getColumnDefMap().values().stream()
-                .collect(Collectors.toMap(ColumnDef::getColumnName, 
Function.identity()));
-        Sets.SetView<String> intersection = 
Sets.intersection(nameOfColDefMap.keySet(), measureNames);
-        if (skipCheckTds || CollectionUtils.isEmpty(intersection)) {
-            return true;
-        }
-
-        String name = intersection.iterator().next();
-        ColumnDef columnDef = nameOfColDefMap.get(name);
-        if (columnDef.isDimension()) {
-            throw new 
KylinException(MODEL_TDS_EXPORT_DIM_COL_AND_MEASURE_NAME_CONFLICT, name, name);
-        } else {
-            throw new 
KylinException(MODEL_TDS_EXPORT_COLUMN_AND_MEASURE_NAME_CONFLICT, name, name);
+        boolean skipCheckTds = 
NProjectManager.getProjectConfig(syncModel.getProject()).skipCheckTds();
+
+        if (!skipCheckTds) {
+            Set<String> measureNames = 
syncModel.getMetrics().stream().filter(measureDef -> !measureDef.isHidden())
+                    .map(measureDef -> 
measureDef.getMeasure().getName()).collect(Collectors.toSet());
+            Map<String, ColumnDef> nameOfColDefMap = 
syncModel.getColumnDefMap().values().stream()
+                    .filter(columnDef -> !columnDef.isHidden())
+                    .collect(Collectors.toMap(ColumnDef::getAliasDotColumn, 
Function.identity()));
+
+            nameOfColDefMap.forEach((aliasColName, columnDef) -> {
+                String name = aliasColName.split("\\.").length > 1 ? 
aliasColName.split("\\.")[1] : "";
+                if (measureNames.contains(name)) {
+                    if (columnDef.isDimension()) {
+                        throw new 
KylinException(MODEL_TDS_EXPORT_DIM_COL_AND_MEASURE_NAME_CONFLICT, name, name);
+                    } else {
+                        throw new 
KylinException(MODEL_TDS_EXPORT_COLUMN_AND_MEASURE_NAME_CONFLICT, name, name);
+                    }
+                }
+            });
         }
+        return true;
     }
 
     public SyncModel exportModel(SyncContext syncContext) {
diff --git 
a/src/modeling-service/src/main/java/org/apache/kylin/tool/bisync/SyncModelBuilder.java
 
b/src/modeling-service/src/main/java/org/apache/kylin/tool/bisync/SyncModelBuilder.java
index 74b402bc29..fa14d623cd 100644
--- 
a/src/modeling-service/src/main/java/org/apache/kylin/tool/bisync/SyncModelBuilder.java
+++ 
b/src/modeling-service/src/main/java/org/apache/kylin/tool/bisync/SyncModelBuilder.java
@@ -209,7 +209,9 @@ public class SyncModelBuilder {
         default:
             break;
         }
-        showDimsAndMeasures(columnDefMap, measureDefs, colsToShow, 
measuresToShow);
+        Set<String> dimensionSet = 
indexPlan.getModel().getEffectiveDimensions().values().stream()
+                .map(TblColRef::getAliasDotName).collect(Collectors.toSet());
+        showDimsAndMeasures(columnDefMap, measureDefs, colsToShow, 
measuresToShow, dimensionSet);
     }
 
     private boolean testAuthorizedCols(Set<String> authorizedCols, TblColRef 
colRef) {
@@ -227,9 +229,13 @@ public class SyncModelBuilder {
     }
 
     private void showDimsAndMeasures(Map<String, ColumnDef> columnDefMap, 
List<MeasureDef> measureDefs,
-            Set<String> colsToShow, Set<String> measuresToShow) {
+            Set<String> colsToShow, Set<String> measuresToShow, Set<String> 
dimensionSet) {
         for (String colToShow : colsToShow) {
-            columnDefMap.get(colToShow).setHidden(false);
+            ColumnDef colToShowDef = columnDefMap.get(colToShow);
+            colToShowDef.setHidden(false);
+            if (dimensionSet.contains(colToShow)) {
+                colToShowDef.setDimension(true);
+            }
         }
         for (MeasureDef measureDef : measureDefs) {
             if (measuresToShow.contains(measureDef.getMeasure().getName())) {
diff --git 
a/src/modeling-service/src/main/java/org/apache/kylin/tool/bisync/model/ColumnDef.java
 
b/src/modeling-service/src/main/java/org/apache/kylin/tool/bisync/model/ColumnDef.java
index c67f56a432..89aa966aee 100644
--- 
a/src/modeling-service/src/main/java/org/apache/kylin/tool/bisync/model/ColumnDef.java
+++ 
b/src/modeling-service/src/main/java/org/apache/kylin/tool/bisync/model/ColumnDef.java
@@ -44,7 +44,9 @@ public class ColumnDef {
 
     private boolean isComputedColumn;
 
-    public boolean isDimension() {
-        return columnType.equalsIgnoreCase("nominal");
+    private boolean isDimension;
+
+    public String getAliasDotColumn() {
+        return this.getTableAlias() + "." + this.getColumnName();
     }
 }
diff --git 
a/src/modeling-service/src/test/java/org/apache/kylin/rest/service/ModelTdsServiceColumnNameTest.java
 
b/src/modeling-service/src/test/java/org/apache/kylin/rest/service/ModelTdsServiceColumnNameTest.java
new file mode 100644
index 0000000000..6a381fa564
--- /dev/null
+++ 
b/src/modeling-service/src/test/java/org/apache/kylin/rest/service/ModelTdsServiceColumnNameTest.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kylin.rest.service;
+
+import lombok.extern.slf4j.Slf4j;
+import org.apache.kylin.common.scheduler.EventBusFactory;
+import org.apache.kylin.engine.spark.ExecutableUtils;
+import org.apache.kylin.junit.rule.TransactionExceptedException;
+import org.apache.kylin.metadata.cube.model.NDataflowManager;
+import org.apache.kylin.metadata.recommendation.candidate.JdbcRawRecStore;
+import org.apache.kylin.rest.constant.Constant;
+import org.apache.kylin.rest.util.AclEvaluate;
+import org.apache.kylin.rest.util.AclUtil;
+import org.apache.kylin.tool.bisync.SyncContext;
+import org.apache.kylin.tool.bisync.model.SyncModel;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.springframework.security.authentication.TestingAuthenticationToken;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+import org.springframework.test.util.ReflectionTestUtils;
+
+@Slf4j
+public class ModelTdsServiceColumnNameTest extends SourceTestCase {
+
+    @InjectMocks
+    private final ModelService modelService = Mockito.spy(new ModelService());
+
+    @InjectMocks
+    private final ModelTdsService tdsService = Mockito.spy(new 
ModelTdsService());
+
+    @InjectMocks
+    private final ModelSemanticHelper semanticService = Mockito.spy(new 
ModelSemanticHelper());
+
+    @InjectMocks
+    private final IndexPlanService indexPlanService = Mockito.spy(new 
IndexPlanService());
+
+    @Mock
+    private final AclUtil aclUtil = Mockito.spy(AclUtil.class);
+
+    @Mock
+    private final AclEvaluate aclEvaluate = Mockito.spy(AclEvaluate.class);
+
+    @Mock
+    protected IUserGroupService userGroupService = 
Mockito.spy(NUserGroupService.class);
+
+    @Mock
+    private final AccessService accessService = 
Mockito.spy(AccessService.class);
+
+    @Rule
+    public TransactionExceptedException thrown = 
TransactionExceptedException.none();
+
+    protected String getProject() {
+        return "test_tds_export";
+    }
+
+    @Before
+    public void setup() {
+        ExecutableUtils.initJobFactory();
+        String localMetaDir = "src/test/resources/ut_meta/tds_export_test";
+        createTestMetadata(localMetaDir);
+        Authentication authentication = new 
TestingAuthenticationToken("ADMIN", "ADMIN", Constant.ROLE_ADMIN);
+        SecurityContextHolder.getContext().setAuthentication(authentication);
+
+        overwriteSystemProp("HADOOP_USER_NAME", "root");
+        ReflectionTestUtils.setField(aclEvaluate, "aclUtil", aclUtil);
+        ReflectionTestUtils.setField(modelService, "aclEvaluate", aclEvaluate);
+        ReflectionTestUtils.setField(modelService, "accessService", 
accessService);
+        ReflectionTestUtils.setField(modelService, "userGroupService", 
userGroupService);
+        ReflectionTestUtils.setField(modelService, "userGroupService", 
userGroupService);
+
+        ReflectionTestUtils.setField(tdsService, "accessService", 
accessService);
+        ReflectionTestUtils.setField(tdsService, "userGroupService", 
userGroupService);
+        ReflectionTestUtils.setField(tdsService, "aclEvaluate", aclEvaluate);
+
+        modelService.setSemanticUpdater(semanticService);
+        modelService.setIndexPlanService(indexPlanService);
+
+        try {
+            new JdbcRawRecStore(getTestConfig());
+        } catch (Exception e) {
+            //
+        }
+    }
+
+    @After
+    public void tearDown() {
+        getTestConfig().setProperty("kylin.metadata.semi-automatic-mode", 
"false");
+        EventBusFactory.getInstance().restart();
+        cleanupTestMetadata();
+    }
+
+    @Test
+    public void testDifferentTableSameColNameExportTds() {
+        String modelId = "8b6fa01d-1607-9459-81aa-115b9419b830";
+        SyncContext syncContext = new SyncContext();
+        syncContext.setProjectName(getProject());
+        syncContext.setModelId(modelId);
+        syncContext.setModelElement(SyncContext.ModelElement.AGG_INDEX_COL);
+        syncContext.setAdmin(true);
+        syncContext.setDataflow(NDataflowManager.getInstance(getTestConfig(), 
getProject()).getDataflow(modelId));
+        syncContext.setKylinConfig(getTestConfig());
+        SyncModel syncModel = tdsService.exportModel(syncContext);
+        Assert.assertTrue(tdsService.preCheckNameConflict(syncModel));
+    }
+}
diff --git 
a/src/modeling-service/src/test/java/org/apache/kylin/rest/service/ModelTdsServiceTest.java
 
b/src/modeling-service/src/test/java/org/apache/kylin/rest/service/ModelTdsServiceTest.java
index f1db49147f..b60753ea7b 100644
--- 
a/src/modeling-service/src/test/java/org/apache/kylin/rest/service/ModelTdsServiceTest.java
+++ 
b/src/modeling-service/src/test/java/org/apache/kylin/rest/service/ModelTdsServiceTest.java
@@ -192,7 +192,7 @@ public class ModelTdsServiceTest extends SourceTestCase {
     }
 
     @Test
-    public void testExportTDSWithDupMeasureColumnNames() throws IOException {
+    public void testExportTDSWithDupMeasureColumnNamesOutOfScope() throws 
IOException {
         String projectName = "default";
         String modelId = "2ed3bf12-ad40-e8a0-73da-8dc3b4c798bb";
         val modelRequest = JsonUtil.readValue(
@@ -213,9 +213,7 @@ public class ModelTdsServiceTest extends SourceTestCase {
         syncContext.setKylinConfig(getTestConfig());
         syncContext.setAdmin(true);
         SyncModel syncModel = tdsService.exportModel(syncContext);
-        Assert.assertThrows(
-                "There are duplicated names among model column LO_LINENUMBER 
and measure name LO_LINENUMBER. Cannot export a valid TDS file. Please correct 
the duplicated names and try again.",
-                KylinException.class, () -> 
tdsService.preCheckNameConflict(syncModel));
+        Assert.assertTrue(tdsService.preCheckNameConflict(syncModel));
     }
 
     @Test
diff --git 
a/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/_global/project/test_tds_export.json
 
b/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/_global/project/test_tds_export.json
new file mode 100644
index 0000000000..22d5d8bc18
--- /dev/null
+++ 
b/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/_global/project/test_tds_export.json
@@ -0,0 +1,35 @@
+{
+  "uuid" : "68c1c378-9bc0-e3a2-bb44-3d5bd23fc5ea",
+  "last_modified" : 1670814885403,
+  "create_time" : 1670814885385,
+  "version" : "4.0.0.0",
+  "name" : "test_tds_export",
+  "owner" : "ADMIN",
+  "status" : "ENABLED",
+  "create_time_utc" : 1670814885385,
+  "default_database" : "DEFAULT",
+  "description" : "",
+  "principal" : null,
+  "keytab" : null,
+  "maintain_model_type" : "MANUAL_MAINTAIN",
+  "override_kylin_properties" : {
+    "kylin.metadata.semi-automatic-mode" : "false",
+    "kylin.query.metadata.expose-computed-column" : "true",
+    "kylin.source.default" : "9"
+  },
+  "segment_config" : {
+    "auto_merge_enabled" : false,
+    "auto_merge_time_ranges" : [ "WEEK", "MONTH", "QUARTER", "YEAR" ],
+    "volatile_range" : {
+      "volatile_range_number" : 0,
+      "volatile_range_enabled" : false,
+      "volatile_range_type" : "DAY"
+    },
+    "retention_range" : {
+      "retention_range_number" : 1,
+      "retention_range_enabled" : false,
+      "retention_range_type" : "MONTH"
+    },
+    "create_empty_segment_enabled" : false
+  }
+}
diff --git 
a/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/dataflow/8b6fa01d-1607-9459-81aa-115b9419b830.json
 
b/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/dataflow/8b6fa01d-1607-9459-81aa-115b9419b830.json
new file mode 100644
index 0000000000..f441cd702a
--- /dev/null
+++ 
b/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/dataflow/8b6fa01d-1607-9459-81aa-115b9419b830.json
@@ -0,0 +1,93 @@
+{
+  "uuid" : "8b6fa01d-1607-9459-81aa-115b9419b830",
+  "last_modified" : 1670816215330,
+  "create_time" : 1670816130299,
+  "version" : "4.0.0.0",
+  "status" : "ONLINE",
+  "last_status" : null,
+  "cost" : 50,
+  "query_hit_count" : 0,
+  "last_query_time" : 0,
+  "layout_query_hit_count" : { },
+  "segments" : [ {
+    "id" : "7592350d-aed6-2ece-c99b-b0bf8002837b",
+    "name" : "FULL_BUILD",
+    "create_time_utc" : 1670816137816,
+    "status" : "READY",
+    "segRange" : {
+      "@class" : 
"org.apache.kylin.metadata.model.SegmentRange$TimePartitionedSegmentRange",
+      "date_range_start" : 0,
+      "date_range_end" : 9223372036854775807
+    },
+    "timeRange" : null,
+    "dimension_range_info_map" : {
+      "0" : {
+        "min" : "1",
+        "max" : "60000"
+      },
+      "1" : {
+        "min" : "1",
+        "max" : "2000"
+      },
+      "23" : {
+        "min" : "1",
+        "max" : "2000"
+      },
+      "24" : {
+        "min" : "1",
+        "max" : "60000"
+      },
+      "25" : {
+        "min" : "1",
+        "max" : "299"
+      },
+      "15" : {
+        "min" : "1",
+        "max" : "7"
+      },
+      "16" : {
+        "min" : "1",
+        "max" : "299"
+      },
+      "7" : {
+        "min" : "1",
+        "max" : "20"
+      },
+      "18" : {
+        "min" : "1",
+        "max" : "7"
+      },
+      "21" : {
+        "min" : "1",
+        "max" : "20"
+      }
+    },
+    "parameters" : null,
+    "dictionaries" : null,
+    "snapshots" : null,
+    "last_build_time" : 1670815943859,
+    "source_count" : 301389,
+    "source_bytes_size" : 11319910,
+    "column_source_bytes" : {
+      "SSB.P_LINEORDER.LO_ORDERKEY" : 140689,
+      "SSB.LINEORDER.LO_LINENUMBER" : 301389,
+      "SSB.P_LINEORDER.LO_CUSTKEY" : 149895,
+      "SSB.LINEORDER.LO_ORDERKEY" : 704647,
+      "SSB.LINEORDER.LO_SUPPKEY" : 475290,
+      "SSB.LINEORDER.LO_PARTKEY" : 1019900,
+      "SSB.P_LINEORDER.LO_PARTKEY" : 204053,
+      "SSB.LINEORDER.LO_CUSTKEY" : 750759,
+      "SSB.P_LINEORDER.LO_LINENUMBER" : 60175,
+      "SSB.P_LINEORDER.LO_SUPPKEY" : 94835
+    },
+    "ori_snapshot_size" : { },
+    "additionalInfo" : { },
+    "is_realtime_segment" : false,
+    "is_snapshot_ready" : false,
+    "is_dict_ready" : true,
+    "is_flat_table_ready" : true,
+    "is_fact_view_ready" : false,
+    "multi_partitions" : [ ],
+    "max_bucket_id" : -1
+  } ]
+}
diff --git 
a/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/index_plan/8b6fa01d-1607-9459-81aa-115b9419b830.json
 
b/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/index_plan/8b6fa01d-1607-9459-81aa-115b9419b830.json
new file mode 100644
index 0000000000..ab4d8dae82
--- /dev/null
+++ 
b/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/index_plan/8b6fa01d-1607-9459-81aa-115b9419b830.json
@@ -0,0 +1,63 @@
+{
+  "uuid" : "8b6fa01d-1607-9459-81aa-115b9419b830",
+  "last_modified" : 1670816130298,
+  "create_time" : 1670816130232,
+  "version" : "4.0.0.0",
+  "description" : null,
+  "rule_based_index" : null,
+  "indexes" : [ {
+    "id" : 0,
+    "dimensions" : [ 0, 1, 7, 15, 16, 18, 21, 23, 24, 25 ],
+    "measures" : [ 100000, 100001, 100002 ],
+    "layouts" : [ {
+      "id" : 1,
+      "name" : null,
+      "owner" : null,
+      "col_order" : [ 0, 1, 7, 15, 16, 18, 21, 23, 24, 25, 100000, 100001, 
100002 ],
+      "shard_by_columns" : [ ],
+      "partition_by_columns" : [ ],
+      "sort_by_columns" : [ ],
+      "storage_type" : 20,
+      "update_time" : 1670816130247,
+      "manual" : false,
+      "auto" : false,
+      "base" : true,
+      "draft_version" : null,
+      "index_range" : null
+    } ],
+    "next_layout_offset" : 2
+  }, {
+    "id" : 20000000000,
+    "dimensions" : [ 0, 1, 7, 15, 16, 18, 21, 23, 24, 25 ],
+    "measures" : [ ],
+    "layouts" : [ {
+      "id" : 20000000001,
+      "name" : null,
+      "owner" : null,
+      "col_order" : [ 0, 1, 7, 15, 16, 18, 21, 23, 24, 25 ],
+      "shard_by_columns" : [ ],
+      "partition_by_columns" : [ ],
+      "sort_by_columns" : [ ],
+      "storage_type" : 20,
+      "update_time" : 1670816130249,
+      "manual" : false,
+      "auto" : false,
+      "base" : true,
+      "draft_version" : null,
+      "index_range" : null
+    } ],
+    "next_layout_offset" : 2
+  } ],
+  "override_properties" : { },
+  "to_be_deleted_indexes" : [ ],
+  "auto_merge_time_ranges" : null,
+  "retention_range" : 0,
+  "engine_type" : 80,
+  "next_aggregation_index_id" : 10000,
+  "next_table_index_id" : 20000010000,
+  "agg_shard_by_columns" : [ ],
+  "extend_partition_columns" : [ ],
+  "layout_bucket_num" : { },
+  "approved_additional_recs" : 0,
+  "approved_removal_recs" : 0
+}
diff --git 
a/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/model_desc/8b6fa01d-1607-9459-81aa-115b9419b830.json
 
b/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/model_desc/8b6fa01d-1607-9459-81aa-115b9419b830.json
new file mode 100644
index 0000000000..45e14db8c3
--- /dev/null
+++ 
b/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/model_desc/8b6fa01d-1607-9459-81aa-115b9419b830.json
@@ -0,0 +1,262 @@
+{
+  "uuid" : "8b6fa01d-1607-9459-81aa-115b9419b830",
+  "last_modified" : 1670816130232,
+  "create_time" : 1670816130091,
+  "version" : "4.0.0.0",
+  "alias" : "model1",
+  "owner" : "ADMIN",
+  "config_last_modifier" : null,
+  "config_last_modified" : 0,
+  "description" : null,
+  "fact_table" : "SSB.LINEORDER",
+  "fact_table_alias" : null,
+  "management_type" : "MODEL_BASED",
+  "join_tables" : [ {
+    "table" : "SSB.P_LINEORDER",
+    "kind" : "LOOKUP",
+    "alias" : "P_LINEORDER",
+    "join" : {
+      "type" : "INNER",
+      "primary_key" : [ "P_LINEORDER.LO_ORDERKEY" ],
+      "foreign_key" : [ "LINEORDER.LO_ORDERKEY" ],
+      "non_equi_join_condition" : null,
+      "primary_table" : null,
+      "foreign_table" : null
+    },
+    "flattenable" : "flatten",
+    "join_relation_type" : "MANY_TO_ONE"
+  } ],
+  "filter_condition" : "",
+  "partition_desc" : null,
+  "capacity" : "MEDIUM",
+  "segment_config" : {
+    "auto_merge_enabled" : null,
+    "auto_merge_time_ranges" : null,
+    "volatile_range" : null,
+    "retention_range" : null,
+    "create_empty_segment_enabled" : false
+  },
+  "data_check_desc" : null,
+  "semantic_version" : 0,
+  "storage_type" : 0,
+  "model_type" : "BATCH",
+  "all_named_columns" : [ {
+    "id" : 0,
+    "name" : "LO_ORDERKEY_LINEORDER",
+    "column" : "LINEORDER.LO_ORDERKEY",
+    "status" : "DIMENSION"
+  }, {
+    "id" : 1,
+    "name" : "LO_PARTKEY_LINEORDER",
+    "column" : "LINEORDER.LO_PARTKEY",
+    "status" : "DIMENSION"
+  }, {
+    "id" : 2,
+    "name" : "LO_DISCOUNT_LINEORDER_1",
+    "column" : "LINEORDER.LO_DISCOUNT"
+  }, {
+    "id" : 3,
+    "name" : "LO_SUPPLYCOST_LINEORDER_1",
+    "column" : "LINEORDER.LO_SUPPLYCOST"
+  }, {
+    "id" : 4,
+    "name" : "LO_COMMITDATE_LINEORDER_1",
+    "column" : "LINEORDER.LO_COMMITDATE"
+  }, {
+    "id" : 5,
+    "name" : "LO_EXTENDEDPRICE_LINEORDER_1",
+    "column" : "LINEORDER.LO_EXTENDEDPRICE"
+  }, {
+    "id" : 6,
+    "name" : "LO_TAX_LINEORDER_1",
+    "column" : "LINEORDER.LO_TAX"
+  }, {
+    "id" : 7,
+    "name" : "LO_SUPPKEY_LINEORDER_1",
+    "column" : "LINEORDER.LO_SUPPKEY",
+    "status" : "DIMENSION"
+  }, {
+    "id" : 8,
+    "name" : "LO_ORDTOTALPRICE_LINEORDER_1",
+    "column" : "LINEORDER.LO_ORDTOTALPRICE"
+  }, {
+    "id" : 9,
+    "name" : "LO_REVENUE_LINEORDER_1",
+    "column" : "LINEORDER.LO_REVENUE"
+  }, {
+    "id" : 10,
+    "name" : "LO_ORDERDATE_LINEORDER_1",
+    "column" : "LINEORDER.LO_ORDERDATE"
+  }, {
+    "id" : 11,
+    "name" : "LO_ORDERPRIOTITY_LINEORDER_1",
+    "column" : "LINEORDER.LO_ORDERPRIOTITY"
+  }, {
+    "id" : 12,
+    "name" : "LO_SHIPPRIOTITY_LINEORDER_1",
+    "column" : "LINEORDER.LO_SHIPPRIOTITY"
+  }, {
+    "id" : 13,
+    "name" : "LO_QUANTITY_LINEORDER_1",
+    "column" : "LINEORDER.LO_QUANTITY"
+  }, {
+    "id" : 14,
+    "name" : "LO_SHIPMODE_LINEORDER_1",
+    "column" : "LINEORDER.LO_SHIPMODE"
+  }, {
+    "id" : 15,
+    "name" : "LO_LINENUMBER_LINEORDER",
+    "column" : "LINEORDER.LO_LINENUMBER",
+    "status" : "DIMENSION"
+  }, {
+    "id" : 16,
+    "name" : "LO_CUSTKEY_LINEORDER",
+    "column" : "LINEORDER.LO_CUSTKEY",
+    "status" : "DIMENSION"
+  }, {
+    "id" : 17,
+    "name" : "LO_SHIPMODE_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_SHIPMODE"
+  }, {
+    "id" : 18,
+    "name" : "LO_LINENUMBER_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_LINENUMBER",
+    "status" : "DIMENSION"
+  }, {
+    "id" : 19,
+    "name" : "LO_ORDTOTALPRICE_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_ORDTOTALPRICE"
+  }, {
+    "id" : 20,
+    "name" : "LO_SUPPLYCOST_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_SUPPLYCOST"
+  }, {
+    "id" : 21,
+    "name" : "LO_SUPPKEY_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_SUPPKEY",
+    "status" : "DIMENSION"
+  }, {
+    "id" : 22,
+    "name" : "LO_QUANTITY_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_QUANTITY"
+  }, {
+    "id" : 23,
+    "name" : "LO_PARTKEY_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_PARTKEY",
+    "status" : "DIMENSION"
+  }, {
+    "id" : 24,
+    "name" : "LO_ORDERKEY_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_ORDERKEY",
+    "status" : "DIMENSION"
+  }, {
+    "id" : 25,
+    "name" : "LO_CUSTKEY_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_CUSTKEY",
+    "status" : "DIMENSION"
+  }, {
+    "id" : 26,
+    "name" : "LO_SHIPPRIOTITY_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_SHIPPRIOTITY"
+  }, {
+    "id" : 27,
+    "name" : "LO_DISCOUNT_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_DISCOUNT"
+  }, {
+    "id" : 28,
+    "name" : "LO_ORDERPRIOTITY_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_ORDERPRIOTITY"
+  }, {
+    "id" : 29,
+    "name" : "LO_ORDERDATE_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_ORDERDATE"
+  }, {
+    "id" : 30,
+    "name" : "LO_REVENUE_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_REVENUE"
+  }, {
+    "id" : 31,
+    "name" : "V_REVENUE",
+    "column" : "P_LINEORDER.V_REVENUE"
+  }, {
+    "id" : 32,
+    "name" : "LO_COMMITDATE_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_COMMITDATE"
+  }, {
+    "id" : 33,
+    "name" : "LO_EXTENDEDPRICE_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_EXTENDEDPRICE"
+  }, {
+    "id" : 34,
+    "name" : "LO_TAX_P_LINEORDER_1",
+    "column" : "P_LINEORDER.LO_TAX"
+  } ],
+  "all_measures" : [ {
+    "name" : "COUNT_ALL",
+    "function" : {
+      "expression" : "COUNT",
+      "parameters" : [ {
+        "type" : "constant",
+        "value" : "1"
+      } ],
+      "returntype" : "bigint"
+    },
+    "column" : null,
+    "comment" : null,
+    "id" : 100000,
+    "type" : "NORMAL",
+    "internal_ids" : [ ]
+  }, {
+    "name" : "sum11",
+    "function" : {
+      "expression" : "SUM",
+      "parameters" : [ {
+        "type" : "column",
+        "value" : "LINEORDER.LO_LINENUMBER"
+      } ],
+      "returntype" : "bigint"
+    },
+    "column" : null,
+    "comment" : "",
+    "id" : 100001,
+    "type" : "NORMAL",
+    "internal_ids" : [ ]
+  }, {
+    "name" : "sum2",
+    "function" : {
+      "expression" : "SUM",
+      "parameters" : [ {
+        "type" : "column",
+        "value" : "P_LINEORDER.LO_LINENUMBER"
+      } ],
+      "returntype" : "bigint"
+    },
+    "column" : null,
+    "comment" : "",
+    "id" : 100002,
+    "type" : "NORMAL",
+    "internal_ids" : [ ]
+  } ],
+  "recommendations_count" : 0,
+  "computed_columns" : [ ],
+  "canvas" : {
+    "coordinate" : {
+      "LINEORDER" : {
+        "x" : 739.9444580078124,
+        "y" : 82.94443766276042,
+        "width" : 200.0,
+        "height" : 230.0
+      },
+      "P_LINEORDER" : {
+        "x" : 346.61112467447913,
+        "y" : 220.72221544053812,
+        "width" : 200.0,
+        "height" : 230.0
+      }
+    },
+    "zoom" : 9.0
+  },
+  "multi_partition_desc" : null,
+  "multi_partition_key_mapping" : null,
+  "fusion_id" : null
+}
diff --git 
a/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/table/SSB.LINEORDER.json
 
b/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/table/SSB.LINEORDER.json
new file mode 100644
index 0000000000..9b5626b915
--- /dev/null
+++ 
b/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/table/SSB.LINEORDER.json
@@ -0,0 +1,113 @@
+{
+  "uuid" : "2639d836-95e1-a1dc-850b-089a89825193",
+  "last_modified" : 0,
+  "create_time" : 1670815325493,
+  "version" : "4.0.0.0",
+  "name" : "LINEORDER",
+  "columns" : [ {
+    "id" : "1",
+    "name" : "LO_ORDERKEY",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_orderkey"
+  }, {
+    "id" : "2",
+    "name" : "LO_LINENUMBER",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_linenumber"
+  }, {
+    "id" : "3",
+    "name" : "LO_CUSTKEY",
+    "datatype" : "integer",
+    "case_sensitive_name" : "lo_custkey"
+  }, {
+    "id" : "4",
+    "name" : "LO_PARTKEY",
+    "datatype" : "integer",
+    "case_sensitive_name" : "lo_partkey"
+  }, {
+    "id" : "5",
+    "name" : "LO_SUPPKEY",
+    "datatype" : "integer",
+    "case_sensitive_name" : "lo_suppkey"
+  }, {
+    "id" : "6",
+    "name" : "LO_ORDERDATE",
+    "datatype" : "date",
+    "case_sensitive_name" : "lo_orderdate"
+  }, {
+    "id" : "7",
+    "name" : "LO_ORDERPRIOTITY",
+    "datatype" : "varchar(4096)",
+    "case_sensitive_name" : "lo_orderpriotity"
+  }, {
+    "id" : "8",
+    "name" : "LO_SHIPPRIOTITY",
+    "datatype" : "integer",
+    "case_sensitive_name" : "lo_shippriotity"
+  }, {
+    "id" : "9",
+    "name" : "LO_QUANTITY",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_quantity"
+  }, {
+    "id" : "10",
+    "name" : "LO_EXTENDEDPRICE",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_extendedprice"
+  }, {
+    "id" : "11",
+    "name" : "LO_ORDTOTALPRICE",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_ordtotalprice"
+  }, {
+    "id" : "12",
+    "name" : "LO_DISCOUNT",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_discount"
+  }, {
+    "id" : "13",
+    "name" : "LO_REVENUE",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_revenue"
+  }, {
+    "id" : "14",
+    "name" : "LO_SUPPLYCOST",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_supplycost"
+  }, {
+    "id" : "15",
+    "name" : "LO_TAX",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_tax"
+  }, {
+    "id" : "16",
+    "name" : "LO_COMMITDATE",
+    "datatype" : "date",
+    "case_sensitive_name" : "lo_commitdate"
+  }, {
+    "id" : "17",
+    "name" : "LO_SHIPMODE",
+    "datatype" : "varchar(4096)",
+    "case_sensitive_name" : "lo_shipmode"
+  } ],
+  "source_type" : 9,
+  "table_type" : "EXTERNAL",
+  "top" : false,
+  "increment_loading" : false,
+  "last_snapshot_path" : null,
+  "last_snapshot_size" : 0,
+  "snapshot_last_modified" : 0,
+  "query_hit_count" : 0,
+  "partition_column" : null,
+  "snapshot_partitions" : { },
+  "snapshot_partitions_info" : { },
+  "snapshot_total_rows" : 0,
+  "snapshot_partition_col" : null,
+  "selected_snapshot_partition_col" : null,
+  "temp_snapshot_path" : null,
+  "snapshot_has_broken" : false,
+  "database" : "SSB",
+  "transactional" : false,
+  "rangePartition" : false,
+  "partition_desc" : null
+}
diff --git 
a/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/table/SSB.P_LINEORDER.json
 
b/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/table/SSB.P_LINEORDER.json
new file mode 100644
index 0000000000..3f05465e97
--- /dev/null
+++ 
b/src/modeling-service/src/test/resources/ut_meta/tds_export_test/metadata/test_tds_export/table/SSB.P_LINEORDER.json
@@ -0,0 +1,118 @@
+{
+  "uuid" : "e0463929-d9c0-55ba-3c63-6cb0703053df",
+  "last_modified" : 1670836576389,
+  "create_time" : 1670815325386,
+  "version" : "4.0.0.0",
+  "name" : "P_LINEORDER",
+  "columns" : [ {
+    "id" : "1",
+    "name" : "LO_ORDERKEY",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_orderkey"
+  }, {
+    "id" : "2",
+    "name" : "LO_LINENUMBER",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_linenumber"
+  }, {
+    "id" : "3",
+    "name" : "LO_CUSTKEY",
+    "datatype" : "integer",
+    "case_sensitive_name" : "lo_custkey"
+  }, {
+    "id" : "4",
+    "name" : "LO_PARTKEY",
+    "datatype" : "integer",
+    "case_sensitive_name" : "lo_partkey"
+  }, {
+    "id" : "5",
+    "name" : "LO_SUPPKEY",
+    "datatype" : "integer",
+    "case_sensitive_name" : "lo_suppkey"
+  }, {
+    "id" : "6",
+    "name" : "LO_ORDERDATE",
+    "datatype" : "date",
+    "case_sensitive_name" : "lo_orderdate"
+  }, {
+    "id" : "7",
+    "name" : "LO_ORDERPRIOTITY",
+    "datatype" : "varchar(4096)",
+    "case_sensitive_name" : "lo_orderpriotity"
+  }, {
+    "id" : "8",
+    "name" : "LO_SHIPPRIOTITY",
+    "datatype" : "integer",
+    "case_sensitive_name" : "lo_shippriotity"
+  }, {
+    "id" : "9",
+    "name" : "LO_QUANTITY",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_quantity"
+  }, {
+    "id" : "10",
+    "name" : "LO_EXTENDEDPRICE",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_extendedprice"
+  }, {
+    "id" : "11",
+    "name" : "LO_ORDTOTALPRICE",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_ordtotalprice"
+  }, {
+    "id" : "12",
+    "name" : "LO_DISCOUNT",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_discount"
+  }, {
+    "id" : "13",
+    "name" : "LO_REVENUE",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_revenue"
+  }, {
+    "id" : "14",
+    "name" : "LO_SUPPLYCOST",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_supplycost"
+  }, {
+    "id" : "15",
+    "name" : "LO_TAX",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "lo_tax"
+  }, {
+    "id" : "16",
+    "name" : "LO_COMMITDATE",
+    "datatype" : "date",
+    "case_sensitive_name" : "lo_commitdate"
+  }, {
+    "id" : "17",
+    "name" : "LO_SHIPMODE",
+    "datatype" : "varchar(4096)",
+    "case_sensitive_name" : "lo_shipmode"
+  }, {
+    "id" : "18",
+    "name" : "V_REVENUE",
+    "datatype" : "bigint",
+    "case_sensitive_name" : "v_revenue"
+  } ],
+  "source_type" : 9,
+  "table_type" : "VIEW",
+  "top" : false,
+  "increment_loading" : false,
+  "last_snapshot_path" : 
"test_tds_export/table_snapshot/SSB.P_LINEORDER/162b8fce-4867-4322-9b5c-e1149784d478",
+  "last_snapshot_size" : 1867437,
+  "snapshot_last_modified" : 1670902544401,
+  "query_hit_count" : 0,
+  "partition_column" : null,
+  "snapshot_partitions" : { },
+  "snapshot_partitions_info" : { },
+  "snapshot_total_rows" : 0,
+  "snapshot_partition_col" : null,
+  "selected_snapshot_partition_col" : null,
+  "temp_snapshot_path" : null,
+  "snapshot_has_broken" : false,
+  "database" : "SSB",
+  "transactional" : false,
+  "rangePartition" : false,
+  "partition_desc" : null
+}


Reply via email to