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 @@ -31,6 +31,7 @@
import static com.facebook.presto.spi.function.OperatorType.LESS_THAN;
import static com.facebook.presto.spi.function.OperatorType.LESS_THAN_OR_EQUAL;
import static com.facebook.presto.spi.function.OperatorType.NOT_EQUAL;
import static com.facebook.presto.spi.function.OperatorType.XX_HASH_64;
import static com.facebook.presto.spi.type.Chars.compareChars;

public final class CharOperators
Expand Down Expand Up @@ -101,6 +102,14 @@ public static long hashCode(@SqlType("char(x)") Slice value)
return XxHash64.hash(value);
}

@LiteralParameters("x")
@ScalarOperator(XX_HASH_64)
@SqlType(StandardTypes.BIGINT)
public static long xxHash64(@SqlType("char(x)") Slice slice)
{
return XxHash64.hash(slice);
}

@LiteralParameters({"x"})
@ScalarOperator(IS_DISTINCT_FROM)
@SqlType(StandardTypes.BOOLEAN)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,10 @@ public void testApproximateCountDistinct()
assertQuery("SELECT approx_distinct(CAST(custkey AS VARCHAR)) FROM orders", "SELECT 1036");
assertQuery("SELECT approx_distinct(CAST(custkey AS VARCHAR), 0.023) FROM orders", "SELECT 1036");

// test char
assertQuery("SELECT approx_distinct(CAST(CAST(custkey AS VARCHAR) AS CHAR(20))) FROM orders", "SELECT 1036");
Copy link
Contributor

Choose a reason for hiding this comment

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

i guess CAST(custkey AS CHAR(20)) is not enough?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, there is no direct cast operator

assertQuery("SELECT approx_distinct(CAST(CAST(custkey AS VARCHAR) AS CHAR(20)), 0.023) FROM orders", "SELECT 1036");

// test varbinary
assertQuery("SELECT approx_distinct(to_utf8(CAST(custkey AS VARCHAR))) FROM orders", "SELECT 1036");
assertQuery("SELECT approx_distinct(to_utf8(CAST(custkey AS VARCHAR)), 0.023) FROM orders", "SELECT 1036");
Expand Down