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

Nulls order ignored when query is pushed down to Snowflake #534

Open
Messlow opened this issue Nov 29, 2023 · 0 comments
Open

Nulls order ignored when query is pushed down to Snowflake #534

Messlow opened this issue Nov 29, 2023 · 0 comments

Comments

@Messlow
Copy link

Messlow commented Nov 29, 2023

The spark connector ignores the NULLS FIRST or NULLS LAST part of the order by clause when the query is pushed down to Snowflake. Also, for Snowflake NULL values are considered to be higher than any non-NULL values, which is the opposite as spark. This makes null ordering non-coherent between both.
Here is a reproducible example, on Databricks with DBR 12,2:

spark.createDataFrame(
    [(None, None), (1.0, 2.0), (2.0, 1.0), (None, None)], schema=["col1", "col2"]
).write.format("snowflake").options(**snowflake_options).mode("overwrite").option(
    "dbtable", "TEST_NULLS"
).save()

data = (
    spark.read.format("snowflake")
    .options(**snowflake_options)
    .option("dbtable", "TEST_NULLS")
    .load()
)

data.sort(F.col("col1").desc_nulls_last()).show()

Expected output:

+----+----+
|COL1|COL2|
+----+----+
|   2|   1|
|   1|   2|
|null|null|
|null|null|
+----+----+

Observed output:

+----+----+
|COL1|COL2|
+----+----+
|null|null|
|null|null|
|   2|   1|
|   1|   2|
+----+----+
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

No branches or pull requests

1 participant