Java Code Examples for io.prestosql.spi.type.Type#compareTo()
The following examples show how to use
io.prestosql.spi.type.Type#compareTo() .
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: ArraysOverlapFunction.java From presto with Apache License 2.0 | 6 votes |
private static IntComparator intBlockCompare(Type type, Block block) { return new AbstractIntComparator() { @Override public int compare(int left, int right) { if (block.isNull(left) && block.isNull(right)) { return 0; } if (block.isNull(left)) { return 1; } if (block.isNull(right)) { return -1; } return type.compareTo(block, left, block, right); } }; }
Example 2
Source File: AbstractMinMaxAggregationFunction.java From presto with Apache License 2.0 | 5 votes |
@UsedByGeneratedCode public static void minInput(Type type, BlockPositionState state, Block block, int position) { if (state.getBlock() == null || type.compareTo(block, position, state.getBlock(), state.getPosition()) < 0) { state.setBlock(block); state.setPosition(position); } }
Example 3
Source File: AbstractMinMaxAggregationFunction.java From presto with Apache License 2.0 | 5 votes |
@UsedByGeneratedCode public static void maxInput(Type type, BlockPositionState state, Block block, int position) { if (state.getBlock() == null || type.compareTo(block, position, state.getBlock(), state.getPosition()) > 0) { state.setBlock(block); state.setPosition(position); } }
Example 4
Source File: AbstractMinMaxAggregationFunction.java From presto with Apache License 2.0 | 5 votes |
@UsedByGeneratedCode public static void minCombine(Type type, BlockPositionState state, BlockPositionState otherState) { if (state.getBlock() == null || type.compareTo(otherState.getBlock(), otherState.getPosition(), state.getBlock(), state.getPosition()) < 0) { state.setBlock(otherState.getBlock()); state.setPosition(otherState.getPosition()); } }
Example 5
Source File: AbstractMinMaxAggregationFunction.java From presto with Apache License 2.0 | 5 votes |
@UsedByGeneratedCode public static void maxCombine(Type type, BlockPositionState state, BlockPositionState otherState) { if (state.getBlock() == null || type.compareTo(otherState.getBlock(), otherState.getPosition(), state.getBlock(), state.getPosition()) > 0) { state.setBlock(otherState.getBlock()); state.setPosition(otherState.getPosition()); } }
Example 6
Source File: UnwrapCastInComparison.java From presto with Apache License 2.0 | 5 votes |
private static int compare(Type type, Object first, Object second) { return type.compareTo( Utils.nativeValueToBlock(type, first), 0, Utils.nativeValueToBlock(type, second), 0); }
Example 7
Source File: DomainTranslator.java From presto with Apache License 2.0 | 5 votes |
private int compareOriginalValueToCoerced(Type originalValueType, Object originalValue, Type coercedValueType, Object coercedValue) { ResolvedFunction castToOriginalTypeOperator = metadata.getCoercion(coercedValueType, originalValueType); Object coercedValueInOriginalType = functionInvoker.invoke(castToOriginalTypeOperator, session.toConnectorSession(), coercedValue); Block originalValueBlock = Utils.nativeValueToBlock(originalValueType, originalValue); Block coercedValueBlock = Utils.nativeValueToBlock(originalValueType, coercedValueInOriginalType); return originalValueType.compareTo(originalValueBlock, 0, coercedValueBlock, 0); }
Example 8
Source File: ArraysOverlapFunction.java From presto with Apache License 2.0 | 4 votes |
@SqlNullable @TypeParameter("E") @SqlType(StandardTypes.BOOLEAN) public Boolean arraysOverlap( @OperatorDependency(operator = LESS_THAN, argumentTypes = {"E", "E"}) MethodHandle lessThanFunction, @TypeParameter("E") Type type, @SqlType("array(E)") Block leftArray, @SqlType("array(E)") Block rightArray) { int leftPositionCount = leftArray.getPositionCount(); int rightPositionCount = rightArray.getPositionCount(); if (leftPositionCount == 0 || rightPositionCount == 0) { return false; } if (leftPositions == null || leftPositions.length < leftPositionCount) { leftPositions = new int[leftPositionCount * 2]; } if (rightPositions == null || rightPositions.length < rightPositionCount) { rightPositions = new int[rightPositionCount * 2]; } for (int i = 0; i < leftPositionCount; i++) { leftPositions[i] = i; } for (int i = 0; i < rightPositionCount; i++) { rightPositions[i] = i; } IntArrays.quickSort(leftPositions, 0, leftPositionCount, intBlockCompare(type, leftArray)); IntArrays.quickSort(rightPositions, 0, rightPositionCount, intBlockCompare(type, rightArray)); int leftCurrentPosition = 0; int rightCurrentPosition = 0; while (leftCurrentPosition < leftPositionCount && rightCurrentPosition < rightPositionCount) { if (leftArray.isNull(leftPositions[leftCurrentPosition]) || rightArray.isNull(rightPositions[rightCurrentPosition])) { // Nulls are in the end of the array. Non-null elements do not overlap. return null; } int compareValue = type.compareTo(leftArray, leftPositions[leftCurrentPosition], rightArray, rightPositions[rightCurrentPosition]); if (compareValue > 0) { rightCurrentPosition++; } else if (compareValue < 0) { leftCurrentPosition++; } else { return true; } } return leftArray.isNull(leftPositions[leftPositionCount - 1]) || rightArray.isNull(rightPositions[rightPositionCount - 1]) ? null : false; }