Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
marin-ma committed May 1, 2024
1 parent 6fd9505 commit 7c53bba
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 34 deletions.
5 changes: 0 additions & 5 deletions velox/docs/functions/spark/binary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ Binary Functions
Computes the hash of one or more input values using seed value of 42. For
multiple arguments, their types can be different.
Supported types are: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, VARCHAR,
VARBINARY, REAL, DOUBLE, HUGEINT, TIMESTAMP, ARRAY, MAP and ROW.


.. spark:function:: hash_with_seed(seed, x, ...) -> integer
Computes the hash of one or more input values using specified seed. For
multiple arguments, their types can be different.
Supported types are: BOOLEAN, TINYINT, SMALLINT, INTEGER, BIGINT, VARCHAR,
VARBINARY, REAL, DOUBLE, HUGEINT, TIMESTAMP, ARRAY, MAP and ROW.

.. spark:function:: xxhash64(x, ...) -> bigint
Expand Down
25 changes: 9 additions & 16 deletions velox/functions/sparksql/tests/HashTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ TEST_F(HashTest, Float) {
EXPECT_EQ(hash<float>(-limits::infinity()), 427440766);
}

TEST_F(HashTest, Array) {
TEST_F(HashTest, array) {
assertEqualVectors(
makeFlatVector<int32_t>({2101165938, 42, 1045631400}),
hash(makeArrayVector<int64_t>({{1, 2, 3, 4, 5}, {}, {1, 2, 3}})));
Expand All @@ -146,19 +146,12 @@ TEST_F(HashTest, Array) {

// Nested array.
{
using innerArrayType = std::vector<std::optional<int64_t>>;
using outerArrayType =
std::vector<std::optional<std::vector<std::optional<int64_t>>>>;

innerArrayType a{1, std::nullopt, 2, 3};
innerArrayType b{4, 5};
innerArrayType c{6, 7, 8};
outerArrayType row1{{a}, {b}};
outerArrayType row2{{a}, {c}};
outerArrayType row3{{{}}};
outerArrayType row4{{{std::nullopt}}};
auto arrayVector = makeNullableNestedArrayVector<int64_t>(
{{row1}, {row2}, {row3}, {row4}, std::nullopt});
auto arrayVector = makeNestedArrayVectorFromJson<int64_t>(
{"[[1, null, 2, 3], [4, 5]]",
"[[1, null, 2, 3], [6, 7, 8]]",
"[[]]",
"[[null]]",
"[null]"});
assertEqualVectors(
makeFlatVector<int32_t>({2101165938, -992561130, 42, 42, 42}),
hash(arrayVector));
Expand Down Expand Up @@ -192,7 +185,7 @@ TEST_F(HashTest, Array) {
}
}

TEST_F(HashTest, Map) {
TEST_F(HashTest, map) {
auto mapVector = makeMapVector<int64_t, double>(
{{{1, 17.0}, {2, 36.0}, {3, 8.0}, {4, 28.0}, {5, 24.0}, {6, 32.0}}});
assertEqualVectors(
Expand All @@ -212,7 +205,7 @@ TEST_F(HashTest, Map) {
hash(mapWithNullArrays));
}

TEST_F(HashTest, Row) {
TEST_F(HashTest, row) {
auto row = makeRowVector({
makeFlatVector<int64_t>({1, 3}),
makeFlatVector<int64_t>({2, 4}),
Expand Down
19 changes: 6 additions & 13 deletions velox/functions/sparksql/tests/XxHash64Test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,12 @@ TEST_F(XxHash64Test, array) {

// Nested array.
{
using innerArrayType = std::vector<std::optional<int64_t>>;
using outerArrayType =
std::vector<std::optional<std::vector<std::optional<int64_t>>>>;

innerArrayType a{1, std::nullopt, 2, 3};
innerArrayType b{4, 5};
innerArrayType c{6, 7, 8};
outerArrayType row1{{a}, {b}};
outerArrayType row2{{a}, {c}};
outerArrayType row3{{{}}};
outerArrayType row4{{{std::nullopt}}};
auto arrayVector = makeNullableNestedArrayVector<int64_t>(
{{row1}, {row2}, {row3}, {row4}, std::nullopt});
auto arrayVector = makeNestedArrayVectorFromJson<int64_t>(
{"[[1, null, 2, 3], [4, 5]]",
"[[1, null, 2, 3], [6, 7, 8]]",
"[[]]",
"[[null]]",
"[null]"});
assertEqualVectors(
makeFlatVector<int64_t>(
{-6041664978295882827, -1052942565807509112, 42, 42, 42}),
Expand Down

0 comments on commit 7c53bba

Please sign in to comment.