kylin-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] shaofengshi closed pull request #364: KYLIN-3559 Use Splitter for splitting String
Date Wed, 28 Nov 2018 00:49:44 GMT
shaofengshi closed pull request #364: KYLIN-3559 Use Splitter for splitting String
URL: https://github.com/apache/kylin/pull/364
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/core-common/src/main/java/org/apache/kylin/common/util/StringUtil.java b/core-common/src/main/java/org/apache/kylin/common/util/StringUtil.java
index 84c1da5919..4fc37c9154 100644
--- a/core-common/src/main/java/org/apache/kylin/common/util/StringUtil.java
+++ b/core-common/src/main/java/org/apache/kylin/common/util/StringUtil.java
@@ -22,6 +22,9 @@
 import java.util.Collection;
 
 import java.util.Locale;
+
+import com.google.common.base.Splitter;
+import com.google.common.collect.Iterables;
 import org.apache.commons.lang.StringUtils;
 
 /**
@@ -159,14 +162,17 @@ public static void appendWithSeparator(StringBuilder src, String append)
{
     }
 
     public static String[] splitAndTrim(String str, String splitBy) {
-        String[] split = str.split(splitBy);
-        ArrayList<String> r = new ArrayList<>(split.length);
-        for (String s : split) {
-            s = s.trim();
-            if (!s.isEmpty())
-                r.add(s);
-        }
-        return r.toArray(new String[r.size()]);
+        Splitter splitterWithTrim = Splitter.on(splitBy).trimResults().omitEmptyStrings();
+
+        return Iterables.toArray(splitterWithTrim.split(str), String.class);
+    }
+
+    public static String[] split(String str, String splitBy) {
+        return Iterables.toArray(Splitter.on(splitBy).split(str), String.class);
+    }
+
+    public static String[] splitByComma(String str) {
+        return split(str, ",");
     }
 
     // calculating length in UTF-8 of Java String without actually encoding it
diff --git a/core-common/src/test/java/org/apache/kylin/common/util/StringUtilTest.java b/core-common/src/test/java/org/apache/kylin/common/util/StringUtilTest.java
new file mode 100644
index 0000000000..88ed9d84a8
--- /dev/null
+++ b/core-common/src/test/java/org/apache/kylin/common/util/StringUtilTest.java
@@ -0,0 +1,53 @@
+/*
+ * 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.common.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class StringUtilTest {
+    @Test
+    public void splitTest() {
+        String normalText = "Try to make the code better";
+        String[] expected = new String[] { "Try", "to", "make", "the", "code", "better" };
+        Assert.assertArrayEquals(expected, StringUtil.split(normalText, " "));
+
+        // case in http://errorprone.info/bugpattern/StringSplitter
+        expected = new String[] { "" };
+        Assert.assertArrayEquals(expected, StringUtil.split("", ":"));
+
+        expected = new String[] { "", "" };
+        Assert.assertArrayEquals(expected, StringUtil.split(":", ":"));
+
+        expected = new String[] { "1", "2" };
+        Assert.assertArrayEquals(expected, StringUtil.split("1<|>2", "<|>"));
+    }
+
+    @Test
+    public void splitAndTrimTest() {
+        String[] expected = new String[] { "foo", "bar" };
+        Assert.assertArrayEquals(expected, StringUtil.splitAndTrim(" foo... bar. ", "."));
+    }
+
+    @Test
+    public void splitByCommaTest() {
+        String[] expected = new String[] { "Hello", "Kylin" };
+        Assert.assertArrayEquals(expected, StringUtil.splitByComma("Hello,Kylin"));
+    }
+}
diff --git a/core-cube/src/main/java/org/apache/kylin/cube/cli/CubeSignatureRefresher.java
b/core-cube/src/main/java/org/apache/kylin/cube/cli/CubeSignatureRefresher.java
index 2eaebb1a9a..b149f11dec 100644
--- a/core-cube/src/main/java/org/apache/kylin/cube/cli/CubeSignatureRefresher.java
+++ b/core-cube/src/main/java/org/apache/kylin/cube/cli/CubeSignatureRefresher.java
@@ -24,6 +24,7 @@
 import org.apache.commons.lang.ArrayUtils;
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.persistence.ResourceStore;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.cube.CubeDescManager;
 import org.apache.kylin.cube.CubeManager;
 import org.apache.kylin.cube.model.CubeDesc;
@@ -61,7 +62,7 @@ public void update() {
         if (ArrayUtils.isEmpty(cubeNames)) {
             cubeDescs = cubeDescManager.listAllDesc();
         } else {
-            String[] names = cubeNames[0].split(",");
+            String[] names = StringUtil.splitByComma(cubeNames[0]);
             if (ArrayUtils.isEmpty(names))
                 return;
             cubeDescs = Lists.newArrayListWithCapacity(names.length);
diff --git a/core-job/src/main/java/org/apache/kylin/job/impl/threadpool/DistributedScheduler.java
b/core-job/src/main/java/org/apache/kylin/job/impl/threadpool/DistributedScheduler.java
index d6f9fe2c08..a9988734f8 100644
--- a/core-job/src/main/java/org/apache/kylin/job/impl/threadpool/DistributedScheduler.java
+++ b/core-job/src/main/java/org/apache/kylin/job/impl/threadpool/DistributedScheduler.java
@@ -36,6 +36,7 @@
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.lock.DistributedLock;
 import org.apache.kylin.common.util.SetThreadName;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.job.Scheduler;
 import org.apache.kylin.job.engine.JobEngineConfig;
 import org.apache.kylin.job.exception.ExecuteException;
@@ -150,7 +151,7 @@ public WatcherProcessImpl(String serverName) {
 
         @Override
         public void onUnlock(String path, String nodeData) {
-            String[] paths = path.split("/");
+            String[] paths = StringUtil.split(path, "/");
             String jobId = paths[paths.length - 1];
 
             final Output output = executableManager.getOutput(jobId);
diff --git a/engine-mr/src/main/java/org/apache/kylin/engine/mr/LookupMaterializeContext.java
b/engine-mr/src/main/java/org/apache/kylin/engine/mr/LookupMaterializeContext.java
index f235283576..4fa9126a1e 100644
--- a/engine-mr/src/main/java/org/apache/kylin/engine/mr/LookupMaterializeContext.java
+++ b/engine-mr/src/main/java/org/apache/kylin/engine/mr/LookupMaterializeContext.java
@@ -21,6 +21,7 @@
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.job.execution.DefaultChainedExecutable;
 
 import com.google.common.collect.Maps;
@@ -74,9 +75,9 @@ public String getAllLookupSnapshotsInString() {
      */
     public static Map<String, String> parseLookupSnapshots(String snapshotsString)
{
         Map<String, String> lookupSnapshotMap = Maps.newHashMap();
-        String[] lookupSnapshotEntries = snapshotsString.split(",");
+        String[] lookupSnapshotEntries = StringUtil.splitByComma(snapshotsString);
         for (String lookupSnapshotEntryStr : lookupSnapshotEntries) {
-            String[] split = lookupSnapshotEntryStr.split("=");
+            String[] split = StringUtil.split(lookupSnapshotEntryStr, "=");
             lookupSnapshotMap.put(split[0], split[1]);
         }
         return lookupSnapshotMap;
diff --git a/engine-mr/src/main/java/org/apache/kylin/engine/mr/common/AbstractHadoopJob.java
b/engine-mr/src/main/java/org/apache/kylin/engine/mr/common/AbstractHadoopJob.java
index 6a9158d609..7c769bc929 100644
--- a/engine-mr/src/main/java/org/apache/kylin/engine/mr/common/AbstractHadoopJob.java
+++ b/engine-mr/src/main/java/org/apache/kylin/engine/mr/common/AbstractHadoopJob.java
@@ -324,7 +324,7 @@ private void setJobTmpJarsAndFiles(Job job, String kylinDependency) {
             StringBuilder jarList = new StringBuilder();
             StringBuilder fileList = new StringBuilder();
 
-            for (String fileName : kylinDependency.split(",")) {
+            for (String fileName : StringUtil.splitAndTrim(kylinDependency, ",")) {
                 Path p = new Path(fileName);
                 if (p.isAbsolute() == false) {
                     logger.warn("The directory of kylin dependency '" + fileName + "' is
not absolute, skip");
diff --git a/engine-mr/src/main/java/org/apache/kylin/engine/mr/steps/MergeDictionaryMapper.java
b/engine-mr/src/main/java/org/apache/kylin/engine/mr/steps/MergeDictionaryMapper.java
index 522c06a491..c55f4d2cd0 100644
--- a/engine-mr/src/main/java/org/apache/kylin/engine/mr/steps/MergeDictionaryMapper.java
+++ b/engine-mr/src/main/java/org/apache/kylin/engine/mr/steps/MergeDictionaryMapper.java
@@ -42,6 +42,7 @@
 import org.apache.kylin.common.util.ByteArray;
 import org.apache.kylin.common.util.Bytes;
 import org.apache.kylin.common.util.HadoopUtil;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.cube.CubeDescManager;
 import org.apache.kylin.cube.CubeInstance;
 import org.apache.kylin.cube.CubeManager;
@@ -82,7 +83,7 @@ protected void doSetup(Context context) throws IOException, InterruptedException
         final CubeInstance cubeInstance = CubeManager.getInstance(kylinConfig).getCube(cubeName);
         final CubeDesc cubeDesc = CubeDescManager.getInstance(kylinConfig).getCubeDesc(cubeInstance.getDescName());
 
-        mergingSegments = getMergingSegments(cubeInstance, segmentIds.split(","));
+        mergingSegments = getMergingSegments(cubeInstance, StringUtil.splitByComma(segmentIds));
         tblColRefs = cubeDesc.getAllColumnsNeedDictionaryBuilt().toArray(new TblColRef[0]);
         dictMgr = DictionaryManager.getInstance(kylinConfig);
     }
@@ -114,11 +115,14 @@ protected void doMap(IntWritable key, NullWritable value, Context context)
 
         } else {
             // merge statistics
-            KylinConfig kylinConfig = AbstractHadoopJob.loadKylinConfigFromHdfs(new SerializableConfiguration(context.getConfiguration()),
context.getConfiguration().get(BatchConstants.ARG_META_URL));
+            KylinConfig kylinConfig = AbstractHadoopJob.loadKylinConfigFromHdfs(
+                    new SerializableConfiguration(context.getConfiguration()),
+                    context.getConfiguration().get(BatchConstants.ARG_META_URL));
 
             final String cubeName = context.getConfiguration().get(BatchConstants.ARG_CUBE_NAME);
             final String segmentId = context.getConfiguration().get(BatchConstants.ARG_SEGMENT_ID);
-            final String statOutputPath = context.getConfiguration().get(MergeDictionaryJob.OPTION_OUTPUT_PATH_STAT.getOpt());
+            final String statOutputPath = context.getConfiguration()
+                    .get(MergeDictionaryJob.OPTION_OUTPUT_PATH_STAT.getOpt());
             CubeInstance cubeInstance = CubeManager.getInstance(kylinConfig).getCube(cubeName);
 
             logger.info("Statistics output path: {}", statOutputPath);
@@ -179,8 +183,10 @@ protected void doMap(IntWritable key, NullWritable value, Context context)
             }
 
             averageSamplingPercentage = averageSamplingPercentage / mergingSegments.size();
-            CubeStatsWriter.writeCuboidStatistics(conf, new Path(statOutputPath), cuboidHLLMap,
averageSamplingPercentage);
-            Path statisticsFilePath = new Path(statOutputPath, BatchConstants.CFG_STATISTICS_CUBOID_ESTIMATION_FILENAME);
+            CubeStatsWriter.writeCuboidStatistics(conf, new Path(statOutputPath), cuboidHLLMap,
+                    averageSamplingPercentage);
+            Path statisticsFilePath = new Path(statOutputPath,
+                    BatchConstants.CFG_STATISTICS_CUBOID_ESTIMATION_FILENAME);
 
             FileSystem fs = HadoopUtil.getFileSystem(statisticsFilePath, conf);
             FSDataInputStream fis = fs.open(statisticsFilePath);
diff --git a/engine-mr/src/main/java/org/apache/kylin/engine/mr/steps/MergeDictionaryReducer.java
b/engine-mr/src/main/java/org/apache/kylin/engine/mr/steps/MergeDictionaryReducer.java
index 1eb3c07f20..15a346f50d 100644
--- a/engine-mr/src/main/java/org/apache/kylin/engine/mr/steps/MergeDictionaryReducer.java
+++ b/engine-mr/src/main/java/org/apache/kylin/engine/mr/steps/MergeDictionaryReducer.java
@@ -22,6 +22,7 @@
 
 import org.apache.hadoop.io.IntWritable;
 import org.apache.hadoop.io.Text;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.engine.mr.KylinReducer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -35,7 +36,7 @@ protected void doReduce(IntWritable key, Iterable<Text> values, Context
context)
             throws IOException, InterruptedException {
         for (Text text : values) {
             String value = text.toString();
-            String[] splited = value.split("=");
+            String[] splited = StringUtil.split(value, "=");
             if (splited != null && splited.length == 2) {
                 logger.info("Dictionary for col {}, save at {}", splited[0], splited[1]);
                 context.write(new Text(splited[0]), new Text(splited[1]));
diff --git a/engine-spark/src/main/java/org/apache/kylin/engine/spark/SparkMergingDictionary.java
b/engine-spark/src/main/java/org/apache/kylin/engine/spark/SparkMergingDictionary.java
index bbdeb85ecc..d473a0a42a 100644
--- a/engine-spark/src/main/java/org/apache/kylin/engine/spark/SparkMergingDictionary.java
+++ b/engine-spark/src/main/java/org/apache/kylin/engine/spark/SparkMergingDictionary.java
@@ -41,6 +41,7 @@
 import org.apache.kylin.common.util.Bytes;
 import org.apache.kylin.common.util.HadoopUtil;
 import org.apache.kylin.common.util.OptionsHelper;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.cube.CubeDescManager;
 import org.apache.kylin.cube.CubeInstance;
 import org.apache.kylin.cube.CubeManager;
@@ -151,7 +152,7 @@ protected void execute(OptionsHelper optionsHelper) throws Exception {
             JavaRDD<Integer> indexRDD = sc.parallelize(indexs, columnLength + 1);
 
             JavaPairRDD<Text, Text> colToDictPathRDD = indexRDD.mapToPair(new MergeDictAndStatsFunction(cubeName,
-                    metaUrl, segmentId, segmentIds.split(","), statOutputPath, tblColRefs,
sConf));
+                    metaUrl, segmentId, StringUtil.splitByComma(segmentIds), statOutputPath,
tblColRefs, sConf));
 
             colToDictPathRDD.coalesce(1, false).saveAsNewAPIHadoopFile(dictOutputPath, Text.class,
Text.class,
                     SequenceFileOutputFormat.class);
diff --git a/jdbc/src/main/java/org/apache/kylin/jdbc/KylinConnection.java b/jdbc/src/main/java/org/apache/kylin/jdbc/KylinConnection.java
index b2b3315225..b138ff30b6 100644
--- a/jdbc/src/main/java/org/apache/kylin/jdbc/KylinConnection.java
+++ b/jdbc/src/main/java/org/apache/kylin/jdbc/KylinConnection.java
@@ -27,6 +27,8 @@
 import java.util.Map;
 import java.util.Properties;
 
+import com.google.common.base.Splitter;
+import com.google.common.collect.Iterables;
 import org.apache.calcite.avatica.AvaticaConnection;
 import org.apache.calcite.avatica.AvaticaFactory;
 import org.apache.calcite.avatica.AvaticaParameter;
@@ -54,7 +56,7 @@ protected KylinConnection(UnregisteredDriver driver, JdbcFactory factory,
String
         String odbcUrl = url;
         odbcUrl = odbcUrl.replaceAll((Driver.CONNECT_STRING_PREFIX + "[[A-Za-z0-9]*=[A-Za-z0-9]*;]*//").toString(),
"");
 
-        String[] temps = odbcUrl.split("/");
+        String[] temps = Iterables.toArray(Splitter.on("/").split(odbcUrl), String.class);
         assert temps.length >= 2;
 
         this.project = temps[temps.length - 1];
diff --git a/kylin-it/src/test/java/org/apache/kylin/cube/cuboid/algorithm/ITAlgorithmTestBase.java
b/kylin-it/src/test/java/org/apache/kylin/cube/cuboid/algorithm/ITAlgorithmTestBase.java
index 1d6d0bc562..49023233dd 100755
--- a/kylin-it/src/test/java/org/apache/kylin/cube/cuboid/algorithm/ITAlgorithmTestBase.java
+++ b/kylin-it/src/test/java/org/apache/kylin/cube/cuboid/algorithm/ITAlgorithmTestBase.java
@@ -28,6 +28,7 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.cube.cuboid.TreeCuboidScheduler.CuboidCostComparator;
 import org.apache.kylin.cube.cuboid.TreeCuboidScheduler.CuboidTree;
 import org.junit.After;
@@ -94,7 +95,7 @@ public double getQueryCostRatio(CuboidStats cuboidStats, List<Long>
recommendLis
                     StandardCharsets.UTF_8));
 
             while ((sCurrentLine = br.readLine()) != null) {
-                String[] statPair = sCurrentLine.split(" ");
+                String[] statPair = StringUtil.split(sCurrentLine, " ");
                 countMap.put(Long.valueOf(statPair[0]), Long.valueOf(statPair[1]));
             }
 
diff --git a/kylin-it/src/test/java/org/apache/kylin/cube/inmemcubing/ITInMemCubeBuilderTest.java
b/kylin-it/src/test/java/org/apache/kylin/cube/inmemcubing/ITInMemCubeBuilderTest.java
index 9bfc18ea07..2a96b3915d 100644
--- a/kylin-it/src/test/java/org/apache/kylin/cube/inmemcubing/ITInMemCubeBuilderTest.java
+++ b/kylin-it/src/test/java/org/apache/kylin/cube/inmemcubing/ITInMemCubeBuilderTest.java
@@ -35,6 +35,7 @@
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.util.Dictionary;
 import org.apache.kylin.common.util.LocalFileMetadataTestCase;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.cube.CubeInstance;
 import org.apache.kylin.cube.CubeManager;
 import org.apache.kylin.cube.cuboid.Cuboid;
@@ -172,7 +173,7 @@ static void feedData(final CubeInstance cube, final String flatTable,
ArrayBlock
         // get distinct values on each column
         List<String> lines = FileUtils.readLines(new File(flatTable), "UTF-8");
         for (String line : lines) {
-            String[] row = line.trim().split(",");
+            String[] row = StringUtil.splitByComma(line.trim());
             assert row.length == nColumns;
             for (int i = 0; i < nColumns; i++)
                 distinctSets[i].add(row[i]);
@@ -253,7 +254,7 @@ static void feedData(final CubeInstance cube, final String flatTable,
ArrayBlock
         List<String> result = Lists.newArrayList();
         List<String> lines = FileUtils.readLines(new File(flatTable), "UTF-8");
         for (String line : lines) {
-            String[] row = line.trim().split(",");
+            String[] row = StringUtil.splitByComma(line.trim());
             if (row.length != nColumns) {
                 throw new IllegalStateException();
             }
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPAuthentication.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPAuthentication.java
index 48aa1fad5f..716caa458e 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPAuthentication.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPAuthentication.java
@@ -17,17 +17,19 @@
 */
 package org.apache.kylin.query.relnode;
 
+import org.apache.kylin.common.util.StringUtil;
+
 import java.util.ArrayList;
 
 /**
  * Created by wangcheng on 7/8/16.
  */
 public class OLAPAuthentication {
-     String username;
-     ArrayList<String> roles = new ArrayList<>();
+    String username;
+    ArrayList<String> roles = new ArrayList<>();
 
     public void parseUserInfo(String userInfo) {
-        String[] info = userInfo.split(",");
+        String[] info = StringUtil.splitByComma(userInfo);
         if (info.length > 0) //first element is username
             this.username = info[0];
         for (int i = 1; i < info.length; i++) //the remains should be roles which starts
from index 1
diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java
index ac6241fa28..1da8ae9a51 100644
--- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java
+++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPTableScan.java
@@ -68,6 +68,7 @@
 import org.apache.calcite.rel.type.RelDataTypeFieldImpl;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.kylin.common.KylinConfig;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.metadata.model.ColumnDesc;
 import org.apache.kylin.metadata.model.DataModelDesc;
 import org.apache.kylin.metadata.model.TableRef;
@@ -242,7 +243,7 @@ private void modifyRules(List<String> rules, Function<RelOptRule,
Void> func) {
             if (StringUtils.isEmpty(rule)) {
                 continue;
             }
-            String[] split = rule.split("#");
+            String[] split = StringUtil.split(rule, "#");
             if (split.length != 2) {
                 throw new RuntimeException("Customized Rule should be in format <RuleClassName>#<FieldName>");
             }
diff --git a/server-base/src/main/java/org/apache/kylin/rest/controller/TableController.java
b/server-base/src/main/java/org/apache/kylin/rest/controller/TableController.java
index 488b7e0259..4cdc9b694f 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/controller/TableController.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/controller/TableController.java
@@ -139,7 +139,7 @@ public TableDesc getTableDesc(@PathVariable String tableName, @PathVariable
Stri
         Set<String> unLoadFail = Sets.newHashSet();
         Map<String, String[]> result = new HashMap<String, String[]>();
         try {
-            for (String tableName : tables.split(",")) {
+            for (String tableName : StringUtil.splitByComma(tables)) {
                 tableACLService.deleteFromTableACLByTbl(project, tableName);
                 if (tableService.unloadHiveTable(tableName, project)) {
                     unLoadSuccess.add(tableName);
@@ -169,7 +169,7 @@ public TableDesc getTableDesc(@PathVariable String tableName, @PathVariable
Stri
     public CardinalityRequest generateCardinality(@PathVariable String tableNames,
             @RequestBody CardinalityRequest request, @PathVariable String project) throws
Exception {
         String submitter = SecurityContextHolder.getContext().getAuthentication().getName();
-        String[] tables = tableNames.split(",");
+        String[] tables = StringUtil.splitByComma(tableNames);
         try {
             for (String table : tables) {
                 tableService.calculateCardinality(table.trim().toUpperCase(Locale.ROOT),
submitter, project);
diff --git a/server-base/src/main/java/org/apache/kylin/rest/init/InitialTaskManager.java
b/server-base/src/main/java/org/apache/kylin/rest/init/InitialTaskManager.java
index 467ef825e5..876ae0859e 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/init/InitialTaskManager.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/init/InitialTaskManager.java
@@ -20,6 +20,7 @@
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.kylin.common.KylinConfig;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.rest.metrics.QueryMetrics2Facade;
 import org.apache.kylin.rest.metrics.QueryMetricsFacade;
 import org.slf4j.Logger;
@@ -49,7 +50,7 @@ private void runInitialTasks() {
         KylinConfig kylinConfig = KylinConfig.getInstanceFromEnv();
         String initTasks = kylinConfig.getInitTasks();
         if (!StringUtils.isEmpty(initTasks)) {
-            String[] taskClasses = initTasks.split(",");
+            String[] taskClasses = StringUtil.splitByComma(initTasks);
             for (String taskClass : taskClasses) {
                 try {
                     InitialTask task = (InitialTask) Class.forName(taskClass).newInstance();
diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java b/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java
index 23d523e866..6abbe98a21 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/service/AdminService.java
@@ -32,6 +32,7 @@
 import org.apache.commons.lang3.StringUtils;
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.util.OrderedProperties;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.rest.constant.Constant;
 import org.apache.kylin.rest.job.StorageCleanupJob;
 import org.slf4j.Logger;
@@ -106,7 +107,7 @@ public String getPublicConfig() throws IOException {
 
         Collection<String> propertyKeys = Lists.newArrayList();
         if (StringUtils.isNotEmpty(whiteListProperties)) {
-            propertyKeys.addAll(Arrays.asList(whiteListProperties.split(",")));
+            propertyKeys.addAll(Arrays.asList(StringUtil.splitByComma(whiteListProperties)));
         }
 
         return KylinConfig.getInstanceFromEnv().exportToString(propertyKeys);
diff --git a/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java b/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
index bd4049d0d1..661b0fd35c 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/service/QueryService.java
@@ -75,6 +75,7 @@
 import org.apache.kylin.common.util.JsonUtil;
 import org.apache.kylin.common.util.Pair;
 import org.apache.kylin.common.util.SetThreadName;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.cube.CubeInstance;
 import org.apache.kylin.cube.CubeManager;
 import org.apache.kylin.cube.cuboid.Cuboid;
@@ -315,7 +316,7 @@ public void logQuery(final String queryId, final SQLRequest request, final
SQLRe
 
         if (realizationNames.isEmpty()) {
             if (!Strings.isNullOrEmpty(response.getCube())) {
-                realizationNames.addAll(Lists.newArrayList(response.getCube().split(",")));
+                realizationNames.addAll(Lists.newArrayList(StringUtil.splitByComma(response.getCube())));
             }
         }
 
diff --git a/server-base/src/main/java/org/apache/kylin/rest/signature/RealizationSetCalculator.java
b/server-base/src/main/java/org/apache/kylin/rest/signature/RealizationSetCalculator.java
index 63139f38f6..b7d3f73e6e 100644
--- a/server-base/src/main/java/org/apache/kylin/rest/signature/RealizationSetCalculator.java
+++ b/server-base/src/main/java/org/apache/kylin/rest/signature/RealizationSetCalculator.java
@@ -24,6 +24,7 @@
 import org.apache.commons.codec.binary.Base64;
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.util.Pair;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.metadata.project.ProjectInstance;
 import org.apache.kylin.rest.response.SQLResponse;
 import org.slf4j.Logger;
@@ -69,7 +70,7 @@ public String calculateSignature(KylinConfig config, SQLResponse sqlResponse,
Pr
         if (Strings.isNullOrEmpty(cubes)) {
             return null;
         }
-        String[] realizations = parseNamesFromCanonicalNames(cubes.split(","));
+        String[] realizations = parseNamesFromCanonicalNames(StringUtil.splitByComma(cubes));
         return Sets.newHashSet(realizations);
     }
 
diff --git a/source-hive/src/main/java/org/apache/kylin/source/hive/cardinality/HiveColumnCardinalityUpdateJob.java
b/source-hive/src/main/java/org/apache/kylin/source/hive/cardinality/HiveColumnCardinalityUpdateJob.java
index eb32756806..6593ec6ba5 100644
--- a/source-hive/src/main/java/org/apache/kylin/source/hive/cardinality/HiveColumnCardinalityUpdateJob.java
+++ b/source-hive/src/main/java/org/apache/kylin/source/hive/cardinality/HiveColumnCardinalityUpdateJob.java
@@ -39,6 +39,7 @@
 import org.apache.hadoop.io.compress.CompressionCodecFactory;
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.util.HadoopUtil;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.engine.mr.common.AbstractHadoopJob;
 import org.apache.kylin.metadata.TableMetadataManager;
 import org.apache.kylin.metadata.model.TableExtDesc;
@@ -160,7 +161,7 @@ public void updateKylinTableExd(String tableName, String outPath, Configuration
             StringWriter writer = new StringWriter();
             IOUtils.copy(stream, writer, "UTF-8");
             String raw = writer.toString();
-            for (String str : raw.split("\n")) {
+            for (String str : StringUtil.split(raw, "\n")) {
                 results.add(str);
             }
         }
diff --git a/source-hive/src/test/java/org/apache/kylin/source/hive/HiveMRInputTest.java b/source-hive/src/test/java/org/apache/kylin/source/hive/HiveMRInputTest.java
index 384c2b8ba6..917db3ec8b 100644
--- a/source-hive/src/test/java/org/apache/kylin/source/hive/HiveMRInputTest.java
+++ b/source-hive/src/test/java/org/apache/kylin/source/hive/HiveMRInputTest.java
@@ -29,6 +29,7 @@
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.KylinConfig.SetAndUnsetThreadLocalConfig;
 import org.apache.kylin.common.util.RandomUtil;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.job.execution.DefaultChainedExecutable;
 import org.junit.Assert;
 import org.junit.Test;
@@ -46,7 +47,8 @@ public void TestGetJobWorkingDir() throws IOException {
             DefaultChainedExecutable defaultChainedExecutable = mock(DefaultChainedExecutable.class);
             defaultChainedExecutable.setId(RandomUtil.randomUUID().toString());
 
-            String jobWorkingDir = HiveInputBase.getJobWorkingDir(defaultChainedExecutable,
KylinConfig.getInstanceFromEnv().getHdfsWorkingDirectory());
+            String jobWorkingDir = HiveInputBase.getJobWorkingDir(defaultChainedExecutable,
+                    KylinConfig.getInstanceFromEnv().getHdfsWorkingDirectory());
             jobWorkDirPath = new Path(jobWorkingDir);
             Assert.assertTrue(fileSystem.exists(jobWorkDirPath));
         } finally {
@@ -64,12 +66,11 @@ public void testMaterializeViewHql() {
 
         StringBuilder hqls = new StringBuilder();
         for (int i = 0; i < viewSize; i++) {
-            String hql = HiveInputBase.materializeViewHql(mockedViewNames[i], mockedTalbeNames[i],
-                    mockedWorkingDir);
+            String hql = HiveInputBase.materializeViewHql(mockedViewNames[i], mockedTalbeNames[i],
mockedWorkingDir);
             hqls.append(hql);
         }
 
-        for (String sub : hqls.toString().split("\n")) {
+        for (String sub : StringUtil.splitAndTrim(hqls.toString(), "\n")) {
             Assert.assertTrue(sub.endsWith(";"));
         }
     }
diff --git a/tool/src/main/java/org/apache/kylin/tool/CubeMetaExtractor.java b/tool/src/main/java/org/apache/kylin/tool/CubeMetaExtractor.java
index 5cf035072b..78aa889fde 100644
--- a/tool/src/main/java/org/apache/kylin/tool/CubeMetaExtractor.java
+++ b/tool/src/main/java/org/apache/kylin/tool/CubeMetaExtractor.java
@@ -31,6 +31,7 @@
 import org.apache.kylin.common.persistence.ResourceStore;
 import org.apache.kylin.common.persistence.ResourceTool;
 import org.apache.kylin.common.util.OptionsHelper;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.cube.CubeDescManager;
 import org.apache.kylin.cube.CubeInstance;
 import org.apache.kylin.cube.CubeManager;
@@ -201,14 +202,14 @@ protected void executeExtract(OptionsHelper optionsHelper, File exportDir)
throw
             }
         } else if (optionsHelper.hasOption(OPTION_PROJECT)) {
             String projectNames = optionsHelper.getOptionValue(OPTION_PROJECT);
-            for (String projectName : projectNames.split(",")) {
+            for (String projectName : StringUtil.splitByComma(projectNames)) {
                 ProjectInstance projectInstance = projectManager.getProject(projectName);
                 Preconditions.checkNotNull(projectInstance, "Project " + projectName + "
does not exist.");
                 requireProject(projectInstance);
             }
         } else if (optionsHelper.hasOption(OPTION_CUBE)) {
             String cubeNames = optionsHelper.getOptionValue(OPTION_CUBE);
-            for (String cubeName : cubeNames.split(",")) {
+            for (String cubeName : StringUtil.splitByComma(cubeNames)) {
                 IRealization realization = cubeManager.getRealization(cubeName);
                 if (realization == null) {
                     throw new IllegalArgumentException("No cube found with name of " + cubeName);
@@ -218,7 +219,7 @@ protected void executeExtract(OptionsHelper optionsHelper, File exportDir)
throw
             }
         } else if (optionsHelper.hasOption(OPTION_HYBRID)) {
             String hybridNames = optionsHelper.getOptionValue(OPTION_HYBRID);
-            for (String hybridName : hybridNames.split(",")) {
+            for (String hybridName : StringUtil.splitByComma(hybridNames)) {
                 IRealization realization = hybridManager.getRealization(hybridName);
 
                 if (realization != null) {
diff --git a/tool/src/main/java/org/apache/kylin/tool/CubeMigrationCheckCLI.java b/tool/src/main/java/org/apache/kylin/tool/CubeMigrationCheckCLI.java
index 54fbbc083e..cbbe029869 100644
--- a/tool/src/main/java/org/apache/kylin/tool/CubeMigrationCheckCLI.java
+++ b/tool/src/main/java/org/apache/kylin/tool/CubeMigrationCheckCLI.java
@@ -32,6 +32,7 @@
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.util.OptionsHelper;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.cube.CubeInstance;
 import org.apache.kylin.cube.CubeManager;
 import org.apache.kylin.cube.CubeSegment;
@@ -169,7 +170,7 @@ public void check(List<String> segFullNameList) {
         inconsistentHTables = Lists.newArrayList();
 
         for (String segFullName : segFullNameList) {
-            String[] sepNameList = segFullName.split(",");
+            String[] sepNameList = StringUtil.splitByComma(segFullName);
             try {
                 HTableDescriptor hTableDescriptor = hbaseAdmin.getTableDescriptor(TableName.valueOf(sepNameList[0]));
                 String host = hTableDescriptor.getValue(IRealizationConstants.HTableTag);
@@ -186,7 +187,7 @@ public void check(List<String> segFullNameList) {
     public void fixInconsistent() throws IOException {
         if (ifFix == true) {
             for (String segFullName : inconsistentHTables) {
-                String[] sepNameList = segFullName.split(",");
+                String[] sepNameList = StringUtil.splitByComma(segFullName);
                 HTableDescriptor desc = hbaseAdmin.getTableDescriptor(TableName.valueOf(sepNameList[0]));
                 logger.info("Change the host of htable " + sepNameList[0] + "belonging to
cube " + sepNameList[1] + " from " + desc.getValue(IRealizationConstants.HTableTag) + " to
" + dstCfg.getMetadataUrlPrefix());
                 hbaseAdmin.disableTable(sepNameList[0]);
@@ -197,7 +198,7 @@ public void fixInconsistent() throws IOException {
         } else {
             logger.info("------ Inconsistent HTables Needed To Be Fixed ------");
             for (String hTable : inconsistentHTables) {
-                String[] sepNameList = hTable.split(",");
+                String[] sepNameList = StringUtil.splitByComma(hTable);
                 logger.info(sepNameList[0] + " belonging to cube " + sepNameList[1]);
             }
             logger.info("----------------------------------------------------");
@@ -207,7 +208,7 @@ public void fixInconsistent() throws IOException {
     public void printIssueExistingHTables() {
         logger.info("------ HTables exist issues in hbase : not existing, metadata broken
------");
         for (String segFullName : issueExistHTables) {
-            String[] sepNameList = segFullName.split(",");
+            String[] sepNameList = StringUtil.splitByComma(segFullName);
             logger.error(sepNameList[0] + " belonging to cube " + sepNameList[1] + " has
some issues and cannot be read successfully!!!");
         }
         logger.info("----------------------------------------------------");
diff --git a/tool/src/main/java/org/apache/kylin/tool/HBaseUsageExtractor.java b/tool/src/main/java/org/apache/kylin/tool/HBaseUsageExtractor.java
index 0d8c08f500..8ffa4733dd 100644
--- a/tool/src/main/java/org/apache/kylin/tool/HBaseUsageExtractor.java
+++ b/tool/src/main/java/org/apache/kylin/tool/HBaseUsageExtractor.java
@@ -35,6 +35,7 @@
 import org.apache.kylin.common.KylinConfig;
 import org.apache.kylin.common.util.CliCommandExecutor;
 import org.apache.kylin.common.util.OptionsHelper;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.cube.CubeInstance;
 import org.apache.kylin.cube.CubeManager;
 import org.apache.kylin.cube.CubeSegment;
@@ -101,7 +102,7 @@ protected void executeExtract(OptionsHelper optionsHelper, File exportDir)
throw
 
         if (optionsHelper.hasOption(OPTION_PROJECT)) {
             String projectNames = optionsHelper.getOptionValue(OPTION_PROJECT);
-            for (String projectName: projectNames.split(",")) {
+            for (String projectName : StringUtil.splitByComma(projectNames)) {
                 ProjectInstance projectInstance = projectManager.getProject(projectName);
                 if (projectInstance == null) {
                     throw new IllegalArgumentException("Project " + projectName + " does
not exist");
@@ -113,7 +114,7 @@ protected void executeExtract(OptionsHelper optionsHelper, File exportDir)
throw
             }
         } else if (optionsHelper.hasOption(OPTION_CUBE)) {
             String cubeNames = optionsHelper.getOptionValue(OPTION_CUBE);
-            for (String cubeName : cubeNames.split(",")) {
+            for (String cubeName : StringUtil.splitByComma(cubeNames)) {
                 IRealization realization = cubeManager.getRealization(cubeName);
                 if (realization != null) {
                     retrieveResourcePath(realization);
diff --git a/tool/src/main/java/org/apache/kylin/tool/JobDiagnosisInfoCLI.java b/tool/src/main/java/org/apache/kylin/tool/JobDiagnosisInfoCLI.java
index a0c846533b..65094d4cfc 100644
--- a/tool/src/main/java/org/apache/kylin/tool/JobDiagnosisInfoCLI.java
+++ b/tool/src/main/java/org/apache/kylin/tool/JobDiagnosisInfoCLI.java
@@ -32,6 +32,7 @@
 import org.apache.kylin.common.persistence.ResourceStore;
 import org.apache.kylin.common.persistence.ResourceTool;
 import org.apache.kylin.common.util.OptionsHelper;
+import org.apache.kylin.common.util.StringUtil;
 import org.apache.kylin.job.constant.ExecutableConstants;
 import org.apache.kylin.job.dao.ExecutableDao;
 import org.apache.kylin.job.dao.ExecutablePO;
@@ -227,9 +228,9 @@ private boolean isYarnAppSucc(String applicationId) throws IOException
{
         final String yarnCmd = "yarn application -status " + applicationId;
         final String cmdOutput = kylinConfig.getCliCommandExecutor().execute(yarnCmd).getSecond();
         final Map<String, String> params = Maps.newHashMap();
-        final String[] cmdOutputLines = cmdOutput.split("\n");
+        final String[] cmdOutputLines = StringUtil.split(cmdOutput, "\n");
         for (String cmdOutputLine : cmdOutputLines) {
-            String[] pair = cmdOutputLine.split(":");
+            String[] pair = StringUtil.split(cmdOutputLine, ":");
             if (pair.length >= 2) {
                 params.put(pair[0].trim(), pair[1].trim());
             }
@@ -242,11 +243,7 @@ private boolean isYarnAppSucc(String applicationId) throws IOException
{
             return true;
         }
 
-        if (params.containsKey("Final-State") && params.get("Final-State").equals("SUCCEEDED"))
{
-            return true;
-        }
-
-        return false;
+        return params.containsKey("Final-State") && params.get("Final-State").equals("SUCCEEDED");
     }
 
     private void addRequired(String record) {


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message