|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * |
| 6 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + * |
| 8 | + * Unless required by applicable law or agreed to in writing, software |
| 9 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | + * See the License for the specific language governing permissions and |
| 12 | + * limitations under the License. |
| 13 | + */ |
| 14 | +package io.trino.tests.tpch; |
| 15 | + |
| 16 | +import com.google.common.collect.ImmutableList; |
| 17 | +import io.airlift.slice.Slice; |
| 18 | +import io.airlift.slice.Slices; |
| 19 | +import io.airlift.units.DataSize; |
| 20 | +import io.trino.plugin.tpch.DecimalTypeMapping; |
| 21 | +import io.trino.plugin.tpch.TpchTables; |
| 22 | +import io.trino.spi.Page; |
| 23 | +import io.trino.spi.block.IntArrayBlock; |
| 24 | +import io.trino.spi.block.LongArrayBlock; |
| 25 | +import io.trino.spi.block.vstream.IntStreamVByte; |
| 26 | +import io.trino.spi.block.vstream.LongStreamVByte; |
| 27 | + |
| 28 | +import java.util.List; |
| 29 | + |
| 30 | +import static io.airlift.slice.SizeOf.SIZE_OF_INT; |
| 31 | + |
| 32 | +public class TestTpchDataSize |
| 33 | +{ |
| 34 | + private TestTpchDataSize() {} |
| 35 | + |
| 36 | + public static void main(String[] args) |
| 37 | + { |
| 38 | + List<Page> pages = ImmutableList.copyOf(TpchTables.getTablePages("lineitem", 3, DecimalTypeMapping.DECIMAL)); |
| 39 | + |
| 40 | + int totalSize = 0; |
| 41 | + int encodedTotalSize = 0; |
| 42 | + |
| 43 | + for (Page page : pages) { |
| 44 | + for (int i = 0; i < page.getChannelCount(); i++) { |
| 45 | + if (page.getBlock(i) instanceof LongArrayBlock longArrayBlock) { |
| 46 | + totalSize += longArrayBlock.getRawValues().length * SIZE_OF_INT; |
| 47 | + //System.out.println("block[" + i + "] size is " + longArrayBlock.getRawValues().length * SIZE_OF_INT); |
| 48 | + Slice buffer = Slices.allocate(LongStreamVByte.maxEncodedSize(longArrayBlock.getRawValues().length)); |
| 49 | + |
| 50 | + //System.out.println("Buffer size is " + buffer.length() + " for positions " + longArrayBlock.getRawValues().length); |
| 51 | + |
| 52 | + int size = LongStreamVByte.writeLongs(buffer.getOutput(), longArrayBlock.getRawValues()); |
| 53 | + //System.out.println("block[" + i + "] encoded size is " + size + " " + (size * 100.0f / (longArrayBlock.getRawValues().length * SIZE_OF_INT)) + "%"); |
| 54 | + encodedTotalSize += size; |
| 55 | + } |
| 56 | + |
| 57 | + if (page.getBlock(i) instanceof IntArrayBlock intArrayBlock) { |
| 58 | + totalSize += intArrayBlock.getRawValues().length * SIZE_OF_INT; |
| 59 | + //System.out.println("block[" + i + "] size is " + intArrayBlock.getRawValues().length * SIZE_OF_INT); |
| 60 | + Slice buffer = Slices.allocate(LongStreamVByte.maxEncodedSize(intArrayBlock.getRawValues().length)); |
| 61 | + int size = IntStreamVByte.writeInts(buffer.getOutput(), intArrayBlock.getRawValues()); |
| 62 | + //System.out.println("block[" + i + "] encoded size is " + size + " " + (size * 100.0f / (intArrayBlock.getRawValues().length * SIZE_OF_INT)) + "%"); |
| 63 | + encodedTotalSize += size; |
| 64 | + } |
| 65 | + } |
| 66 | + } |
| 67 | + |
| 68 | + System.out.println("Total size is " + DataSize.succinctBytes(totalSize)); |
| 69 | + System.out.println("Total encoded size is " + DataSize.succinctBytes(encodedTotalSize)); |
| 70 | + System.out.println("Total encoded size is " + (encodedTotalSize * 100.0f / totalSize) + "%"); |
| 71 | + } |
| 72 | +} |
0 commit comments