use of io.trino.type.BlockTypeOperators.BlockPositionHashCode in project trino by trinodb.
the class MapUnionAggregation method specialize.
@Override
public AggregationMetadata specialize(BoundSignature boundSignature) {
MapType outputType = (MapType) boundSignature.getReturnType();
Type keyType = outputType.getKeyType();
BlockPositionEqual keyEqual = blockTypeOperators.getEqualOperator(keyType);
BlockPositionHashCode keyHashCode = blockTypeOperators.getHashCodeOperator(keyType);
Type valueType = outputType.getValueType();
KeyValuePairStateSerializer stateSerializer = new KeyValuePairStateSerializer(outputType, keyEqual, keyHashCode);
MethodHandle inputFunction = MethodHandles.insertArguments(INPUT_FUNCTION, 0, keyType, keyEqual, keyHashCode, valueType);
inputFunction = normalizeInputMethod(inputFunction, boundSignature, STATE, INPUT_CHANNEL);
return new AggregationMetadata(inputFunction, Optional.empty(), Optional.of(COMBINE_FUNCTION), OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor<>(KeyValuePairsState.class, stateSerializer, new KeyValuePairsStateFactory(keyType, valueType))));
}
use of io.trino.type.BlockTypeOperators.BlockPositionHashCode in project trino by trinodb.
the class MapAggregationFunction method specialize.
@Override
public AggregationMetadata specialize(BoundSignature boundSignature) {
MapType outputType = (MapType) boundSignature.getReturnType();
Type keyType = outputType.getKeyType();
BlockPositionEqual keyEqual = blockTypeOperators.getEqualOperator(keyType);
BlockPositionHashCode keyHashCode = blockTypeOperators.getHashCodeOperator(keyType);
Type valueType = outputType.getValueType();
KeyValuePairStateSerializer stateSerializer = new KeyValuePairStateSerializer(outputType, keyEqual, keyHashCode);
return new AggregationMetadata(MethodHandles.insertArguments(INPUT_FUNCTION, 0, keyType, keyEqual, keyHashCode, valueType), Optional.empty(), Optional.of(COMBINE_FUNCTION), OUTPUT_FUNCTION, ImmutableList.of(new AccumulatorStateDescriptor<>(KeyValuePairsState.class, stateSerializer, new KeyValuePairsStateFactory(keyType, valueType))));
}
use of io.trino.type.BlockTypeOperators.BlockPositionHashCode in project trino by trinodb.
the class MapToMapCast method specialize.
@Override
public ScalarFunctionImplementation specialize(BoundSignature boundSignature, FunctionDependencies functionDependencies) {
checkArgument(boundSignature.getArity() == 1, "Expected arity to be 1");
MapType fromMapType = (MapType) boundSignature.getArgumentType(0);
Type fromKeyType = fromMapType.getKeyType();
Type fromValueType = fromMapType.getValueType();
MapType toMapType = (MapType) boundSignature.getReturnType();
Type toKeyType = toMapType.getKeyType();
Type toValueType = toMapType.getValueType();
MethodHandle keyProcessor = buildProcessor(functionDependencies, fromKeyType, toKeyType, true);
MethodHandle valueProcessor = buildProcessor(functionDependencies, fromValueType, toValueType, false);
BlockPositionEqual keyEqual = blockTypeOperators.getEqualOperator(toKeyType);
BlockPositionHashCode keyHashCode = blockTypeOperators.getHashCodeOperator(toKeyType);
MethodHandle target = MethodHandles.insertArguments(METHOD_HANDLE, 0, keyProcessor, valueProcessor, toMapType, keyEqual, keyHashCode);
return new ChoicesScalarFunctionImplementation(boundSignature, NULLABLE_RETURN, ImmutableList.of(NEVER_NULL), target);
}
use of io.trino.type.BlockTypeOperators.BlockPositionHashCode in project trino by trinodb.
the class MapConcatFunction method specialize.
@Override
protected ScalarFunctionImplementation specialize(BoundSignature boundSignature) {
if (boundSignature.getArity() < 2) {
throw new TrinoException(INVALID_FUNCTION_ARGUMENT, "There must be two or more concatenation arguments to " + FUNCTION_NAME);
}
MapType mapType = (MapType) boundSignature.getReturnType();
Type keyType = mapType.getKeyType();
BlockPositionEqual keyEqual = blockTypeOperators.getEqualOperator(keyType);
BlockPositionHashCode keyHashCode = blockTypeOperators.getHashCodeOperator(keyType);
MethodHandleAndConstructor methodHandleAndConstructor = generateVarArgsToArrayAdapter(Block.class, Block.class, boundSignature.getArity(), MethodHandles.insertArguments(METHOD_HANDLE, 0, mapType, keyEqual, keyHashCode), USER_STATE_FACTORY.bindTo(mapType));
return new ChoicesScalarFunctionImplementation(boundSignature, FAIL_ON_NULL, nCopies(boundSignature.getArity(), NEVER_NULL), methodHandleAndConstructor.getMethodHandle(), Optional.of(methodHandleAndConstructor.getConstructor()));
}
use of io.trino.type.BlockTypeOperators.BlockPositionHashCode in project trino by trinodb.
the class TestRealType method testNaNHash.
@Test
public void testNaNHash() {
BlockBuilder blockBuilder = new IntArrayBlockBuilder(null, 4);
blockBuilder.writeInt(floatToIntBits(Float.NaN));
blockBuilder.writeInt(floatToRawIntBits(Float.NaN));
// the following two are the integer values of a float NaN
blockBuilder.writeInt(-0x400000);
blockBuilder.writeInt(0x7fc00000);
BlockPositionHashCode hashCodeOperator = blockTypeOperators.getHashCodeOperator(REAL);
assertEquals(hashCodeOperator.hashCode(blockBuilder, 0), hashCodeOperator.hashCode(blockBuilder, 1));
assertEquals(hashCodeOperator.hashCode(blockBuilder, 0), hashCodeOperator.hashCode(blockBuilder, 2));
assertEquals(hashCodeOperator.hashCode(blockBuilder, 0), hashCodeOperator.hashCode(blockBuilder, 3));
}
Aggregations