use of io.trino.type.BlockTypeOperators.BlockPositionEqual 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.BlockPositionEqual 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.BlockPositionEqual in project trino by trinodb.
the class TuplePageFilter method matches.
private boolean matches(Page page, int position) {
for (int channel = 0; channel < inputChannels.size(); channel++) {
BlockPositionEqual equalOperator = equalOperators.get(channel);
Block outputBlock = page.getBlock(channel);
Block singleTupleBlock = tuplePage.getBlock(channel);
if (!equalOperator.equal(singleTupleBlock, 0, outputBlock, position)) {
return false;
}
}
return true;
}
use of io.trino.type.BlockTypeOperators.BlockPositionEqual 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.BlockPositionEqual in project trino by trinodb.
the class StructuralTestUtil method mapBlocksEqual.
public static boolean mapBlocksEqual(Type keyType, Type valueType, Block block1, Block block2) {
if (block1.getPositionCount() != block2.getPositionCount()) {
return false;
}
BlockPositionEqual keyEqualOperator = TYPE_OPERATORS_CACHE.getEqualOperator(keyType);
BlockPositionEqual valueEqualOperator = TYPE_OPERATORS_CACHE.getEqualOperator(valueType);
for (int i = 0; i < block1.getPositionCount(); i += 2) {
if (block1.isNull(i) != block2.isNull(i) || block1.isNull(i + 1) != block2.isNull(i + 1)) {
return false;
}
if (!block1.isNull(i) && !keyEqualOperator.equal(block1, i, block2, i)) {
return false;
}
if (!block1.isNull(i + 1) && !valueEqualOperator.equal(block1, i + 1, block2, i + 1)) {
return false;
}
}
return true;
}
Aggregations