KYLIN-2812, Fix the wrong destination database during load kafka topic (#2074)
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/e2e0102c Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/e2e0102c Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/e2e0102c Branch: refs/heads/2622-2764 Commit: e2e0102c4bac289c1e0d61226794030fd93cb145 Parents: ff4f634 Author: Billy(Yiming) Liu <liuyiming....@gmail.com> Authored: Sun Aug 27 18:51:50 2017 +0800 Committer: GitHub <nore...@github.com> Committed: Sun Aug 27 18:51:50 2017 +0800 ---------------------------------------------------------------------- .../rest/controller2/StreamingControllerV2.java | 3 +- .../controller/StreamingControllerTest.java | 52 ++++++++++++++++++++ 2 files changed, 53 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/e2e0102c/server-base/src/main/java/org/apache/kylin/rest/controller2/StreamingControllerV2.java ---------------------------------------------------------------------- diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller2/StreamingControllerV2.java b/server-base/src/main/java/org/apache/kylin/rest/controller2/StreamingControllerV2.java index 54733ea..90f2a45 100644 --- a/server-base/src/main/java/org/apache/kylin/rest/controller2/StreamingControllerV2.java +++ b/server-base/src/main/java/org/apache/kylin/rest/controller2/StreamingControllerV2.java @@ -247,10 +247,9 @@ public class StreamingControllerV2 extends BasicController { } if (null != desc) { - String[] dbTable = HadoopUtil.parseHiveTableName(desc.getName()); + String[] dbTable = HadoopUtil.parseHiveTableName(desc.getIdentity()); desc.setName(dbTable[1]); desc.setDatabase(dbTable[0]); - desc.getIdentity(); } return desc; } http://git-wip-us.apache.org/repos/asf/kylin/blob/e2e0102c/server-base/src/test/java/org/apache/kylin/rest/controller/StreamingControllerTest.java ---------------------------------------------------------------------- diff --git a/server-base/src/test/java/org/apache/kylin/rest/controller/StreamingControllerTest.java b/server-base/src/test/java/org/apache/kylin/rest/controller/StreamingControllerTest.java new file mode 100644 index 0000000..171d22e --- /dev/null +++ b/server-base/src/test/java/org/apache/kylin/rest/controller/StreamingControllerTest.java @@ -0,0 +1,52 @@ +/* + * 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.controller; + +import org.apache.kylin.common.util.HadoopUtil; +import org.apache.kylin.common.util.JsonUtil; +import org.apache.kylin.metadata.model.TableDesc; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; + +public class StreamingControllerTest { + + @Test + public void testReadTableDesc() throws IOException { + String requestTableData = "{\"name\":\"my_table_name\",\"source_type\":1,\"columns\":[{\"id\":1,\"name\":" + + "\"amount\",\"datatype\":\"decimal\"},{\"id\":2,\"name\":\"category\",\"datatype\":\"varchar(256)\"}," + + "{\"id\":3,\"name\":\"order_time\",\"datatype\":\"timestamp\"},{\"id\":4,\"name\":\"device\"," + + "\"datatype\":\"varchar(256)\"},{\"id\":5,\"name\":\"qty\",\"datatype\":\"int\"},{\"id\":6,\"name\":" + + "\"user_id\",\"datatype\":\"varchar(256)\"},{\"id\":7,\"name\":\"user_age\",\"datatype\":\"int\"}," + + "{\"id\":8,\"name\":\"user_gender\",\"datatype\":\"varchar(256)\"},{\"id\":9,\"name\":\"currency\"," + + "\"datatype\":\"varchar(256)\"},{\"id\":10,\"name\":\"country\",\"datatype\":\"varchar(256)\"}," + + "{\"id\":11,\"name\":\"year_start\",\"datatype\":\"date\"},{\"id\":12,\"name\":\"quarter_start\"," + + "\"datatype\":\"date\"},{\"id\":13,\"name\":\"month_start\",\"datatype\":\"date\"},{\"id\":14," + + "\"name\":\"week_start\",\"datatype\":\"date\"},{\"id\":15,\"name\":\"day_start\",\"datatype\":" + + "\"date\"},{\"id\":16,\"name\":\"hour_start\",\"datatype\":\"timestamp\"},{\"id\":17,\"name\":" + + "\"minute_start\",\"datatype\":\"timestamp\"}],\"database\":\"my_database_name\"}"; + TableDesc desc = JsonUtil.readValue(requestTableData, TableDesc.class); + String[] dbTable = HadoopUtil.parseHiveTableName(desc.getIdentity()); + desc.setName(dbTable[1]); + desc.setDatabase(dbTable[0]); + Assert.assertEquals("my_table_name".toUpperCase(), desc.getName()); + Assert.assertEquals("my_database_name".toUpperCase(), desc.getDatabase()); + } +}