You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by ma...@apache.org on 2016/08/31 03:53:46 UTC
kylin git commit: minor, fix checkstyle
Repository: kylin
Updated Branches:
refs/heads/master 9e0b8d803 -> a9ba1da13
minor, fix checkstyle
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo
Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/a9ba1da1
Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/a9ba1da1
Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/a9ba1da1
Branch: refs/heads/master
Commit: a9ba1da138966cb3fd6c4bd6950fe4b48597cf8d
Parents: 9e0b8d8
Author: Hongbin Ma <ma...@apache.org>
Authored: Wed Aug 31 11:54:02 2016 +0800
Committer: Hongbin Ma <ma...@apache.org>
Committed: Wed Aug 31 11:54:02 2016 +0800
----------------------------------------------------------------------
.../java/org/apache/kylin/gridtable/GTUtil.java | 383 ++++++++++---------
1 file changed, 199 insertions(+), 184 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/kylin/blob/a9ba1da1/core-cube/src/main/java/org/apache/kylin/gridtable/GTUtil.java
----------------------------------------------------------------------
diff --git a/core-cube/src/main/java/org/apache/kylin/gridtable/GTUtil.java b/core-cube/src/main/java/org/apache/kylin/gridtable/GTUtil.java
index ce0f016..7406e81 100644
--- a/core-cube/src/main/java/org/apache/kylin/gridtable/GTUtil.java
+++ b/core-cube/src/main/java/org/apache/kylin/gridtable/GTUtil.java
@@ -75,224 +75,239 @@ public class GTUtil {
IFilterCodeSystem<ByteArray> filterCodeSystem = wrap(info.codeSystem.getComparator());
- byte[] bytes = TupleFilterSerializer.serialize(rootFilter, new TupleFilterSerializer.Decorator() {
- @Override
- public TupleFilter onSerialize(TupleFilter filter) {
- if (filter == null)
- return null;
-
- // In case of NOT(unEvaluatableFilter), we should immediately replace it as TRUE,
- // Otherwise, unEvaluatableFilter will later be replace with TRUE and NOT(unEvaluatableFilter)
- // will always return FALSE.
- if (filter.getOperator() == TupleFilter.FilterOperatorEnum.NOT && !TupleFilter.isEvaluableRecursively(filter)) {
- TupleFilter.collectColumns(filter, unevaluatableColumnCollector);
- return ConstantTupleFilter.TRUE;
- }
+ byte[] bytes = TupleFilterSerializer.serialize(rootFilter, new GTConvertDecorator(unevaluatableColumnCollector, colMapping, info, encodeConstants), filterCodeSystem);
- // shortcut for unEvaluatable filter
- if (!filter.isEvaluable()) {
- TupleFilter.collectColumns(filter, unevaluatableColumnCollector);
- return ConstantTupleFilter.TRUE;
- }
+ return TupleFilterSerializer.deserialize(bytes, filterCodeSystem);
+ }
- // map to column onto grid table
- if (colMapping != null && filter instanceof ColumnTupleFilter) {
- ColumnTupleFilter colFilter = (ColumnTupleFilter) filter;
- int gtColIdx = colMapping.indexOf(colFilter.getColumn());
- return new ColumnTupleFilter(info.colRef(gtColIdx));
- }
+ public static IFilterCodeSystem<ByteArray> wrap(final IGTComparator comp) {
+ return new IFilterCodeSystem<ByteArray>() {
- // encode constants
- if (encodeConstants && filter instanceof CompareTupleFilter) {
- return encodeConstants((CompareTupleFilter) filter);
- }
- if (encodeConstants && filter instanceof BuiltInFunctionTupleFilter) {
- if (!((BuiltInFunctionTupleFilter) filter).hasNested()) {
- return encodeConstants((BuiltInFunctionTupleFilter) filter);
- } else {
- throw new IllegalStateException("Nested BuiltInFunctionTupleFilter is not supported to be pushed down");
- }
- }
+ @Override
+ public int compare(ByteArray o1, ByteArray o2) {
+ return comp.compare(o1, o2);
+ }
- return filter;
+ @Override
+ public boolean isNull(ByteArray code) {
+ return comp.isNull(code);
}
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private TupleFilter encodeConstants(CompareTupleFilter oldCompareFilter) {
- // extract ColumnFilter & ConstantFilter
- TblColRef externalCol = oldCompareFilter.getColumn();
+ @Override
+ public void serialize(ByteArray code, ByteBuffer buffer) {
+ if (code == null)
+ BytesUtil.writeByteArray(null, 0, 0, buffer);
+ else
+ BytesUtil.writeByteArray(code.array(), code.offset(), code.length(), buffer);
+ }
- if (externalCol == null) {
- return oldCompareFilter;
- }
+ @Override
+ public ByteArray deserialize(ByteBuffer buffer) {
+ return new ByteArray(BytesUtil.readByteArray(buffer));
+ }
+ };
+ }
- Collection constValues = oldCompareFilter.getValues();
- if (constValues == null || constValues.isEmpty()) {
- return oldCompareFilter;
- }
+ private static class GTConvertDecorator implements TupleFilterSerializer.Decorator {
+ private final Set<TblColRef> unevaluatableColumnCollector;
+ private final List<TblColRef> colMapping;
+ private final GTInfo info;
+ private final boolean encodeConstants;
+
+ public GTConvertDecorator(Set<TblColRef> unevaluatableColumnCollector, List<TblColRef> colMapping, GTInfo info, boolean encodeConstants) {
+ this.unevaluatableColumnCollector = unevaluatableColumnCollector;
+ this.colMapping = colMapping;
+ this.info = info;
+ this.encodeConstants = encodeConstants;
+ buf = ByteBuffer.allocate(info.getMaxColumnLength());
+ }
+
+ @Override
+ public TupleFilter onSerialize(TupleFilter filter) {
+ if (filter == null)
+ return null;
+
+ // In case of NOT(unEvaluatableFilter), we should immediately replace it as TRUE,
+ // Otherwise, unEvaluatableFilter will later be replace with TRUE and NOT(unEvaluatableFilter)
+ // will always return FALSE.
+ if (filter.getOperator() == TupleFilter.FilterOperatorEnum.NOT && !TupleFilter.isEvaluableRecursively(filter)) {
+ TupleFilter.collectColumns(filter, unevaluatableColumnCollector);
+ return ConstantTupleFilter.TRUE;
+ }
- //CompareTupleFilter containing BuiltInFunctionTupleFilter will not reach here caz it will be transformed by BuiltInFunctionTransformer
- CompareTupleFilter newCompareFilter = new CompareTupleFilter(oldCompareFilter.getOperator());
- newCompareFilter.addChild(new ColumnTupleFilter(externalCol));
-
- //for CompareTupleFilter containing dynamicVariables, the below codes will actually replace dynamicVariables
- //with normal ConstantTupleFilter
-
- Object firstValue = constValues.iterator().next();
- int col = colMapping == null ? externalCol.getColumnDesc().getZeroBasedIndex() : colMapping.indexOf(externalCol);
-
- TupleFilter result;
- ByteArray code;
-
- // translate constant into code
- switch (newCompareFilter.getOperator()) {
- case EQ:
- case IN:
- Set newValues = Sets.newHashSet();
- for (Object value : constValues) {
- code = translate(col, value, 0);
- if (code != null)
- newValues.add(code);
- }
- if (newValues.isEmpty()) {
- result = ConstantTupleFilter.FALSE;
- } else {
- newCompareFilter.addChild(new ConstantTupleFilter(newValues));
- result = newCompareFilter;
- }
- break;
- case NEQ:
- code = translate(col, firstValue, 0);
- if (code == null) {
- result = ConstantTupleFilter.TRUE;
- } else {
- newCompareFilter.addChild(new ConstantTupleFilter(code));
- result = newCompareFilter;
- }
- break;
- case LT:
- code = translate(col, firstValue, 1);
- if (code == null) {
- result = ConstantTupleFilter.TRUE;
- } else {
- newCompareFilter.addChild(new ConstantTupleFilter(code));
- result = newCompareFilter;
- }
- break;
- case LTE:
- code = translate(col, firstValue, -1);
- if (code == null) {
- result = ConstantTupleFilter.FALSE;
- } else {
- newCompareFilter.addChild(new ConstantTupleFilter(code));
- result = newCompareFilter;
- }
- break;
- case GT:
- code = translate(col, firstValue, -1);
- if (code == null) {
- result = ConstantTupleFilter.TRUE;
- } else {
- newCompareFilter.addChild(new ConstantTupleFilter(code));
- result = newCompareFilter;
- }
- break;
- case GTE:
- code = translate(col, firstValue, 1);
- if (code == null) {
- result = ConstantTupleFilter.FALSE;
- } else {
- newCompareFilter.addChild(new ConstantTupleFilter(code));
- result = newCompareFilter;
- }
- break;
- default:
- throw new IllegalStateException("Cannot handle operator " + newCompareFilter.getOperator());
- }
- return result;
+ // shortcut for unEvaluatable filter
+ if (!filter.isEvaluable()) {
+ TupleFilter.collectColumns(filter, unevaluatableColumnCollector);
+ return ConstantTupleFilter.TRUE;
}
- @SuppressWarnings({ "rawtypes", "unchecked" })
- private TupleFilter encodeConstants(BuiltInFunctionTupleFilter funcFilter) {
- // extract ColumnFilter & ConstantFilter
- TblColRef externalCol = funcFilter.getColumn();
+ // map to column onto grid table
+ if (colMapping != null && filter instanceof ColumnTupleFilter) {
+ ColumnTupleFilter colFilter = (ColumnTupleFilter) filter;
+ int gtColIdx = colMapping.indexOf(colFilter.getColumn());
+ return new ColumnTupleFilter(info.colRef(gtColIdx));
+ }
- if (externalCol == null) {
- return funcFilter;
+ // encode constants
+ if (encodeConstants && filter instanceof CompareTupleFilter) {
+ return encodeConstants((CompareTupleFilter) filter);
+ }
+ if (encodeConstants && filter instanceof BuiltInFunctionTupleFilter) {
+ if (!((BuiltInFunctionTupleFilter) filter).hasNested()) {
+ return encodeConstants((BuiltInFunctionTupleFilter) filter);
+ } else {
+ throw new IllegalStateException("Nested BuiltInFunctionTupleFilter is not supported to be pushed down");
}
+ }
- Collection constValues = funcFilter.getConstantTupleFilter().getValues();
- if (constValues == null || constValues.isEmpty()) {
- return funcFilter;
- }
+ return filter;
+ }
- BuiltInFunctionTupleFilter newFuncFilter;
- try {
- newFuncFilter = funcFilter.getClass().getConstructor(String.class).newInstance(funcFilter.getName());
- } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
- throw new RuntimeException(e);
- }
- newFuncFilter.addChild(new ColumnTupleFilter(externalCol));
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private TupleFilter encodeConstants(CompareTupleFilter oldCompareFilter) {
+ // extract ColumnFilter & ConstantFilter
+ TblColRef externalCol = oldCompareFilter.getColumn();
- int col = colMapping == null ? externalCol.getColumnDesc().getZeroBasedIndex() : colMapping.indexOf(externalCol);
+ if (externalCol == null) {
+ return oldCompareFilter;
+ }
+
+ Collection constValues = oldCompareFilter.getValues();
+ if (constValues == null || constValues.isEmpty()) {
+ return oldCompareFilter;
+ }
+
+ //CompareTupleFilter containing BuiltInFunctionTupleFilter will not reach here caz it will be transformed by BuiltInFunctionTransformer
+ CompareTupleFilter newCompareFilter = new CompareTupleFilter(oldCompareFilter.getOperator());
+ newCompareFilter.addChild(new ColumnTupleFilter(externalCol));
+
+ //for CompareTupleFilter containing dynamicVariables, the below codes will actually replace dynamicVariables
+ //with normal ConstantTupleFilter
- ByteArray code;
+ Object firstValue = constValues.iterator().next();
+ int col = colMapping == null ? externalCol.getColumnDesc().getZeroBasedIndex() : colMapping.indexOf(externalCol);
- // translate constant into code
+ TupleFilter result;
+ ByteArray code;
+
+ // translate constant into code
+ switch (newCompareFilter.getOperator()) {
+ case EQ:
+ case IN:
Set newValues = Sets.newHashSet();
for (Object value : constValues) {
code = translate(col, value, 0);
- if (code == null) {
- throw new IllegalStateException("Cannot serialize BuiltInFunctionTupleFilter");
- }
- newValues.add(code);
+ if (code != null)
+ newValues.add(code);
+ }
+ if (newValues.isEmpty()) {
+ result = ConstantTupleFilter.FALSE;
+ } else {
+ newCompareFilter.addChild(new ConstantTupleFilter(newValues));
+ result = newCompareFilter;
+ }
+ break;
+ case NEQ:
+ code = translate(col, firstValue, 0);
+ if (code == null) {
+ result = ConstantTupleFilter.TRUE;
+ } else {
+ newCompareFilter.addChild(new ConstantTupleFilter(code));
+ result = newCompareFilter;
+ }
+ break;
+ case LT:
+ code = translate(col, firstValue, 1);
+ if (code == null) {
+ result = ConstantTupleFilter.TRUE;
+ } else {
+ newCompareFilter.addChild(new ConstantTupleFilter(code));
+ result = newCompareFilter;
+ }
+ break;
+ case LTE:
+ code = translate(col, firstValue, -1);
+ if (code == null) {
+ result = ConstantTupleFilter.FALSE;
+ } else {
+ newCompareFilter.addChild(new ConstantTupleFilter(code));
+ result = newCompareFilter;
}
- newFuncFilter.addChild(new ConstantTupleFilter(newValues));
+ break;
+ case GT:
+ code = translate(col, firstValue, -1);
+ if (code == null) {
+ result = ConstantTupleFilter.TRUE;
+ } else {
+ newCompareFilter.addChild(new ConstantTupleFilter(code));
+ result = newCompareFilter;
+ }
+ break;
+ case GTE:
+ code = translate(col, firstValue, 1);
+ if (code == null) {
+ result = ConstantTupleFilter.FALSE;
+ } else {
+ newCompareFilter.addChild(new ConstantTupleFilter(code));
+ result = newCompareFilter;
+ }
+ break;
+ default:
+ throw new IllegalStateException("Cannot handle operator " + newCompareFilter.getOperator());
+ }
+ return result;
+ }
- return newFuncFilter;
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private TupleFilter encodeConstants(BuiltInFunctionTupleFilter funcFilter) {
+ // extract ColumnFilter & ConstantFilter
+ TblColRef externalCol = funcFilter.getColumn();
+
+ if (externalCol == null) {
+ return funcFilter;
}
- transient ByteBuffer buf = ByteBuffer.allocate(info.getMaxColumnLength());
+ Collection constValues = funcFilter.getConstantTupleFilter().getValues();
+ if (constValues == null || constValues.isEmpty()) {
+ return funcFilter;
+ }
- private ByteArray translate(int col, Object value, int roundingFlag) {
- try {
- buf.clear();
- info.codeSystem.encodeColumnValue(col, value, roundingFlag, buf);
- return ByteArray.copyOf(buf.array(), 0, buf.position());
- } catch (IllegalArgumentException ex) {
- return null;
- }
+ BuiltInFunctionTupleFilter newFuncFilter;
+ try {
+ newFuncFilter = funcFilter.getClass().getConstructor(String.class).newInstance(funcFilter.getName());
+ } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
+ throw new RuntimeException(e);
}
- }, filterCodeSystem);
+ newFuncFilter.addChild(new ColumnTupleFilter(externalCol));
- return TupleFilterSerializer.deserialize(bytes, filterCodeSystem);
- }
+ int col = colMapping == null ? externalCol.getColumnDesc().getZeroBasedIndex() : colMapping.indexOf(externalCol);
- public static IFilterCodeSystem<ByteArray> wrap(final IGTComparator comp) {
- return new IFilterCodeSystem<ByteArray>() {
+ ByteArray code;
- @Override
- public int compare(ByteArray o1, ByteArray o2) {
- return comp.compare(o1, o2);
+ // translate constant into code
+ Set newValues = Sets.newHashSet();
+ for (Object value : constValues) {
+ code = translate(col, value, 0);
+ if (code == null) {
+ throw new IllegalStateException("Cannot serialize BuiltInFunctionTupleFilter");
+ }
+ newValues.add(code);
}
+ newFuncFilter.addChild(new ConstantTupleFilter(newValues));
- @Override
- public boolean isNull(ByteArray code) {
- return comp.isNull(code);
- }
+ return newFuncFilter;
+ }
- @Override
- public void serialize(ByteArray code, ByteBuffer buffer) {
- if (code == null)
- BytesUtil.writeByteArray(null, 0, 0, buffer);
- else
- BytesUtil.writeByteArray(code.array(), code.offset(), code.length(), buffer);
- }
+ transient ByteBuffer buf;
- @Override
- public ByteArray deserialize(ByteBuffer buffer) {
- return new ByteArray(BytesUtil.readByteArray(buffer));
+ private ByteArray translate(int col, Object value, int roundingFlag) {
+ try {
+ buf.clear();
+ info.codeSystem.encodeColumnValue(col, value, roundingFlag, buf);
+ return ByteArray.copyOf(buf.array(), 0, buf.position());
+ } catch (IllegalArgumentException ex) {
+ return null;
}
- };
+ }
}
}