Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions python/datafusion/tests/test_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ def df():
return ctx.create_dataframe([[batch]])


def test_named_struct(df):
df = df.with_column(
"d",
f.named_struct(
literal("a"),
column("a"),
literal("b"),
column("b"),
literal("c"),
column("c"),
),
)

expected = """DataFrame()
+-------+---+---------+------------------------------+
| a | b | c | d |
+-------+---+---------+------------------------------+
| Hello | 4 | hello | {a: Hello, b: 4, c: hello } |
| World | 5 | world | {a: World, b: 5, c: world } |
| ! | 6 | ! | {a: !, b: 6, c: !} |
+-------+---+---------+------------------------------+
""".strip()

assert str(df) == expected


def test_literal(df):
df = df.select(
literal(1),
Expand Down
2 changes: 2 additions & 0 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ expr_fn_vec!(trunc);
expr_fn!(upper, arg1, "Converts the string to all upper case.");
expr_fn!(uuid);
expr_fn_vec!(r#struct); // Use raw identifier since struct is a keyword
expr_fn_vec!(named_struct);
expr_fn!(from_unixtime, unixtime);
expr_fn!(arrow_typeof, arg_1);
expr_fn!(random);
Expand Down Expand Up @@ -678,6 +679,7 @@ pub(crate) fn init_module(m: &PyModule) -> PyResult<()> {
m.add_wrapped(wrap_pyfunction!(mean))?;
m.add_wrapped(wrap_pyfunction!(median))?;
m.add_wrapped(wrap_pyfunction!(min))?;
m.add_wrapped(wrap_pyfunction!(named_struct))?;
m.add_wrapped(wrap_pyfunction!(nanvl))?;
m.add_wrapped(wrap_pyfunction!(now))?;
m.add_wrapped(wrap_pyfunction!(nullif))?;
Expand Down