Skip to content

Commit

Permalink
[CARBONDATA-673]Reverting big decimal compression as it has below iss…
Browse files Browse the repository at this point in the history
…ue This closes apache#561
  • Loading branch information
ravipesala committed Jan 20, 2017
2 parents 254af99 + 9e24a3d commit 4a1f6ae
Show file tree
Hide file tree
Showing 38 changed files with 851 additions and 902 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ public abstract class AbstractMeasureChunkReader implements MeasureColumnChunkRe
*/
protected String filePath;

/**
* number of rows for blocklet
*/
protected int numberOfRows;

/**
* Constructor to get minimum parameter to create instance of this class
*
* @param filePath file from which data will be read
* @param filePath file from which data will be read
*/
public AbstractMeasureChunkReader(String filePath) {
public AbstractMeasureChunkReader(String filePath, int numberOfRows) {
this.filePath = filePath;
this.numberOfRows = numberOfRows;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class CompressedMeasureChunkFileBasedReaderV1 extends AbstractMeasureChun
*/
public CompressedMeasureChunkFileBasedReaderV1(final BlockletInfo blockletInfo,
final String filePath) {
super(filePath);
super(filePath, blockletInfo.getNumberOfRows());
this.measureColumnChunks = blockletInfo.getMeasureColumnChunk();
}

Expand Down Expand Up @@ -90,7 +90,7 @@ public CompressedMeasureChunkFileBasedReaderV1(final BlockletInfo blockletInfo,
// unCompress data
values.uncompress(compressModel.getConvertedDataType(), dataPage, 0,
measureColumnChunks.get(blockIndex).getDataPageLength(), compressModel.getMantissa(),
compressModel.getMaxValue());
compressModel.getMaxValue(), numberOfRows);

CarbonReadDataHolder measureDataHolder = new CarbonReadDataHolder(values);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class CompressedMeasureChunkFileBasedReaderV2 extends AbstractMeasureChun
*/
public CompressedMeasureChunkFileBasedReaderV2(final BlockletInfo blockletInfo,
final String filePath) {
super(filePath);
super(filePath, blockletInfo.getNumberOfRows());
this.measureColumnChunkOffsets = blockletInfo.getMeasureChunkOffsets();
this.measureColumnChunkLength = blockletInfo.getMeasureChunksLength();
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public MeasureColumnDataChunk[] readMeasureChunks(FileHolder fileReader, int[][]
// uncompress
values.uncompress(compressionModel.getConvertedDataType()[0], data,
copyPoint, measureColumnChunk.data_page_length, compressionModel.getMantissa()[0],
compressionModel.getMaxValue()[0]);
compressionModel.getMaxValue()[0], numberOfRows);

CarbonReadDataHolder measureDataHolder = new CarbonReadDataHolder(values);

Expand Down Expand Up @@ -217,7 +217,7 @@ private MeasureColumnDataChunk[] readMeasureChunksInGroup(FileHolder fileReader,
// uncompress
values.uncompress(compressionModel.getConvertedDataType()[0], data, copyPoint,
measureColumnChunk.data_page_length, compressionModel.getMantissa()[0],
compressionModel.getMaxValue()[0]);
compressionModel.getMaxValue()[0], numberOfRows);

CarbonReadDataHolder measureDataHolder = new CarbonReadDataHolder(values);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
package org.apache.carbondata.core.datastore.chunk.store;

import org.apache.carbondata.core.constants.CarbonCommonConstants;
import org.apache.carbondata.core.datastore.chunk.store.impl.safe.SafeBigDecimalMeasureChunkStore;
import org.apache.carbondata.core.datastore.chunk.store.impl.safe.SafeByteMeasureChunkStore;
import org.apache.carbondata.core.datastore.chunk.store.impl.safe.SafeDoubleMeasureChunkStore;
import org.apache.carbondata.core.datastore.chunk.store.impl.safe.SafeIntMeasureChunkStore;
import org.apache.carbondata.core.datastore.chunk.store.impl.safe.SafeLongMeasureChunkStore;
import org.apache.carbondata.core.datastore.chunk.store.impl.safe.SafeShortMeasureChunkStore;
import org.apache.carbondata.core.datastore.chunk.store.impl.unsafe.UnsafeBigDecimalMeasureChunkStore;
import org.apache.carbondata.core.datastore.chunk.store.impl.unsafe.UnsafeByteMeasureChunkStore;
import org.apache.carbondata.core.datastore.chunk.store.impl.unsafe.UnsafeDoubleMeasureChunkStore;
import org.apache.carbondata.core.datastore.chunk.store.impl.unsafe.UnsafeIntMeasureChunkStore;
Expand Down Expand Up @@ -73,8 +75,9 @@ public MeasureDataChunkStore getMeasureDataChunkStore(DataType dataType, int num
return new SafeIntMeasureChunkStore(numberOfRows);
case DATA_LONG:
return new SafeLongMeasureChunkStore(numberOfRows);
case DATA_BIGDECIMAL:
return new SafeBigDecimalMeasureChunkStore(numberOfRows);
case DATA_DOUBLE:
return new SafeDoubleMeasureChunkStore(numberOfRows);
default:
return new SafeDoubleMeasureChunkStore(numberOfRows);
}
Expand All @@ -88,8 +91,9 @@ public MeasureDataChunkStore getMeasureDataChunkStore(DataType dataType, int num
return new UnsafeIntMeasureChunkStore(numberOfRows);
case DATA_LONG:
return new UnsafeLongMeasureChunkStore(numberOfRows);
case DATA_BIGDECIMAL:
return new UnsafeBigDecimalMeasureChunkStore(numberOfRows);
case DATA_DOUBLE:
return new UnsafeDoubleMeasureChunkStore(numberOfRows);
default:
return new UnsafeDoubleMeasureChunkStore(numberOfRows);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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.carbondata.core.datastore.chunk.store.impl.safe;

import java.math.BigDecimal;
import java.nio.ByteBuffer;

import org.apache.carbondata.core.constants.CarbonCommonConstants;
import org.apache.carbondata.core.util.DataTypeUtil;

/**
* Responsibility is store the big decimal measure data in memory,
*/
public class SafeBigDecimalMeasureChunkStore extends SafeAbstractMeasureDataChunkStore<byte[]> {

/**
* data chunk
*/
private byte[] dataChunk;

/**
* offset of actual data
*/
private int[] dataOffsets;

public SafeBigDecimalMeasureChunkStore(int numberOfRows) {
super(numberOfRows);
this.dataOffsets = new int[numberOfRows];
}

@Override public void putData(byte[] data) {
this.dataChunk = data;
// As data is of variable length and data format is
// <length in int><data><length in int><data>
// we need to store offset of each data so data can be accessed directly
// for example:
//data = {0,0,0,0,5,1,2,3,4,5,0,0,0,0,6,0,1,2,3,4,5,0,0,0,0,2,8,9}
//so value stored in offset will be position of actual data
// [5,14,24]
// to store this value we need to get the actual data length + 4 bytes used for storing the
// length

// start position will be used to store the current data position
int startOffset = 0;
// as first position will be start from 4 byte as data is stored first in the memory block
// we need to skip first two bytes this is because first two bytes will be length of the data
// which we have to skip
dataOffsets[0] = CarbonCommonConstants.INT_SIZE_IN_BYTE;
// creating a byte buffer which will wrap the length of the row
ByteBuffer buffer = ByteBuffer.allocate(CarbonCommonConstants.INT_SIZE_IN_BYTE);
for (int i = 1; i < numberOfRows; i++) {
buffer.put(data, startOffset, CarbonCommonConstants.INT_SIZE_IN_BYTE);
buffer.flip();
// so current row position will be
// previous row length + 4 bytes used for storing previous row data
startOffset += buffer.getInt() + CarbonCommonConstants.INT_SIZE_IN_BYTE;
// as same byte buffer is used to avoid creating many byte buffer for each row
// we need to clear the byte buffer
buffer.clear();
dataOffsets[i] = startOffset + CarbonCommonConstants.INT_SIZE_IN_BYTE;
}
}

/**
* to get the byte value
*
* @param index
* @return byte value based on index
*/
@Override public BigDecimal getBigDecimal(int index) {
int currentDataOffset = dataOffsets[index];
int length = 0;
// calculating the length of data
if (index < numberOfRows - 1) {
length = (int) (dataOffsets[index + 1] - (currentDataOffset
+ CarbonCommonConstants.INT_SIZE_IN_BYTE));
} else {
// for last record
length = (int) (this.dataChunk.length - currentDataOffset);
}
return DataTypeUtil.byteToBigDecimal(dataChunk, currentDataOffset, length);
}

}
Loading

0 comments on commit 4a1f6ae

Please sign in to comment.