Java Code Examples for io.prestosql.spi.type.Type#getLong()
The following examples show how to use
io.prestosql.spi.type.Type#getLong() .
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: PrestoThriftTypeUtils.java From presto with Apache License 2.0 | 6 votes |
public static PrestoThriftBlock fromLongBasedBlock(Block block, Type type, BiFunction<boolean[], long[], PrestoThriftBlock> result) { int positions = block.getPositionCount(); if (positions == 0) { return result.apply(null, null); } boolean[] nulls = null; long[] longs = null; for (int position = 0; position < positions; position++) { if (block.isNull(position)) { if (nulls == null) { nulls = new boolean[positions]; } nulls[position] = true; } else { if (longs == null) { longs = new long[positions]; } longs[position] = type.getLong(block, position); } } return result.apply(nulls, longs); }
Example 2
Source File: PrestoThriftTypeUtils.java From presto with Apache License 2.0 | 6 votes |
public static PrestoThriftBlock fromIntBasedBlock(Block block, Type type, BiFunction<boolean[], int[], PrestoThriftBlock> result) { int positions = block.getPositionCount(); if (positions == 0) { return result.apply(null, null); } boolean[] nulls = null; int[] ints = null; for (int position = 0; position < positions; position++) { if (block.isNull(position)) { if (nulls == null) { nulls = new boolean[positions]; } nulls[position] = true; } else { if (ints == null) { ints = new int[positions]; } ints[position] = (int) type.getLong(block, position); } } return result.apply(nulls, ints); }
Example 3
Source File: ArrayFilterFunction.java From presto with Apache License 2.0 | 6 votes |
@TypeParameter("T") @TypeParameterSpecialization(name = "T", nativeContainerType = long.class) @SqlType("array(T)") public static Block filterLong( @TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") LongToBooleanFunction function) { int positionCount = arrayBlock.getPositionCount(); BlockBuilder resultBuilder = elementType.createBlockBuilder(null, positionCount); for (int position = 0; position < positionCount; position++) { Long input = null; if (!arrayBlock.isNull(position)) { input = elementType.getLong(arrayBlock, position); } Boolean keep = function.apply(input); if (TRUE.equals(keep)) { elementType.appendTo(arrayBlock, position, resultBuilder); } } return resultBuilder.build(); }
Example 4
Source File: ArrayMinMaxUtils.java From presto with Apache License 2.0 | 6 votes |
@UsedByGeneratedCode public static Long longArrayMinMax(MethodHandle compareMethodHandle, Type elementType, Block block) { try { if (block.getPositionCount() == 0) { return null; } long selectedValue = elementType.getLong(block, 0); for (int i = 0; i < block.getPositionCount(); i++) { if (block.isNull(i)) { return null; } long value = elementType.getLong(block, i); if ((boolean) compareMethodHandle.invokeExact(value, selectedValue)) { selectedValue = value; } } return selectedValue; } catch (Throwable t) { throw internalError(t); } }
Example 5
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 6
Source File: PageRecordSet.java From presto with Apache License 2.0 | 5 votes |
@Override public long getLong(int field) { checkState(position >= 0, "Not yet advanced"); checkState(position < page.getPositionCount(), "Already finished"); Type type = types.get(field); return type.getLong(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 = long.class) @SqlType(StandardTypes.BOOLEAN) @SqlNullable public static Boolean allMatchLong( @TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") LongToBooleanFunction function) { boolean hasNullResult = false; int positionCount = arrayBlock.getPositionCount(); for (int i = 0; i < positionCount; i++) { Long element = null; if (!arrayBlock.isNull(i)) { element = elementType.getLong(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: ArrayLessThanOrEqualOperator.java From presto with Apache License 2.0 | 5 votes |
@TypeParameter("E") @TypeParameterSpecialization(name = "E", nativeContainerType = long.class) @SqlType(StandardTypes.BOOLEAN) public static boolean lessThanOrEqualLong( @OperatorDependency(operator = LESS_THAN, argumentTypes = {"E", "E"}) MethodHandle lessThanFunction, @TypeParameter("E") Type type, @SqlType("array(E)") Block leftArray, @SqlType("array(E)") Block rightArray) { int len = Math.min(leftArray.getPositionCount(), rightArray.getPositionCount()); int index = 0; while (index < len) { checkElementNotNull(leftArray.isNull(index), ARRAY_NULL_ELEMENT_MSG); checkElementNotNull(rightArray.isNull(index), ARRAY_NULL_ELEMENT_MSG); long leftElement = type.getLong(leftArray, index); long rightElement = type.getLong(rightArray, index); try { if ((boolean) lessThanFunction.invokeExact(leftElement, rightElement)) { return true; } if ((boolean) lessThanFunction.invokeExact(rightElement, leftElement)) { return false; } } catch (Throwable t) { throw internalError(t); } index++; } return leftArray.getPositionCount() <= rightArray.getPositionCount(); }
Example 9
Source File: ArrayGreaterThanOperator.java From presto with Apache License 2.0 | 5 votes |
@TypeParameter("T") @TypeParameterSpecialization(name = "T", nativeContainerType = long.class) @SqlType(StandardTypes.BOOLEAN) public static boolean greaterThanLong( @OperatorDependency(operator = GREATER_THAN, argumentTypes = {"T", "T"}) MethodHandle greaterThanFunction, @TypeParameter("T") Type type, @SqlType("array(T)") Block leftArray, @SqlType("array(T)") Block rightArray) { int len = Math.min(leftArray.getPositionCount(), rightArray.getPositionCount()); int index = 0; while (index < len) { checkElementNotNull(leftArray.isNull(index), ARRAY_NULL_ELEMENT_MSG); checkElementNotNull(rightArray.isNull(index), ARRAY_NULL_ELEMENT_MSG); long leftElement = type.getLong(leftArray, index); long rightElement = type.getLong(rightArray, index); try { if ((boolean) greaterThanFunction.invokeExact(leftElement, rightElement)) { return true; } if ((boolean) greaterThanFunction.invokeExact(rightElement, leftElement)) { return false; } } catch (Throwable t) { throw internalError(t); } index++; } return leftArray.getPositionCount() > rightArray.getPositionCount(); }
Example 10
Source File: ArrayAnyMatchFunction.java From presto with Apache License 2.0 | 5 votes |
@TypeParameter("T") @TypeParameterSpecialization(name = "T", nativeContainerType = long.class) @SqlType(StandardTypes.BOOLEAN) @SqlNullable public static Boolean anyMatchLong( @TypeParameter("T") Type elementType, @SqlType("array(T)") Block arrayBlock, @SqlType("function(T, boolean)") LongToBooleanFunction function) { boolean hasNullResult = false; int positionCount = arrayBlock.getPositionCount(); for (int i = 0; i < positionCount; i++) { Long element = null; if (!arrayBlock.isNull(i)) { element = elementType.getLong(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 11
Source File: ArrayElementAtFunction.java From presto with Apache License 2.0 | 5 votes |
@TypeParameter("E") @SqlNullable @SqlType("E") public static Long longElementAt(@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.getLong(array, position); }
Example 12
Source File: ArrayLessThanOperator.java From presto with Apache License 2.0 | 5 votes |
@TypeParameter("E") @TypeParameterSpecialization(name = "E", nativeContainerType = long.class) @SqlType(StandardTypes.BOOLEAN) public static boolean lessThanLong( @OperatorDependency(operator = LESS_THAN, argumentTypes = {"E", "E"}) MethodHandle lessThanFunction, @TypeParameter("E") Type type, @SqlType("array(E)") Block leftArray, @SqlType("array(E)") Block rightArray) { int len = Math.min(leftArray.getPositionCount(), rightArray.getPositionCount()); int index = 0; while (index < len) { checkElementNotNull(leftArray.isNull(index), ARRAY_NULL_ELEMENT_MSG); checkElementNotNull(rightArray.isNull(index), ARRAY_NULL_ELEMENT_MSG); long leftElement = type.getLong(leftArray, index); long rightElement = type.getLong(rightArray, index); try { if ((boolean) lessThanFunction.invokeExact(leftElement, rightElement)) { return true; } if ((boolean) lessThanFunction.invokeExact(rightElement, leftElement)) { return false; } } catch (Throwable t) { throw internalError(t); } index++; } return leftArray.getPositionCount() < rightArray.getPositionCount(); }
Example 13
Source File: ArraySubscriptOperator.java From presto with Apache License 2.0 | 5 votes |
@UsedByGeneratedCode public static Long longSubscript(Type elementType, Block array, long index) { checkIndex(array, index); int position = toIntExact(index - 1); if (array.isNull(position)) { return null; } return elementType.getLong(array, position); }
Example 14
Source File: ShardStats.java From presto with Apache License 2.0 | 5 votes |
private static ColumnStats indexLong(Type type, OrcRecordReader reader, long columnId) throws IOException { boolean minSet = false; boolean maxSet = false; long min = 0; long max = 0; 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; } long value = type.getLong(block, i); if (!minSet || (value < min)) { minSet = true; min = value; } if (!maxSet || (value > max)) { maxSet = true; max = value; } } } return new ColumnStats(columnId, minSet ? min : null, maxSet ? max : null); }
Example 15
Source File: IcebergPageSink.java From presto with Apache License 2.0 | 5 votes |
public static Object getIcebergValue(Block block, int position, Type type) { if (block.isNull(position)) { return null; } if (type instanceof BigintType) { return type.getLong(block, position); } if (type instanceof IntegerType || type instanceof SmallintType || type instanceof TinyintType || type instanceof DateType) { return toIntExact(type.getLong(block, position)); } if (type instanceof BooleanType) { return type.getBoolean(block, position); } if (type instanceof DecimalType) { return readBigDecimal((DecimalType) type, block, position); } if (type instanceof RealType) { return intBitsToFloat(toIntExact(type.getLong(block, position))); } if (type instanceof DoubleType) { return type.getDouble(block, position); } if (type instanceof TimestampType) { return MILLISECONDS.toMicros(type.getLong(block, position)); } if (type instanceof TimestampWithTimeZoneType) { return MILLISECONDS.toMicros(unpackMillisUtc(type.getLong(block, position))); } if (type instanceof VarbinaryType) { return type.getSlice(block, position).getBytes(); } if (type instanceof VarcharType) { return type.getSlice(block, position).toStringUtf8(); } throw new UnsupportedOperationException("Type not supported as partition column: " + type.getDisplayName()); }
Example 16
Source File: HiveBucketingV1.java From presto with Apache License 2.0 | 4 votes |
static int hash(TypeInfo type, Block block, int position) { // This function mirrors the behavior of function hashCode in // HIVE-12025 ba83fd7bff serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorUtils.java // https://github.com/apache/hive/blob/ba83fd7bff/serde/src/java/org/apache/hadoop/hive/serde2/objectinspector/ObjectInspectorUtils.java if (block.isNull(position)) { return 0; } switch (type.getCategory()) { case PRIMITIVE: PrimitiveTypeInfo typeInfo = (PrimitiveTypeInfo) type; PrimitiveCategory primitiveCategory = typeInfo.getPrimitiveCategory(); Type prestoType = requireNonNull(HiveType.getPrimitiveType(typeInfo)); switch (primitiveCategory) { case BOOLEAN: return prestoType.getBoolean(block, position) ? 1 : 0; case BYTE: return SignedBytes.checkedCast(prestoType.getLong(block, position)); case SHORT: return Shorts.checkedCast(prestoType.getLong(block, position)); case INT: return toIntExact(prestoType.getLong(block, position)); case LONG: long bigintValue = prestoType.getLong(block, position); return (int) ((bigintValue >>> 32) ^ bigintValue); case FLOAT: // convert to canonical NaN if necessary return floatToIntBits(intBitsToFloat(toIntExact(prestoType.getLong(block, position)))); case DOUBLE: long doubleValue = doubleToLongBits(prestoType.getDouble(block, position)); return (int) ((doubleValue >>> 32) ^ doubleValue); case STRING: return hashBytes(0, prestoType.getSlice(block, position)); case VARCHAR: return hashBytes(1, prestoType.getSlice(block, position)); case DATE: // day offset from 1970-01-01 return toIntExact(prestoType.getLong(block, position)); case TIMESTAMP: return hashTimestamp(prestoType.getLong(block, position)); default: throw new UnsupportedOperationException("Computation of Hive bucket hashCode is not supported for Hive primitive category: " + primitiveCategory); } case LIST: return hashOfList((ListTypeInfo) type, block.getObject(position, Block.class)); case MAP: return hashOfMap((MapTypeInfo) type, block.getObject(position, Block.class)); default: // TODO: support more types, e.g. ROW throw new UnsupportedOperationException("Computation of Hive bucket hashCode is not supported for Hive category: " + type.getCategory()); } }