static Object blockToNativeValue(Type type, Block block) { return readNativeValue(type, block, 0); } }
@UsedByGeneratedCode public static Object elementAt(MethodHandle keyEqualsMethod, Type keyType, Type valueType, Block map, double key) { SingleMapBlock mapBlock = (SingleMapBlock) map; int valuePosition = mapBlock.seekKeyExact(key); if (valuePosition == -1) { return null; } return readNativeValue(valueType, mapBlock, valuePosition); }
@UsedByGeneratedCode public static Object elementAt(MethodHandle keyEqualsMethod, Type keyType, Type valueType, Block map, boolean key) { SingleMapBlock mapBlock = (SingleMapBlock) map; int valuePosition = mapBlock.seekKeyExact(key); if (valuePosition == -1) { return null; } return readNativeValue(valueType, mapBlock, valuePosition); }
@UsedByGeneratedCode public static Object elementAt(MethodHandle keyEqualsMethod, Type keyType, Type valueType, Block map, long key) { SingleMapBlock mapBlock = (SingleMapBlock) map; int valuePosition = mapBlock.seekKeyExact(key); if (valuePosition == -1) { return null; } return readNativeValue(valueType, mapBlock, valuePosition); }
@UsedByGeneratedCode public static Object elementAt(MethodHandle keyEqualsMethod, Type keyType, Type valueType, Block map, Slice key) { SingleMapBlock mapBlock = (SingleMapBlock) map; int valuePosition = mapBlock.seekKeyExact(key); if (valuePosition == -1) { return null; } return readNativeValue(valueType, mapBlock, valuePosition); }
@UsedByGeneratedCode public static Object elementAt(MethodHandle keyEqualsMethod, Type keyType, Type valueType, Block map, Object key) { SingleMapBlock mapBlock = (SingleMapBlock) map; int valuePosition = mapBlock.seekKeyExact((Block) key); if (valuePosition == -1) { return null; } return readNativeValue(valueType, mapBlock, valuePosition); } }
@UsedByGeneratedCode public static Object subscript(boolean legacyMissingKey, InterpretedFunctionInvoker functionInvoker, Type keyType, Type valueType, ConnectorSession session, Block map, boolean key) { SingleMapBlock mapBlock = (SingleMapBlock) map; int valuePosition = mapBlock.seekKeyExact(key); if (valuePosition == -1) { if (legacyMissingKey) { return null; } throw throwMissingKeyException(keyType, functionInvoker, key, session); } return readNativeValue(valueType, mapBlock, valuePosition); }
@UsedByGeneratedCode public static Object subscript(boolean legacyMissingKey, InterpretedFunctionInvoker functionInvoker, Type keyType, Type valueType, ConnectorSession session, Block map, Slice key) { SingleMapBlock mapBlock = (SingleMapBlock) map; int valuePosition = mapBlock.seekKeyExact(key); if (valuePosition == -1) { if (legacyMissingKey) { return null; } throw throwMissingKeyException(keyType, functionInvoker, key, session); } return readNativeValue(valueType, mapBlock, valuePosition); }
@UsedByGeneratedCode public static Object subscript(boolean legacyMissingKey, InterpretedFunctionInvoker functionInvoker, Type keyType, Type valueType, ConnectorSession session, Block map, Object key) { SingleMapBlock mapBlock = (SingleMapBlock) map; int valuePosition = mapBlock.seekKeyExact((Block) key); if (valuePosition == -1) { if (legacyMissingKey) { return null; } throw throwMissingKeyException(keyType, functionInvoker, key, session); } return readNativeValue(valueType, mapBlock, valuePosition); }
@UsedByGeneratedCode public static Object subscript(boolean legacyMissingKey, InterpretedFunctionInvoker functionInvoker, Type keyType, Type valueType, ConnectorSession session, Block map, long key) { SingleMapBlock mapBlock = (SingleMapBlock) map; int valuePosition = mapBlock.seekKeyExact(key); if (valuePosition == -1) { if (legacyMissingKey) { return null; } throw throwMissingKeyException(keyType, functionInvoker, key, session); } return readNativeValue(valueType, mapBlock, valuePosition); }
@UsedByGeneratedCode public static Object subscript(boolean legacyMissingKey, InterpretedFunctionInvoker functionInvoker, Type keyType, Type valueType, ConnectorSession session, Block map, double key) { SingleMapBlock mapBlock = (SingleMapBlock) map; int valuePosition = mapBlock.seekKeyExact(key); if (valuePosition == -1) { if (legacyMissingKey) { return null; } throw throwMissingKeyException(keyType, functionInvoker, key, session); } return readNativeValue(valueType, mapBlock, valuePosition); }
public static Object reduce( Type inputType, Block block, Object initialIntermediateValue, BinaryFunctionInterface inputFunction, UnaryFunctionInterface outputFunction) { int positionCount = block.getPositionCount(); Object intermediateValue = initialIntermediateValue; for (int position = 0; position < positionCount; position++) { Object input = readNativeValue(inputType, block, position); intermediateValue = inputFunction.apply(intermediateValue, input); } return outputFunction.apply(intermediateValue); } }
protected static int compare( RowType rowType, List<MethodHandle> comparisonFunctions, Block leftRow, Block rightRow) { for (int i = 0; i < leftRow.getPositionCount(); i++) { checkElementNotNull(leftRow.isNull(i), "null value at position " + i); checkElementNotNull(rightRow.isNull(i), "null value at position " + i); Type type = rowType.getTypeParameters().get(i); Object leftElement = readNativeValue(type, leftRow, i); Object rightElement = readNativeValue(type, rightRow, i); try { if ((boolean) comparisonFunctions.get(i).invoke(leftElement, rightElement)) { return 1; } if ((boolean) comparisonFunctions.get(i).invoke(rightElement, leftElement)) { return -1; } } catch (Throwable t) { throw internalError(t); } } return 0; } }
/** * Recursive helper function used by {@link AccumuloRowSerializer#getArrayFromBlock} and * {@link AccumuloRowSerializer#getMapFromBlock} to decode the Block into a Java type. * * @param type Presto type * @param block Block to decode * @param position Position in the block to get * @return Java object from the Block */ static Object readObject(Type type, Block block, int position) { if (Types.isArrayType(type)) { Type elementType = Types.getElementType(type); return getArrayFromBlock(elementType, block.getObject(position, Block.class)); } else if (Types.isMapType(type)) { return getMapFromBlock(type, block.getObject(position, Block.class)); } else { if (type.getJavaType() == Slice.class) { Slice slice = (Slice) TypeUtils.readNativeValue(type, block, position); return type.equals(VarcharType.VARCHAR) ? slice.toStringUtf8() : slice.getBytes(); } return TypeUtils.readNativeValue(type, block, position); } } }
public static Block filter(Type type, Block block, MethodHandle function) { int positionCount = block.getPositionCount(); BlockBuilder resultBuilder = type.createBlockBuilder(null, positionCount); for (int position = 0; position < positionCount; position++) { Long input = (Long) readNativeValue(type, block, position); Boolean keep; try { keep = (Boolean) function.invokeExact(input); } catch (Throwable t) { throwIfUnchecked(t); throw new RuntimeException(t); } if (TRUE.equals(keep)) { block.writePositionTo(position, resultBuilder); } } return resultBuilder.build(); } }
checkElementNotNull(leftArray.isNull(index), ARRAY_NULL_ELEMENT_MSG); checkElementNotNull(rightArray.isNull(index), ARRAY_NULL_ELEMENT_MSG); Object leftElement = readNativeValue(type, leftArray, index); Object rightElement = readNativeValue(type, rightArray, index); try { if ((boolean) greaterThanFunction.invoke(leftElement, rightElement)) {
@TypeParameter("T") @SqlType(StandardTypes.BOOLEAN) public static boolean greaterThan( @OperatorDependency(operator = GREATER_THAN, returnType = StandardTypes.BOOLEAN, 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); Object leftElement = readNativeValue(type, leftArray, index); Object rightElement = readNativeValue(type, rightArray, index); try { if ((boolean) greaterThanFunction.invoke(leftElement, rightElement)) { return true; } if ((boolean) greaterThanFunction.invoke(rightElement, leftElement)) { return false; } } catch (Throwable t) { throw internalError(t); } index++; } return leftArray.getPositionCount() > rightArray.getPositionCount(); }
@TypeParameter("E") @SqlNullable @SqlType("E") public static Object generic(@TypeParameter("E") Type type, @BlockPosition @SqlType("E") Block block, @BlockIndex int position) { hitBlockPositionObject.set(true); return readNativeValue(type, block, position); }
@TypeParameter("T") @SqlType(StandardTypes.BIGINT) public static long hash( @OperatorDependency(operator = HASH_CODE, returnType = StandardTypes.BIGINT, argumentTypes = {"T"}) MethodHandle hashFunction, @TypeParameter("T") Type type, @SqlType("array(T)") Block block) { try { long hash = 0; for (int i = 0; i < block.getPositionCount(); i++) { hash = CombineHashFunction.getHash(hash, block.isNull(i) ? NULL_HASH_CODE : (long) hashFunction.invoke(readNativeValue(type, block, i))); } return hash; } catch (Throwable t) { throw internalError(t); } }
@TypeParameter("T") @SqlType(StandardTypes.BOOLEAN) public static boolean indeterminate( @OperatorDependency(operator = INDETERMINATE, returnType = StandardTypes.BOOLEAN, argumentTypes = {"T"}) MethodHandle elementIndeterminateFunction, @TypeParameter("T") Type type, @SqlType("array(T)") Block block, @IsNull boolean isNull) { if (isNull) { return true; } for (int i = 0; i < block.getPositionCount(); i++) { if (block.isNull(i)) { return true; } try { if ((boolean) elementIndeterminateFunction.invoke(readNativeValue(type, block, i), false)) { return true; } } catch (Throwable t) { throw internalError(t); } } return false; } }