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/01/12 04:05:12 UTC
[09/50] [abbrv] kylin git commit: KYLIN-2360 fix minor SonarCube issue
KYLIN-2360 fix minor SonarCube issue
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/503d232d
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/503d232d
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/503d232d
Branch: refs/heads/master-hbase1.x
Commit: 503d232dc1875d504959a3e00da2eb62a7b7d599
Parents: 980b03b
Author: shaofengshi <sh...@apache.org>
Authored: Thu Jan 5 18:04:56 2017 +0800
Committer: shaofengshi <sh...@apache.org>
Committed: Thu Jan 5 18:09:45 2017 +0800
----------------------------------------------------------------------
.../adapter/enumerable/EnumerableWindow.java | 53 +++++++++++++++++++-
.../kylin/common/persistence/ResourceTool.java | 5 +-
.../apache/kylin/common/util/StringUtil.java | 2 +-
.../org/apache/kylin/dict/CacheDictionary.java | 29 ++++++-----
4 files changed, 71 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/503d232d/atopcalcite/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
----------------------------------------------------------------------
diff --git a/atopcalcite/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java b/atopcalcite/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
index 547210c..216b07c 100644
--- a/atopcalcite/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
+++ b/atopcalcite/src/main/java/org/apache/calcite/adapter/enumerable/EnumerableWindow.java
@@ -80,6 +80,7 @@ public class EnumerableWindow extends Window implements EnumerableRel {
constants, rowType, groups);
}
+ @Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
return super.computeSelfCost(planner, mq)
.multiplyBy(EnumerableConvention.COST_MULTIPLIER);
@@ -104,6 +105,7 @@ public class EnumerableWindow extends Window implements EnumerableRel {
this.constants = constants;
}
+ @Override
public Expression field(BlockBuilder list, int index, Type storageType) {
if (index < actualInputFieldCount) {
Expression current = list.append("current", row);
@@ -113,6 +115,55 @@ public class EnumerableWindow extends Window implements EnumerableRel {
}
}
+ private void sampleOfTheGeneratedWindowedAggregate() {
+ // Here's overview of the generated code
+ // For each list of rows that have the same partitioning key, evaluate
+ // all of the windowed aggregate functions.
+
+ // builder
+ Iterator<Integer[]> iterator = null;
+
+ // builder3
+ Integer[] rows = iterator.next();
+
+ int prevStart = -1;
+ int prevEnd = -1;
+
+ for (int i = 0; i < rows.length; i++) {
+ // builder4
+ Integer row = rows[i];
+
+ int start = 0;
+ int end = 100;
+ if (start != prevStart || end != prevEnd) {
+ // builder5
+ int actualStart = 0;
+ if (start != prevStart || end < prevEnd) {
+ // builder6
+ // recompute
+ actualStart = start;
+ // implementReset
+ } else { // must be start == prevStart && end > prevEnd
+ actualStart = prevEnd + 1;
+ }
+ prevStart = start;
+ prevEnd = end;
+
+ if (start != -1) {
+ for (int j = actualStart; j <= end; j++) {
+ // builder7
+ // implementAdd
+ }
+ }
+ // implementResult
+ // list.add(new Xxx(row.deptno, row.empid, sum, count));
+ }
+ }
+ // multiMap.clear(); // allows gc
+ // source = Linq4j.asEnumerable(list);
+ }
+
+ @Override
public Result implement(EnumerableRelImplementor implementor, Prefer pref) {
final JavaTypeFactory typeFactory = implementor.getTypeFactory();
final EnumerableRel child = (EnumerableRel) getInput();
@@ -121,7 +172,7 @@ public class EnumerableWindow extends Window implements EnumerableRel {
Expression source_ = builder.append("source", result.block);
final List<Expression> translatedConstants =
- new ArrayList<Expression>(constants.size());
+ new ArrayList<>(constants.size());
for (RexLiteral constant : constants) {
translatedConstants.add(
RexToLixTranslator.translateLiteral(constant, constant.getType(),
http://git-wip-us.apache.org/repos/asf/kylin/blob/503d232d/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java
----------------------------------------------------------------------
diff --git a/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java b/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java
index 2c8bc83..b3aac09 100644
--- a/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java
+++ b/core-common/src/main/java/org/apache/kylin/common/persistence/ResourceTool.java
@@ -28,11 +28,14 @@ import java.util.NavigableSet;
import org.apache.commons.io.IOUtils;
import org.apache.kylin.common.KylinConfig;
import org.apache.kylin.common.util.StringUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class ResourceTool {
private static String[] includes = null;
private static String[] excludes = null;
+ private static final Logger logger = LoggerFactory.getLogger(ResourceTool.class);
public static void main(String[] args) throws IOException {
args = StringUtil.filterSystemArgs(args);
@@ -164,7 +167,7 @@ public class ResourceTool {
}
} catch (Exception ex) {
System.err.println("Failed to open " + path);
- ex.printStackTrace();
+ logger.error(ex.getLocalizedMessage(), ex);
}
}
} else {
http://git-wip-us.apache.org/repos/asf/kylin/blob/503d232d/core-common/src/main/java/org/apache/kylin/common/util/StringUtil.java
----------------------------------------------------------------------
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 12e7279..96d294b 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
@@ -161,7 +161,7 @@ public class StringUtil {
if (!s.isEmpty())
r.add(s);
}
- return (String[]) r.toArray(new String[r.size()]);
+ return r.toArray(new String[r.size()]);
}
}
http://git-wip-us.apache.org/repos/asf/kylin/blob/503d232d/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java
----------------------------------------------------------------------
diff --git a/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java b/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java
index 1b3bfa1..1e260b2 100644
--- a/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java
+++ b/core-dictionary/src/main/java/org/apache/kylin/dict/CacheDictionary.java
@@ -25,20 +25,19 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
- * Created by xiefan on 16-12-30.
*/
-abstract public class CacheDictionary<T> extends Dictionary<T> {
+public abstract class CacheDictionary<T> extends Dictionary<T> {
private static final long serialVersionUID = 1L;
- transient protected boolean enableValueCache = false;
+ protected transient boolean enableValueCache = false;
- transient private SoftReference<Map> valueToIdCache;
+ private transient SoftReference<ConcurrentHashMap> valueToIdCache;
- transient private SoftReference<Object[]> idToValueCache;
+ private transient SoftReference<Object[]> idToValueCache;
- transient protected int baseId;
+ protected transient int baseId;
- transient protected BytesConverter<T> bytesConvert;
+ protected transient BytesConverter<T> bytesConvert;
public CacheDictionary() {
@@ -46,11 +45,11 @@ abstract public class CacheDictionary<T> extends Dictionary<T> {
//value --> id
@Override
- final protected int getIdFromValueImpl(T value, int roundingFlag) {
+ protected final int getIdFromValueImpl(T value, int roundingFlag) {
if (enableValueCache && roundingFlag == 0) {
Map cache = valueToIdCache.get(); // SoftReference to skip cache gracefully when short of memory
if (cache != null) {
- Integer id = null;
+ Integer id;
id = (Integer) cache.get(value);
if (id != null)
return id.intValue();
@@ -66,7 +65,7 @@ abstract public class CacheDictionary<T> extends Dictionary<T> {
//id --> value
@Override
- final protected T getValueFromIdImpl(int id) {
+ protected final T getValueFromIdImpl(int id) {
if (enableValueCache) {
Object[] cache = idToValueCache.get();
if (cache != null) {
@@ -83,7 +82,7 @@ abstract public class CacheDictionary<T> extends Dictionary<T> {
return bytesConvert.convertFromBytes(valueBytes, 0, valueBytes.length);
}
- final protected int calcSeqNoFromId(int id) {
+ protected final int calcSeqNoFromId(int id) {
int seq = id - baseId;
if (seq < 0 || seq >= getSize()) {
throw new IllegalArgumentException("Not a valid ID: " + id);
@@ -91,15 +90,15 @@ abstract public class CacheDictionary<T> extends Dictionary<T> {
return seq;
}
- final public void enableCache() {
+ public final void enableCache() {
this.enableValueCache = true;
if (this.valueToIdCache == null)
- this.valueToIdCache = new SoftReference<Map>(new ConcurrentHashMap());
+ this.valueToIdCache = new SoftReference<>(new ConcurrentHashMap());
if (this.idToValueCache == null)
- this.idToValueCache = new SoftReference<Object[]>(new Object[getSize()]);
+ this.idToValueCache = new SoftReference<>(new Object[getSize()]);
}
- final public void disableCache() {
+ public final void disableCache() {
this.enableValueCache = false;
this.valueToIdCache = null;
this.idToValueCache = null;