Repository: kylin Updated Branches: refs/heads/2.x-staging c8c652941 -> f1cd86e5a
KYLIN-1303 Fix bug of in-mem cubing on empty segment with boolean/tinyint dims Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/f1cd86e5 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/f1cd86e5 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/f1cd86e5 Branch: refs/heads/2.x-staging Commit: f1cd86e5aaef20aa960d67e610f0c9ee22624cb2 Parents: c8c6529 Author: lidongsjtu <lid...@apache.org> Authored: Wed Jan 20 15:45:45 2016 +0800 Committer: lidongsjtu <lid...@apache.org> Committed: Wed Jan 20 15:45:45 2016 +0800 ---------------------------------------------------------------------- .../metadata/datatype/BooleanSerializer.java | 81 ++++++++++++++++++++ .../metadata/datatype/DataTypeSerializer.java | 2 + 2 files changed, 83 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/f1cd86e5/core-metadata/src/main/java/org/apache/kylin/metadata/datatype/BooleanSerializer.java ---------------------------------------------------------------------- diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/datatype/BooleanSerializer.java b/core-metadata/src/main/java/org/apache/kylin/metadata/datatype/BooleanSerializer.java new file mode 100644 index 0000000..e843247 --- /dev/null +++ b/core-metadata/src/main/java/org/apache/kylin/metadata/datatype/BooleanSerializer.java @@ -0,0 +1,81 @@ +/* + * 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.metadata.datatype; + +import java.nio.ByteBuffer; + +import org.apache.commons.lang.ArrayUtils; +import org.apache.commons.lang.BooleanUtils; + +public class BooleanSerializer extends DataTypeSerializer<LongMutable> { + + final String[] TRUE_VALUE_SET = { "true", "t", "on", "yes" }; + + // be thread-safe and avoid repeated obj creation + private ThreadLocal<LongMutable> current = new ThreadLocal<LongMutable>(); + + public BooleanSerializer(DataType type) { + } + + @Override + public void serialize(LongMutable value, ByteBuffer out) { + out.putLong(value.get()); + } + + private LongMutable current() { + LongMutable l = current.get(); + if (l == null) { + l = new LongMutable(); + current.set(l); + } + return l; + } + + @Override + public LongMutable deserialize(ByteBuffer in) { + LongMutable l = current(); + l.set(in.getLong()); + return l; + } + + @Override + public int peekLength(ByteBuffer in) { + return 8; + } + + @Override + public int maxLength() { + return 8; + } + + @Override + public int getStorageBytesEstimate() { + return 8; + } + + @Override + public LongMutable valueOf(String str) { + LongMutable l = current(); + if (str == null) + l.set(0L); + else + l.set(BooleanUtils.toInteger(ArrayUtils.contains(TRUE_VALUE_SET, str.toLowerCase()))); + return l; + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/kylin/blob/f1cd86e5/core-metadata/src/main/java/org/apache/kylin/metadata/datatype/DataTypeSerializer.java ---------------------------------------------------------------------- diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/datatype/DataTypeSerializer.java b/core-metadata/src/main/java/org/apache/kylin/metadata/datatype/DataTypeSerializer.java index df5513c..d70562b 100644 --- a/core-metadata/src/main/java/org/apache/kylin/metadata/datatype/DataTypeSerializer.java +++ b/core-metadata/src/main/java/org/apache/kylin/metadata/datatype/DataTypeSerializer.java @@ -40,7 +40,9 @@ abstract public class DataTypeSerializer<T> implements BytesSerializer<T> { implementations.put("long", LongSerializer.class); implementations.put("integer", LongSerializer.class); implementations.put("int", LongSerializer.class); + implementations.put("tinyint", LongSerializer.class); implementations.put("smallint", LongSerializer.class); + implementations.put("boolean", BooleanSerializer.class); implementations.put("date", DateTimeSerializer.class); implementations.put("datetime", DateTimeSerializer.class); implementations.put("timestamp", DateTimeSerializer.class);