-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7f60fd
commit 5935376
Showing
3 changed files
with
49 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use eyre::bail; | ||
|
||
use crate::translation::{to_daft_expr, to_logical_plan}; | ||
|
||
pub fn filter( | ||
filter: spark_connect::Filter, | ||
) -> eyre::Result<daft_logical_plan::LogicalPlanBuilder> { | ||
let spark_connect::Filter { input, condition } = filter; | ||
|
||
let Some(input) = input else { | ||
bail!("input is required"); | ||
}; | ||
|
||
let Some(condition) = condition else { | ||
bail!("condition is required"); | ||
}; | ||
|
||
let condition = to_daft_expr(&condition)?; | ||
|
||
let plan = to_logical_plan(*input)?; | ||
|
||
let plan = plan.filter(condition)?; | ||
|
||
Ok(plan) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from __future__ import annotations | ||
|
||
from pyspark.sql.functions import col | ||
|
||
|
||
def test_filter(spark_session): | ||
# Create DataFrame from range(10) | ||
df = spark_session.range(10) | ||
|
||
# Filter for values less than 5 | ||
df_filtered = df.filter(col("id") < 5) | ||
|
||
# Verify the schema is unchanged after filter | ||
assert df_filtered.schema == df.schema, "Schema should be unchanged after filter" | ||
|
||
# Verify the filtered data is correct | ||
df_filtered_pandas = df_filtered.toPandas() | ||
assert len(df_filtered_pandas) == 5, "Should have 5 rows after filtering < 5" | ||
assert all(df_filtered_pandas["id"] < 5), "All values should be less than 5" |