Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,24 @@ private static void project(int position, PageBuilder pageBuilder, Block extende

private static boolean filter(int position, Block discountBlock, Block shipDateBlock, Block quantityBlock)
{
return !shipDateBlock.isNull(position) && VARCHAR.getSlice(shipDateBlock, position).compareTo(MIN_SHIP_DATE) >= 0 &&
!shipDateBlock.isNull(position) && VARCHAR.getSlice(shipDateBlock, position).compareTo(MAX_SHIP_DATE) < 0 &&
return !shipDateBlock.isNull(position) && greaterThanOrEqual(shipDateBlock, position, MIN_SHIP_DATE) &&
!shipDateBlock.isNull(position) && lessThan(shipDateBlock, position, MAX_SHIP_DATE) &&
!discountBlock.isNull(position) && DOUBLE.getDouble(discountBlock, position) >= 0.05 &&
!discountBlock.isNull(position) && DOUBLE.getDouble(discountBlock, position) <= 0.07 &&
!quantityBlock.isNull(position) && DOUBLE.getDouble(quantityBlock, position) < 24;
}

private static boolean lessThan(Block left, int leftPosition, Slice right)
{
int leftLength = left.getSliceLength(leftPosition);
return left.bytesCompare(leftPosition, 0, leftLength, right, 0, right.length()) < 0;
}

private static boolean greaterThanOrEqual(Block left, int leftPosition, Slice right)
{
int leftLength = left.getSliceLength(leftPosition);
return left.bytesCompare(leftPosition, 0, leftLength, right, 0, right.length()) >= 0;
}
}

// where shipdate >= '1994-01-01'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,12 @@ private OperatorMethodHandle generateLessThanOperator(OperatorConvention operato
if (operatorConvention.callingConvention().getArgumentConventions().equals(List.of(BLOCK_POSITION, BLOCK_POSITION))) {
comparisonCallingConvention = simpleConvention(FAIL_ON_NULL, BLOCK_POSITION, BLOCK_POSITION);
}
else if (operatorConvention.callingConvention().getArgumentConventions().equals(List.of(NEVER_NULL, BLOCK_POSITION))) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if type does not implement that convention?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code below passes tis convention to adaptOperator, which will look for the exact a function with that exact convention, and if not found it will ask for the (NEVER_NULL, NEVER_NULL ) version and adapt that to (NEVER_NULL, BLOCK_POSITION) using the scalar function adapter

comparisonCallingConvention = simpleConvention(FAIL_ON_NULL, NEVER_NULL, BLOCK_POSITION);
}
else if (operatorConvention.callingConvention().getArgumentConventions().equals(List.of(BLOCK_POSITION, NEVER_NULL))) {
comparisonCallingConvention = simpleConvention(FAIL_ON_NULL, BLOCK_POSITION, NEVER_NULL);
}
else {
comparisonCallingConvention = simpleConvention(FAIL_ON_NULL, NEVER_NULL, NEVER_NULL);
}
Expand Down
14 changes: 14 additions & 0 deletions core/trino-spi/src/main/java/io/trino/spi/type/VarcharType.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,18 @@ private static long comparisonOperator(@BlockPosition Block leftBlock, @BlockInd
int rightLength = rightBlock.getSliceLength(rightPosition);
return leftBlock.compareTo(leftPosition, 0, leftLength, rightBlock, rightPosition, 0, rightLength);
}

@ScalarOperator(COMPARISON_UNORDERED_LAST)
private static long comparisonOperator(@BlockPosition Block leftBlock, @BlockIndex int leftPosition, Slice right)
{
int leftLength = leftBlock.getSliceLength(leftPosition);
return leftBlock.bytesCompare(leftPosition, 0, leftLength, right, 0, right.length());
}

@ScalarOperator(COMPARISON_UNORDERED_LAST)
private static long comparisonOperator(Slice left, @BlockPosition Block rightBlock, @BlockIndex int rightPosition)
{
int rightLength = rightBlock.getSliceLength(rightPosition);
return -rightBlock.bytesCompare(rightPosition, 0, rightLength, left, 0, left.length());
}
}