-
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.
[FEAT] connect:
createDataFrame
(WIP) help needed
- Loading branch information
1 parent
a2e0beb
commit ffc5efc
Showing
4 changed files
with
54 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
10 changes: 10 additions & 0 deletions
10
src/daft-connect/src/translation/logical_plan/local_relation.rs
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,10 @@ | ||
use daft_logical_plan::LogicalPlanBuilder; | ||
|
||
pub fn local_relation( | ||
local_relation: spark_connect::LocalRelation, | ||
) -> eyre::Result<LogicalPlanBuilder> { | ||
let spark_connect::LocalRelation { | ||
data, | ||
schema, | ||
} = local_relation; | ||
} |
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,26 @@ | ||
use eyre::{bail, WrapErr}; | ||
use daft_logical_plan::LogicalPlanBuilder; | ||
use crate::translation::to_logical_plan; | ||
|
||
pub fn to_df(to_df: spark_connect::ToDf) -> eyre::Result<LogicalPlanBuilder> { | ||
let spark_connect::ToDf { | ||
input, | ||
column_names, | ||
} = to_df; | ||
|
||
let Some(input) = input else { | ||
bail!("Input is required") | ||
}; | ||
|
||
let plan = to_logical_plan(*input) | ||
.wrap_err_with(|| format!("Failed to translate relation to logical plan: {input:?}"))?; | ||
|
||
let column_names: Vec<_> = column_names | ||
.iter() | ||
.map(|name| daft_dsl::col(name)) | ||
.collect(); | ||
|
||
let plan = plan.with_columns(column_names)? | ||
|
||
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,13 @@ | ||
from __future__ import annotations | ||
|
||
|
||
def test_create_df(spark_session): | ||
# Create a DataFrame with duplicate values | ||
data = [(1,), (2,), (2,), (3,), (3,), (3,)] | ||
df = spark_session.createDataFrame(data, ["value"]) | ||
|
||
# Collect and verify results | ||
result = df.collect() | ||
|
||
# Verify the DataFrame has the expected number of rows and values | ||
assert sorted([row.value for row in result]) == [1, 2, 2, 3, 3, 3] |