You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by li...@apache.org on 2017/12/31 13:19:49 UTC
[32/50] [abbrv] kylin git commit: minor, add ut for load hive table.
minor, add ut for load hive table.
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/5aa80335
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/5aa80335
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/5aa80335
Branch: refs/heads/master
Commit: 5aa8033525c9223d305b233928e29ee32193715a
Parents: 19c4eb7
Author: tttMelody <24...@qq.com>
Authored: Tue Dec 26 11:14:57 2017 +0800
Committer: Hongbin Ma <ma...@kyligence.io>
Committed: Wed Dec 27 15:05:12 2017 +0800
----------------------------------------------------------------------
.../apache/kylin/rest/service/TableService.java | 55 +++++++++++---------
.../kylin/rest/service/TableServiceTest.java | 45 ++++++++++++++++
2 files changed, 75 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/5aa80335/server-base/src/main/java/org/apache/kylin/rest/service/TableService.java
----------------------------------------------------------------------
diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/TableService.java b/server-base/src/main/java/org/apache/kylin/rest/service/TableService.java
index 6bb446c..d218bc2 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/service/TableService.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/service/TableService.java
@@ -76,10 +76,6 @@ public class TableService extends BasicService {
private ModelService modelService;
@Autowired
- @Qualifier("projectService")
- private ProjectService projectService;
-
- @Autowired
@Qualifier("streamingMgmtService")
private StreamingService streamingService;
@@ -115,27 +111,11 @@ public class TableService extends BasicService {
public String[] loadHiveTablesToProject(String[] tables, String project) throws Exception {
aclEvaluate.checkProjectAdminPermission(project);
- // de-dup
- SetMultimap<String, String> db2tables = LinkedHashMultimap.create();
- for (String fullTableName : tables) {
- String[] parts = HadoopUtil.parseHiveTableName(fullTableName);
- db2tables.put(parts[0], parts[1]);
- }
+ List<Pair<TableDesc, TableExtDesc>> allMeta = getAllMeta(tables, project);
+ return loadHiveTablesToProject(project, allMeta);
+ }
- // load all tables first
- List<Pair<TableDesc, TableExtDesc>> allMeta = Lists.newArrayList();
- ISourceMetadataExplorer explr = SourceFactory.getDefaultSource().getSourceMetadataExplorer();
- for (Map.Entry<String, String> entry : db2tables.entries()) {
- Pair<TableDesc, TableExtDesc> pair = explr.loadTableMetadata(entry.getKey(), entry.getValue(), project);
- TableDesc tableDesc = pair.getFirst();
- Preconditions.checkState(tableDesc.getDatabase().equals(entry.getKey().toUpperCase()));
- Preconditions.checkState(tableDesc.getName().equals(entry.getValue().toUpperCase()));
- Preconditions.checkState(tableDesc.getIdentity().equals(entry.getKey().toUpperCase() + "." + entry
- .getValue().toUpperCase()));
- TableExtDesc extDesc = pair.getSecond();
- Preconditions.checkState(tableDesc.getIdentity().equals(extDesc.getIdentity()));
- allMeta.add(pair);
- }
+ String[] loadHiveTablesToProject(String project, List<Pair<TableDesc, TableExtDesc>> allMeta) throws Exception {
// do schema check
TableMetadataManager metaMgr = getTableManager();
@@ -181,7 +161,32 @@ public class TableService extends BasicService {
addTableToProject(result, project);
return result;
}
-
+
+ private List<Pair<TableDesc, TableExtDesc>> getAllMeta(String[] tables, String project) throws Exception {
+ // de-dup
+ SetMultimap<String, String> db2tables = LinkedHashMultimap.create();
+ for (String fullTableName : tables) {
+ String[] parts = HadoopUtil.parseHiveTableName(fullTableName);
+ db2tables.put(parts[0], parts[1]);
+ }
+
+ // load all tables first
+ List<Pair<TableDesc, TableExtDesc>> allMeta = Lists.newArrayList();
+ ISourceMetadataExplorer explr = SourceFactory.getDefaultSource().getSourceMetadataExplorer();
+ for (Map.Entry<String, String> entry : db2tables.entries()) {
+ Pair<TableDesc, TableExtDesc> pair = explr.loadTableMetadata(entry.getKey(), entry.getValue(), project);
+ TableDesc tableDesc = pair.getFirst();
+ Preconditions.checkState(tableDesc.getDatabase().equals(entry.getKey().toUpperCase()));
+ Preconditions.checkState(tableDesc.getName().equals(entry.getValue().toUpperCase()));
+ Preconditions.checkState(tableDesc.getIdentity().equals(entry.getKey().toUpperCase() + "." + entry
+ .getValue().toUpperCase()));
+ TableExtDesc extDesc = pair.getSecond();
+ Preconditions.checkState(tableDesc.getIdentity().equals(extDesc.getIdentity()));
+ allMeta.add(pair);
+ }
+ return allMeta;
+ }
+
public Map<String, String[]> loadHiveTables(String[] tableNames, String project, boolean isNeedProfile) throws Exception {
aclEvaluate.checkProjectAdminPermission(project);
String submitter = SecurityContextHolder.getContext().getAuthentication().getName();
http://git-wip-us.apache.org/repos/asf/kylin/blob/5aa80335/server/src/test/java/org/apache/kylin/rest/service/TableServiceTest.java
----------------------------------------------------------------------
diff --git a/server/src/test/java/org/apache/kylin/rest/service/TableServiceTest.java b/server/src/test/java/org/apache/kylin/rest/service/TableServiceTest.java
new file mode 100644
index 0000000..29ab5fd
--- /dev/null
+++ b/server/src/test/java/org/apache/kylin/rest/service/TableServiceTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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 com.google.common.collect.Lists;
+import org.apache.kylin.common.KylinConfig;
+import org.apache.kylin.common.util.Pair;
+import org.apache.kylin.metadata.TableMetadataManager;
+import org.apache.kylin.metadata.model.TableDesc;
+import org.apache.kylin.metadata.model.TableExtDesc;
+import org.junit.Assert;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+
+public class TableServiceTest extends ServiceTestBase {
+ @Autowired
+ @Qualifier("tableService")
+ private TableService tableService;
+
+ @Test
+ public void testLoadHiveTablesToProject() throws Exception {
+ TableMetadataManager tableMgr = TableMetadataManager.getInstance(KylinConfig.getInstanceFromEnv());
+ TableDesc tableDesc = tableMgr.getTableDesc("TEST_KYLIN_FACT", "default");
+ TableExtDesc tableExt = tableMgr.getTableExt(tableDesc);
+ String[] defaults = tableService.loadHiveTablesToProject("default", Lists.newArrayList(Pair.newPair(tableDesc, tableExt)));
+ Assert.assertEquals("DEFAULT.TEST_KYLIN_FACT", defaults[0]);
+ }
+}