use of io.trino.spi.function.OperatorMethodHandle in project trino by trinodb.
the class RowType method getDistinctFromOperatorInvokers.
private static List<OperatorMethodHandle> getDistinctFromOperatorInvokers(TypeOperators typeOperators, List<Field> fields) {
boolean comparable = fields.stream().allMatch(field -> field.getType().isComparable());
if (!comparable) {
return emptyList();
}
// for large rows, use a generic loop with a megamorphic call site
if (fields.size() > MEGAMORPHIC_FIELD_COUNT) {
List<MethodHandle> distinctFromOperators = fields.stream().map(field -> typeOperators.getDistinctFromOperator(field.getType(), simpleConvention(FAIL_ON_NULL, BLOCK_POSITION, BLOCK_POSITION))).collect(toUnmodifiableList());
return singletonList(new OperatorMethodHandle(DISTINCT_FROM_CONVENTION, DISTINCT_FROM.bindTo(distinctFromOperators)));
}
// (Block, Block):boolean
MethodHandle distinctFrom = dropArguments(constant(boolean.class, false), 0, Block.class, Block.class);
for (int fieldId = 0; fieldId < fields.size(); fieldId++) {
Field field = fields.get(fieldId);
// (Block, Block, int, MethodHandle, Block, Block):boolean
distinctFrom = collectArguments(CHAIN_DISTINCT_FROM, 0, distinctFrom);
// field distinctFrom
MethodHandle fieldDistinctFromOperator = typeOperators.getDistinctFromOperator(field.getType(), simpleConvention(FAIL_ON_NULL, BLOCK_POSITION, BLOCK_POSITION));
// (Block, Block, Block, Block):boolean
distinctFrom = insertArguments(distinctFrom, 2, fieldId, fieldDistinctFromOperator);
// (Block, Block):boolean
distinctFrom = permuteArguments(distinctFrom, methodType(boolean.class, Block.class, Block.class), 0, 1, 0, 1);
}
distinctFrom = CHAIN_DISTINCT_FROM_START.bindTo(distinctFrom);
return singletonList(new OperatorMethodHandle(DISTINCT_FROM_CONVENTION, distinctFrom));
}
use of io.trino.spi.function.OperatorMethodHandle in project trino by trinodb.
the class RowType method getComparisonOperatorInvokers.
private static List<OperatorMethodHandle> getComparisonOperatorInvokers(BiFunction<Type, InvocationConvention, MethodHandle> comparisonOperatorFactory, List<Field> fields) {
boolean orderable = fields.stream().allMatch(field -> field.getType().isOrderable());
if (!orderable) {
return emptyList();
}
// for large rows, use a generic loop with a megamorphic call site
if (fields.size() > MEGAMORPHIC_FIELD_COUNT) {
List<MethodHandle> comparisonOperators = fields.stream().map(field -> comparisonOperatorFactory.apply(field.getType(), simpleConvention(FAIL_ON_NULL, BLOCK_POSITION, BLOCK_POSITION))).collect(toUnmodifiableList());
return singletonList(new OperatorMethodHandle(COMPARISON_CONVENTION, COMPARISON.bindTo(comparisonOperators)));
}
// (Block, Block):Boolean
MethodHandle comparison = dropArguments(constant(long.class, 0), 0, Block.class, Block.class);
for (int fieldId = 0; fieldId < fields.size(); fieldId++) {
Field field = fields.get(fieldId);
// (Block, Block, int, MethodHandle, Block, Block):Boolean
comparison = collectArguments(CHAIN_COMPARISON, 0, comparison);
// field comparison
MethodHandle fieldComparisonOperator = comparisonOperatorFactory.apply(field.getType(), simpleConvention(FAIL_ON_NULL, BLOCK_POSITION, BLOCK_POSITION));
// (Block, Block, Block, Block):Boolean
comparison = insertArguments(comparison, 2, fieldId, fieldComparisonOperator);
// (Block, Block):Boolean
comparison = permuteArguments(comparison, methodType(long.class, Block.class, Block.class), 0, 1, 0, 1);
}
return singletonList(new OperatorMethodHandle(COMPARISON_CONVENTION, comparison));
}
use of io.trino.spi.function.OperatorMethodHandle in project trino by trinodb.
the class RowType method getHashCodeOperatorMethodHandles.
private static List<OperatorMethodHandle> getHashCodeOperatorMethodHandles(List<Field> fields, Function<Type, MethodHandle> getHashOperator) {
boolean comparable = fields.stream().allMatch(field -> field.getType().isComparable());
if (!comparable) {
return emptyList();
}
// for large rows, use a generic loop with a megamorphic call site
if (fields.size() > MEGAMORPHIC_FIELD_COUNT) {
List<MethodHandle> hashCodeOperators = fields.stream().map(field -> getHashOperator.apply(field.getType())).collect(toUnmodifiableList());
return singletonList(new OperatorMethodHandle(HASH_CODE_CONVENTION, HASH_CODE.bindTo(hashCodeOperators)));
}
// (Block):long
MethodHandle hashCode = dropArguments(constant(long.class, 1), 0, Block.class);
for (int fieldId = 0; fieldId < fields.size(); fieldId++) {
Field field = fields.get(fieldId);
// (Block, int, MethodHandle, Block):long
hashCode = collectArguments(CHAIN_HASH_CODE, 0, hashCode);
// field hash code
MethodHandle fieldHashCodeOperator = getHashOperator.apply(field.getType());
// (Block, Block):long
hashCode = insertArguments(hashCode, 1, fieldId, fieldHashCodeOperator);
// (Block):long
hashCode = permuteArguments(hashCode, methodType(long.class, Block.class), 0, 0);
}
return singletonList(new OperatorMethodHandle(HASH_CODE_CONVENTION, hashCode));
}
use of io.trino.spi.function.OperatorMethodHandle in project trino by trinodb.
the class RowType method getEqualOperatorMethodHandles.
private static List<OperatorMethodHandle> getEqualOperatorMethodHandles(TypeOperators typeOperators, List<Field> fields) {
boolean comparable = fields.stream().allMatch(field -> field.getType().isComparable());
if (!comparable) {
return emptyList();
}
// for large rows, use a generic loop with a megamorphic call site
if (fields.size() > MEGAMORPHIC_FIELD_COUNT) {
List<MethodHandle> equalOperators = fields.stream().map(field -> typeOperators.getEqualOperator(field.getType(), simpleConvention(NULLABLE_RETURN, BLOCK_POSITION, BLOCK_POSITION))).collect(toUnmodifiableList());
return singletonList(new OperatorMethodHandle(EQUAL_CONVENTION, EQUAL.bindTo(equalOperators)));
}
// (Block, Block):Boolean
MethodHandle equal = dropArguments(constant(Boolean.class, TRUE), 0, Block.class, Block.class);
for (int fieldId = 0; fieldId < fields.size(); fieldId++) {
Field field = fields.get(fieldId);
// (Block, Block, int, MethodHandle, Block, Block):Boolean
equal = collectArguments(CHAIN_EQUAL, 0, equal);
// field equal
MethodHandle fieldEqualOperator = typeOperators.getEqualOperator(field.getType(), simpleConvention(NULLABLE_RETURN, BLOCK_POSITION, BLOCK_POSITION));
// (Block, Block, Block, Block):Boolean
equal = insertArguments(equal, 2, fieldId, fieldEqualOperator);
// (Block, Block):Boolean
equal = permuteArguments(equal, methodType(Boolean.class, Block.class, Block.class), 0, 1, 0, 1);
}
return singletonList(new OperatorMethodHandle(EQUAL_CONVENTION, equal));
}
use of io.trino.spi.function.OperatorMethodHandle in project trino by trinodb.
the class RowType method getIndeterminateOperatorInvokers.
private static List<OperatorMethodHandle> getIndeterminateOperatorInvokers(TypeOperators typeOperators, List<Field> fields) {
boolean comparable = fields.stream().allMatch(field -> field.getType().isComparable());
if (!comparable) {
return emptyList();
}
// for large rows, use a generic loop with a megamorphic call site
if (fields.size() > MEGAMORPHIC_FIELD_COUNT) {
List<MethodHandle> indeterminateOperators = fields.stream().map(field -> typeOperators.getIndeterminateOperator(field.getType(), simpleConvention(FAIL_ON_NULL, BLOCK_POSITION))).collect(toUnmodifiableList());
return singletonList(new OperatorMethodHandle(INDETERMINATE_CONVENTION, INDETERMINATE.bindTo(indeterminateOperators)));
}
// (Block):long
MethodHandle indeterminate = dropArguments(constant(boolean.class, false), 0, Block.class);
for (int fieldId = 0; fieldId < fields.size(); fieldId++) {
Field field = fields.get(fieldId);
// (Block, int, MethodHandle, Block):boolean
indeterminate = collectArguments(CHAIN_INDETERMINATE, 0, indeterminate);
// field indeterminate
MethodHandle fieldIndeterminateOperator = typeOperators.getIndeterminateOperator(field.getType(), simpleConvention(FAIL_ON_NULL, BLOCK_POSITION));
// (Block, Block):boolean
indeterminate = insertArguments(indeterminate, 1, fieldId, fieldIndeterminateOperator);
// (Block):boolean
indeterminate = permuteArguments(indeterminate, methodType(boolean.class, Block.class), 0, 0);
}
return singletonList(new OperatorMethodHandle(INDETERMINATE_CONVENTION, indeterminate));
}
Aggregations