Java Code Examples for io.prestosql.spi.type.Type#getSlice()
The following examples show how to use
io.prestosql.spi.type.Type#getSlice() .
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: ArrayFilterFunction.java From presto with Apache License 2.0 | 6 votes |
@TypeParameter("T") @TypeParameterSpecialization(name = "T", nativeContainerType = Slice.class) @SqlType("array(T)") public static Block filterSlice( @TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") SliceToBooleanFunction function) { int positionCount = arrayBlock.getPositionCount(); BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount); for (int position = 0; position < positionCount; position++) { Slice input = null; if (!arrayBlock.isNull(position)) { input = elementType.getSlice(arrayBlock, position); } Boolean keep = function.apply(input); if (TRUE.equals(keep)) { elementType.appendTo(arrayBlock, position, resultBuilder); } } return resultBuilder.build(); }
Example 2
Source File: ArrayMinMaxUtils.java From presto with Apache License 2.0 | 6 votes |
@UsedByGeneratedCode public static Slice sliceArrayMinMax(MethodHandle compareMethodHandle, Type elementType, Block block) { try { if (block.getPositionCount() == 0) { return null; } Slice selectedValue = elementType.getSlice(block, 0); for (int i = 0; i < block.getPositionCount(); i++) { if (block.isNull(i)) { return null; } Slice value = elementType.getSlice(block, i); if ((boolean) compareMethodHandle.invokeExact(value, selectedValue)) { selectedValue = value; } } return selectedValue; } catch (Throwable t) { throw internalError(t); } }
Example 3
Source File: Row.java From presto with Apache License 2.0 | 6 votes |
private static Object getNativeContainerValue(Type type, Block block, int position) { if (block.isNull(position)) { return null; } else if (type.getJavaType() == boolean.class) { return type.getBoolean(block, position); } else if (type.getJavaType() == long.class) { return type.getLong(block, position); } else if (type.getJavaType() == double.class) { return type.getDouble(block, position); } else if (type.getJavaType() == Slice.class) { return type.getSlice(block, position); } else if (type.getJavaType() == Block.class) { return type.getObject(block, position); } else { throw new AssertionError("Unimplemented type: " + type); } }
Example 4
Source File: LongDecimalStatisticsBuilder.java From presto with Apache License 2.0 | 5 votes |
@Override public void addBlock(Type type, Block block) { int scale = ((DecimalType) type).getScale(); for (int position = 0; position < block.getPositionCount(); position++) { if (!block.isNull(position)) { Slice value = type.getSlice(block, position); addValue(new BigDecimal(Decimals.decodeUnscaledValue(value), scale)); } } }
Example 5
Source File: SliceData.java From presto with Apache License 2.0 | 5 votes |
public static PrestoThriftBlock fromSliceBasedBlock(Block block, Type type, CreateSliceThriftBlockFunction create) { int positions = block.getPositionCount(); if (positions == 0) { return create.apply(null, null, null); } boolean[] nulls = null; int[] sizes = null; byte[] bytes = null; int bytesIndex = 0; for (int position = 0; position < positions; position++) { if (block.isNull(position)) { if (nulls == null) { nulls = new boolean[positions]; } nulls[position] = true; } else { Slice value = type.getSlice(block, position); if (sizes == null) { sizes = new int[positions]; int totalBytes = totalSliceBytes(block); if (totalBytes > 0) { bytes = new byte[totalBytes]; } } int length = value.length(); sizes[position] = length; if (length > 0) { checkState(bytes != null); value.getBytes(0, bytes, bytesIndex, length); bytesIndex += length; } } } checkState(bytes == null || bytesIndex == bytes.length); return create.apply(nulls, sizes, bytes); }
Example 6
Source File: PageRecordSet.java From presto with Apache License 2.0 | 5 votes |
@Override public Slice getSlice(int field) { checkState(position >= 0, "Not yet advanced"); checkState(position < page.getPositionCount(), "Already finished"); Type type = types.get(field); return type.getSlice(page.getBlock(field), position); }
Example 7
Source File: ArrayAllMatchFunction.java From presto with Apache License 2.0 | 5 votes |
@TypeParameter("T") @TypeParameterSpecialization(name = "T", nativeContainerType = Slice.class) @SqlType(StandardTypes.BOOLEAN) @SqlNullable public static Boolean allMatchSlice( @TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") SliceToBooleanFunction function) { boolean hasNullResult = false; int positionCount = arrayBlock.getPositionCount(); for (int i = 0; i < positionCount; i++) { Slice element = null; if (!arrayBlock.isNull(i)) { element = elementType.getSlice(arrayBlock, i); } Boolean match = function.apply(element); if (FALSE.equals(match)) { return false; } if (match == null) { hasNullResult = true; } } if (hasNullResult) { return null; } return true; }
Example 8
Source File: ArrayAnyMatchFunction.java From presto with Apache License 2.0 | 5 votes |
@TypeParameter("T") @TypeParameterSpecialization(name = "T", nativeContainerType = Slice.class) @SqlType(StandardTypes.BOOLEAN) @SqlNullable public static Boolean anyMatchSlice( @TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") SliceToBooleanFunction function) { boolean hasNullResult = false; int positionCount = arrayBlock.getPositionCount(); for (int i = 0; i < positionCount; i++) { Slice element = null; if (!arrayBlock.isNull(i)) { element = elementType.getSlice(arrayBlock, i); } Boolean match = function.apply(element); if (TRUE.equals(match)) { return true; } if (match == null) { hasNullResult = true; } } if (hasNullResult) { return null; } return false; }
Example 9
Source File: ArrayElementAtFunction.java From presto with Apache License 2.0 | 5 votes |
@TypeParameter("E") @SqlNullable @SqlType("E") public static Slice sliceElementAt(@TypeParameter("E") Type elementType, @SqlType("array(E)") Block array, @SqlType("bigint") long index) { int position = checkedIndexToBlockPosition(array, index); if (position == -1) { return null; } if (array.isNull(position)) { return null; } return elementType.getSlice(array, position); }
Example 10
Source File: ArraySubscriptOperator.java From presto with Apache License 2.0 | 5 votes |
@UsedByGeneratedCode public static Slice sliceSubscript(Type elementType, Block array, long index) { checkIndex(array, index); int position = toIntExact(index - 1); if (array.isNull(position)) { return null; } return elementType.getSlice(array, position); }
Example 11
Source File: TestBlockAndPositionNullConvention.java From presto with Apache License 2.0 | 5 votes |
@TypeParameter("E") @SqlNullable @SqlType("E") public static Slice specializedSlice(@TypeParameter("E") Type type, @BlockPosition @SqlType(value = "E", nativeContainerType = Slice.class) Block block, @BlockIndex int position) { hitBlockPositionSlice.set(true); return type.getSlice(block, position); }
Example 12
Source File: ShardStats.java From presto with Apache License 2.0 | 5 votes |
private static ColumnStats indexString(Type type, OrcRecordReader reader, long columnId) throws IOException { boolean minSet = false; boolean maxSet = false; Slice min = null; Slice max = null; while (true) { Page page = reader.nextPage(); if (page == null) { break; } Block block = page.getBlock(0).getLoadedBlock(); for (int i = 0; i < page.getPositionCount(); i++) { if (block.isNull(i)) { continue; } Slice slice = type.getSlice(block, i); slice = truncateIndexValue(slice); if (!minSet || (slice.compareTo(min) < 0)) { minSet = true; min = slice; } if (!maxSet || (slice.compareTo(max) > 0)) { maxSet = true; max = slice; } } } return new ColumnStats(columnId, minSet ? min.toStringUtf8() : null, maxSet ? max.toStringUtf8() : null); }