KYLIN-1387 should support empty segment
Project: http://git-wip-us.apache.org/repos/asf/kylin/repo Commit: http://git-wip-us.apache.org/repos/asf/kylin/commit/95f8a2c5 Tree: http://git-wip-us.apache.org/repos/asf/kylin/tree/95f8a2c5 Diff: http://git-wip-us.apache.org/repos/asf/kylin/diff/95f8a2c5 Branch: refs/heads/helix-201602 Commit: 95f8a2c567875ed48fc6de27a3918e8d6d607835 Parents: dc460de Author: shaofengshi <shaofeng...@apache.org> Authored: Tue Feb 16 09:42:34 2016 +0800 Committer: shaofengshi <shaofeng...@apache.org> Committed: Tue Feb 16 11:05:12 2016 +0800 ---------------------------------------------------------------------- .../hbase/steps/SequenceFileCuboidWriter.java | 48 +++++++++++--------- 1 file changed, 26 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kylin/blob/95f8a2c5/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/steps/SequenceFileCuboidWriter.java ---------------------------------------------------------------------- diff --git a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/steps/SequenceFileCuboidWriter.java b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/steps/SequenceFileCuboidWriter.java index 4d76522..8c2d5e4 100644 --- a/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/steps/SequenceFileCuboidWriter.java +++ b/storage-hbase/src/main/java/org/apache/kylin/storage/hbase/steps/SequenceFileCuboidWriter.java @@ -25,35 +25,39 @@ public class SequenceFileCuboidWriter extends KVGTRecordWriter { public SequenceFileCuboidWriter(CubeDesc cubeDesc, CubeSegment segment) { super(cubeDesc, segment); + try { + initiate(); + } catch (IOException e) { + throw new RuntimeException(e); + } } - - @Override - protected void writeAsKeyValue(ByteArrayWritable key, ByteArrayWritable value) throws IOException { + protected void initiate() throws IOException { if (writer == null) { - synchronized (SequenceFileCuboidWriter.class) { - if (writer == null) { - JobBuilderSupport jobBuilderSupport = new JobBuilderSupport(cubeSegment, "SYSTEM"); - String cuboidRoot = jobBuilderSupport.getCuboidRootPath(cubeSegment); - Path cuboidPath = new Path(cuboidRoot); - FileSystem fs = HadoopUtil.getFileSystem(cuboidRoot); - try { - if (fs.exists(cuboidPath)) { - fs.delete(cuboidPath, true); - } - - fs.mkdirs(cuboidPath); - } finally { - IOUtils.closeQuietly(fs); - } - - Path cuboidFile = new Path(cuboidPath, "data.seq"); - logger.debug("Cuboid is written to " + cuboidFile); - writer = SequenceFile.createWriter(HadoopUtil.getCurrentConfiguration(), SequenceFile.Writer.file(cuboidFile), SequenceFile.Writer.keyClass(Text.class), SequenceFile.Writer.valueClass(Text.class)); + JobBuilderSupport jobBuilderSupport = new JobBuilderSupport(cubeSegment, "SYSTEM"); + String cuboidRoot = jobBuilderSupport.getCuboidRootPath(cubeSegment); + Path cuboidPath = new Path(cuboidRoot); + FileSystem fs = HadoopUtil.getFileSystem(cuboidRoot); + try { + if (fs.exists(cuboidPath)) { + fs.delete(cuboidPath, true); } + + fs.mkdirs(cuboidPath); + } finally { + IOUtils.closeQuietly(fs); } + + Path cuboidFile = new Path(cuboidPath, "data.seq"); + logger.debug("Cuboid is written to " + cuboidFile); + writer = SequenceFile.createWriter(HadoopUtil.getCurrentConfiguration(), SequenceFile.Writer.file(cuboidFile), SequenceFile.Writer.keyClass(Text.class), SequenceFile.Writer.valueClass(Text.class)); } + } + + @Override + protected void writeAsKeyValue(ByteArrayWritable key, ByteArrayWritable value) throws IOException { + Text outputValue = new Text(); Text outputKey = new Text(); outputKey.set(key.array(), key.offset(), key.length());