Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add xxhash64 support for nested types #2575

Open
wants to merge 6 commits into
base: branch-25.02
Choose a base branch
from

Conversation

ustcfy
Copy link
Collaborator

@ustcfy ustcfy commented Nov 6, 2024

Contribute to #2574

This PR adds support for xxhash64 with struct , list and map types.

The hardcoded expected values in the tests are generated using Spark.
For example, you can produce the same results as in testXXHash64ListOfStruct using the following code.

import org.apache.spark.sql.functions._
import org.apache.spark.sql.types._
import org.apache.spark.sql.Row

val schema = StructType(Seq(
    StructField("listofstruct",
        ArrayType(
            StructType(Seq(
                StructField("string", StringType, true),
                StructField("int", IntegerType, true),
                StructField("double", DoubleType, true),
                StructField("float", FloatType, true),
                StructField("bool", BooleanType, true)
            )),
            true
        )
    )
))

val data = Seq(
    Row(List()),
    Row(List(Row("a", 0, 0.0, 0f, true))),
    Row(List(Row("B\n", 100, 100.0, 100f, false), Row("dE\"\u0100\t\u0101 \ud720\ud721", -100, -100.0, -100f, null))),
    Row(List(Row("A very long (greater than 128 bytes/char string) to test a multi hash-step data point " +
        "in the MD5 hash function. This string needed to be longer.", Int.MinValue, java.lang.Double.longBitsToDouble(0x7ff0000000000001L), java.lang.Float.intBitsToFloat(0xff800001), false))),
    Row(List(Row(null, Int.MaxValue, java.lang.Double.longBitsToDouble(0x7fffffffffffffffL), java.lang.Float.intBitsToFloat(0xffffffff), true), Row(null, null, null, null, null))),
    Row(null)
)

val df = spark.createDataFrame(spark.sparkContext.parallelize(data), schema)
df.columns.foreach(c => println(s"$c => ${df.select(xxhash64(col(c))).collect.mkString(",")}"))

You will get the following output:

listofstruct => [42],[7451748878409563026],[948372773124634350],[8444697026100086329],[-5888679192448042852],[42]

@ustcfy ustcfy self-assigned this Nov 6, 2024
@ustcfy ustcfy changed the title Add xxhash64 support for nested types Add xxhash64 support for nested types Nov 6, 2024
Signed-off-by: ustcfy <[email protected]>
Signed-off-by: ustcfy <[email protected]>
@res-life
Copy link
Collaborator

res-life commented Nov 6, 2024

Please add more cases, LGTM for the function.

ustcfy and others added 2 commits November 6, 2024 15:50
@res-life
Copy link
Collaborator

res-life commented Nov 6, 2024

LGTM

@res-life
Copy link
Collaborator

res-life commented Nov 6, 2024

build

res-life
res-life previously approved these changes Nov 6, 2024
Copy link
Collaborator

@revans2 revans2 left a comment

Choose a reason for hiding this comment

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

looks good, but I am no expert on the CUDA side of things.

cudf::size_type row_index) const noexcept
{
if (_check_nulls && col.is_null(row_index)) { return _seed; }
return XXHash_64<T>{_seed}(col.element<T>(row_index));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we have a follow on issue to make the hash function a template? We have the same issues with all hash functions we want to support, so having generic code would be nice.

Copy link
Collaborator

@firestarman firestarman left a comment

Choose a reason for hiding this comment

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

Look good to me, but a nit.

src/main/cpp/src/xxhash64.cu Show resolved Hide resolved
Copy link
Collaborator

@ttnghia ttnghia left a comment

Choose a reason for hiding this comment

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

Sorry, this PR has similar implementation with the HiveHash one, so both need to address the issue with shallow stack size unless we want to target this for 24.12.

@ustcfy ustcfy changed the base branch from branch-24.12 to branch-25.02 November 25, 2024 09:55
@ustcfy ustcfy dismissed res-life’s stale review November 25, 2024 09:55

The base branch was changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants