Java Code Examples for io.prestosql.spi.block.Block#getSliceLength()
The following examples show how to use
io.prestosql.spi.block.Block#getSliceLength() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KuduUpdatablePageSource.java From presto with Apache License 2.0 | 6 votes |
@Override public void deleteRows(Block rowIds) { Schema schema = table.getSchema(); KuduSession session = clientSession.newSession(); session.setFlushMode(FlushMode.AUTO_FLUSH_BACKGROUND); try { try { for (int i = 0; i < rowIds.getPositionCount(); i++) { int len = rowIds.getSliceLength(i); Slice slice = rowIds.getSlice(i, 0, len); PartialRow row = KeyEncoderAccessor.decodePrimaryKey(schema, slice.getBytes()); Delete delete = table.newDelete(); RowHelper.copyPrimaryKey(schema, row, delete.getRow()); session.apply(delete); } } finally { session.close(); } } catch (KuduException e) { throw new RuntimeException(e); } }
Example 2
Source File: JsonOperators.java From presto with Apache License 2.0 | 6 votes |
@SqlType(BOOLEAN) public static boolean isDistinctFrom( @BlockPosition @SqlType(value = JSON, nativeContainerType = Slice.class) Block left, @BlockIndex int leftPosition, @BlockPosition @SqlType(value = JSON, nativeContainerType = Slice.class) Block right, @BlockIndex int rightPosition) { if (left.isNull(leftPosition) != right.isNull(rightPosition)) { return true; } if (left.isNull(leftPosition)) { return false; } int leftLength = left.getSliceLength(leftPosition); int rightLength = right.getSliceLength(rightPosition); if (leftLength != rightLength) { return true; } return !left.equals(leftPosition, 0, right, rightPosition, 0, leftLength); }
Example 3
Source File: VarcharOperators.java From presto with Apache License 2.0 | 6 votes |
@LiteralParameters({"x", "y"}) @SqlType(StandardTypes.BOOLEAN) public static boolean isDistinctFrom( @BlockPosition @SqlType(value = "varchar(x)", nativeContainerType = Slice.class) Block left, @BlockIndex int leftPosition, @BlockPosition @SqlType(value = "varchar(y)", nativeContainerType = Slice.class) Block right, @BlockIndex int rightPosition) { if (left.isNull(leftPosition) != right.isNull(rightPosition)) { return true; } if (left.isNull(leftPosition)) { return false; } int leftLength = left.getSliceLength(leftPosition); int rightLength = right.getSliceLength(rightPosition); if (leftLength != rightLength) { return true; } return !left.equals(leftPosition, 0, right, rightPosition, 0, leftLength); }
Example 4
Source File: VarbinaryOperators.java From presto with Apache License 2.0 | 6 votes |
@SqlType(StandardTypes.BOOLEAN) public static boolean isDistinctFrom( @BlockPosition @SqlType(value = StandardTypes.VARBINARY, nativeContainerType = Slice.class) Block left, @BlockIndex int leftPosition, @BlockPosition @SqlType(value = StandardTypes.VARBINARY, nativeContainerType = Slice.class) Block right, @BlockIndex int rightPosition) { if (left.isNull(leftPosition) != right.isNull(rightPosition)) { return true; } if (left.isNull(leftPosition)) { return false; } int leftLength = left.getSliceLength(leftPosition); int rightLength = right.getSliceLength(rightPosition); if (leftLength != rightLength) { return true; } return !left.equals(leftPosition, 0, right, rightPosition, 0, leftLength); }
Example 5
Source File: CharOperators.java From presto with Apache License 2.0 | 6 votes |
@LiteralParameters("x") @SqlType(StandardTypes.BOOLEAN) public static boolean isDistinctFrom( @BlockPosition @SqlType(value = "char(x)", nativeContainerType = Slice.class) Block left, @BlockIndex int leftPosition, @BlockPosition @SqlType(value = "char(x)", nativeContainerType = Slice.class) Block right, @BlockIndex int rightPosition) { if (left.isNull(leftPosition) != right.isNull(rightPosition)) { return true; } if (left.isNull(leftPosition)) { return false; } int leftLength = left.getSliceLength(leftPosition); int rightLength = right.getSliceLength(rightPosition); if (leftLength != rightLength) { return true; } return !left.equals(leftPosition, 0, right, rightPosition, 0, leftLength); }
Example 6
Source File: DictionaryBuilder.java From presto with Apache License 2.0 | 6 votes |
/** * Get slot position of element at {@code position} of {@code block} */ private long getHashPositionOfElement(Block block, int position) { checkArgument(!block.isNull(position), "position is null"); int length = block.getSliceLength(position); long hashPosition = getMaskedHash(block.hash(position, 0, length)); while (true) { int blockPosition = blockPositionByHash.get(hashPosition); if (blockPosition == EMPTY_SLOT) { // Doesn't have this element return hashPosition; } if (elementBlock.getSliceLength(blockPosition) == length && block.equals(position, 0, elementBlock, blockPosition, 0, length)) { // Already has this element return hashPosition; } hashPosition = getMaskedHash(hashPosition + 1); } }
Example 7
Source File: AbstractTestBlock.java From presto with Apache License 2.0 | 5 votes |
protected void assertSlicePosition(Block block, int position, Slice expectedSliceValue) { int length = block.getSliceLength(position); assertEquals(length, expectedSliceValue.length()); Block expectedBlock = toSingeValuedBlock(expectedSliceValue); for (int offset = 0; offset < length - 3; offset++) { assertEquals(block.getSlice(position, offset, 3), expectedSliceValue.slice(offset, 3)); assertTrue(block.bytesEqual(position, offset, expectedSliceValue, offset, 3)); // if your tests fail here, please change your test to not use this value assertFalse(block.bytesEqual(position, offset, Slices.utf8Slice("XXX"), 0, 3)); assertEquals(block.bytesCompare(position, offset, 3, expectedSliceValue, offset, 3), 0); assertTrue(block.bytesCompare(position, offset, 3, expectedSliceValue, offset, 2) > 0); Slice greaterSlice = createGreaterValue(expectedSliceValue, offset, 3); assertTrue(block.bytesCompare(position, offset, 3, greaterSlice, 0, greaterSlice.length()) < 0); assertTrue(block.equals(position, offset, expectedBlock, 0, offset, 3)); assertEquals(block.compareTo(position, offset, 3, expectedBlock, 0, offset, 3), 0); BlockBuilder blockBuilder = VARBINARY.createBlockBuilder(null, 1); block.writeBytesTo(position, offset, 3, blockBuilder); blockBuilder.closeEntry(); Block segment = blockBuilder.build(); assertTrue(block.equals(position, offset, segment, 0, 0, 3)); } }
Example 8
Source File: CharType.java From presto with Apache License 2.0 | 5 votes |
@Override public boolean equalTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition) { int leftLength = leftBlock.getSliceLength(leftPosition); int rightLength = rightBlock.getSliceLength(rightPosition); if (leftLength != rightLength) { return false; } return leftBlock.equals(leftPosition, 0, rightBlock, rightPosition, 0, leftLength); }
Example 9
Source File: VarcharType.java From presto with Apache License 2.0 | 5 votes |
@Override public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition) { int leftLength = leftBlock.getSliceLength(leftPosition); int rightLength = rightBlock.getSliceLength(rightPosition); return leftBlock.compareTo(leftPosition, 0, leftLength, rightBlock, rightPosition, 0, rightLength); }
Example 10
Source File: VarcharType.java From presto with Apache License 2.0 | 5 votes |
@Override public boolean equalTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition) { int leftLength = leftBlock.getSliceLength(leftPosition); int rightLength = rightBlock.getSliceLength(rightPosition); if (leftLength != rightLength) { return false; } return leftBlock.equals(leftPosition, 0, rightBlock, rightPosition, 0, leftLength); }
Example 11
Source File: VarbinaryType.java From presto with Apache License 2.0 | 5 votes |
@Override public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition) { int leftLength = leftBlock.getSliceLength(leftPosition); int rightLength = rightBlock.getSliceLength(rightPosition); return leftBlock.compareTo(leftPosition, 0, leftLength, rightBlock, rightPosition, 0, rightLength); }
Example 12
Source File: VarbinaryType.java From presto with Apache License 2.0 | 5 votes |
@Override public boolean equalTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition) { int leftLength = leftBlock.getSliceLength(leftPosition); int rightLength = rightBlock.getSliceLength(rightPosition); if (leftLength != rightLength) { return false; } return leftBlock.equals(leftPosition, 0, rightBlock, rightPosition, 0, leftLength); }
Example 13
Source File: ObjectIdType.java From presto with Apache License 2.0 | 5 votes |
@Override public int compareTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition) { int leftLength = leftBlock.getSliceLength(leftPosition); int rightLength = rightBlock.getSliceLength(rightPosition); return leftBlock.compareTo(leftPosition, 0, leftLength, rightBlock, rightPosition, 0, rightLength); }
Example 14
Source File: ObjectIdType.java From presto with Apache License 2.0 | 5 votes |
@Override public boolean equalTo(Block leftBlock, int leftPosition, Block rightBlock, int rightPosition) { int leftLength = leftBlock.getSliceLength(leftPosition); int rightLength = rightBlock.getSliceLength(rightPosition); if (leftLength != rightLength) { return false; } return leftBlock.equals(leftPosition, 0, rightBlock, rightPosition, 0, leftLength); }
Example 15
Source File: SliceData.java From presto with Apache License 2.0 | 5 votes |
private static int totalSliceBytes(Block block) { int totalBytes = 0; int positions = block.getPositionCount(); for (int position = 0; position < positions; position++) { totalBytes += block.getSliceLength(position); } return totalBytes; }
Example 16
Source File: SliceDictionaryColumnWriter.java From presto with Apache License 2.0 | 5 votes |
@Override public void writeBlock(Block block) { checkState(!closed); checkArgument(block.getPositionCount() > 0, "Block is empty"); if (directEncoded) { directColumnWriter.writeBlock(block); return; } // record values values.ensureCapacity(rowGroupValueCount + block.getPositionCount()); for (int position = 0; position < block.getPositionCount(); position++) { int index = dictionary.putIfAbsent(block, position); values.set(rowGroupValueCount, index); rowGroupValueCount++; totalValueCount++; if (!block.isNull(position)) { // todo min/max statistics only need to be updated if value was not already in the dictionary, but non-null count does statisticsBuilder.addValue(type.getSlice(block, position)); rawBytes += block.getSliceLength(position); totalNonNullValueCount++; } } }
Example 17
Source File: SliceDictionaryColumnWriter.java From presto with Apache License 2.0 | 4 votes |
private void bufferOutputData() { checkState(closed); checkState(!directEncoded); Block dictionaryElements = dictionary.getElementBlock(); // write dictionary in sorted order int[] sortedDictionaryIndexes = getSortedDictionaryNullsLast(dictionaryElements); for (int sortedDictionaryIndex : sortedDictionaryIndexes) { if (!dictionaryElements.isNull(sortedDictionaryIndex)) { int length = dictionaryElements.getSliceLength(sortedDictionaryIndex); dictionaryLengthStream.writeLong(length); Slice value = dictionaryElements.getSlice(sortedDictionaryIndex, 0, length); dictionaryDataStream.writeSlice(value); } } columnEncoding = new ColumnEncoding(DICTIONARY_V2, dictionaryElements.getPositionCount() - 1); // build index from original dictionary index to new sorted position int[] originalDictionaryToSortedIndex = new int[sortedDictionaryIndexes.length]; for (int sortOrdinal = 0; sortOrdinal < sortedDictionaryIndexes.length; sortOrdinal++) { int dictionaryIndex = sortedDictionaryIndexes[sortOrdinal]; originalDictionaryToSortedIndex[dictionaryIndex] = sortOrdinal; } if (!rowGroups.isEmpty()) { presentStream.recordCheckpoint(); dataStream.recordCheckpoint(); } for (DictionaryRowGroup rowGroup : rowGroups) { IntBigArray dictionaryIndexes = rowGroup.getDictionaryIndexes(); for (int position = 0; position < rowGroup.getValueCount(); position++) { presentStream.writeBoolean(dictionaryIndexes.get(position) != 0); } for (int position = 0; position < rowGroup.getValueCount(); position++) { int originalDictionaryIndex = dictionaryIndexes.get(position); // index zero in original dictionary is reserved for null if (originalDictionaryIndex != 0) { int sortedIndex = originalDictionaryToSortedIndex[originalDictionaryIndex]; if (sortedIndex < 0) { throw new IllegalArgumentException(); } dataStream.writeLong(sortedIndex); } } presentStream.recordCheckpoint(); dataStream.recordCheckpoint(); } // free the dictionary memory dictionary.clear(); dictionaryDataStream.close(); dictionaryLengthStream.close(); dataStream.close(); presentStream.close(); }