Is your feature request related to a problem?
Daft supports the Map datatype and provides map_get for accessing map values, but there is no way to manually construct a map column from expressions. We already have to_list and to_struct constructor functions that allow users to build list and struct columns from expressions, but the equivalent to_map is missing.
This means users who want to create map columns must either:
- Read them from an external source (e.g. Parquet, Iceberg)
- Use workarounds with structs/lists and casts
Describe the solution you'd like
Add a to_map function (exposed via daft.functions.to_map) that constructs a map column from key-value expression pairs.
Proposed API:
from daft.functions import to_map
df = daft.from_pydict({"k1": ["a", "b"], "v1": [1, 2], "k2": ["c", "d"], "v2": [3, 4]})
# Option A: alternating key/value expressions
df.select(to_map(df["k1"], df["v1"], df["k2"], df["v2"]).alias("my_map"))
# Option B: keyword-style (keys as strings, values as expressions)
df.select(to_map(a=df["v1"], b=df["v2"]).alias("my_map"))
This should follow the same patterns established by to_list (daft/functions/list.py) and to_struct (daft/functions/struct.py).
Describe alternatives you've considered
- Constructing a list of structs and casting to map — verbose and error-prone
- Using
from_pydict with pre-built Python dicts — doesn't work for expression-level construction within a query plan
Component(s)
Built-in Functions
Additional Context
- Existing map support:
MapType dtype, map_get accessor
- Reference implementations:
to_list in daft/functions/list.py, to_struct in daft/functions/struct.py
Would you like to implement a fix?
Yes
Is your feature request related to a problem?
Daft supports the
Mapdatatype and providesmap_getfor accessing map values, but there is no way to manually construct a map column from expressions. We already haveto_listandto_structconstructor functions that allow users to build list and struct columns from expressions, but the equivalentto_mapis missing.This means users who want to create map columns must either:
Describe the solution you'd like
Add a
to_mapfunction (exposed viadaft.functions.to_map) that constructs a map column from key-value expression pairs.Proposed API:
This should follow the same patterns established by
to_list(daft/functions/list.py) andto_struct(daft/functions/struct.py).Describe alternatives you've considered
from_pydictwith pre-built Python dicts — doesn't work for expression-level construction within a query planComponent(s)
Built-in Functions
Additional Context
MapTypedtype,map_getaccessorto_listindaft/functions/list.py,to_structindaft/functions/struct.pyWould you like to implement a fix?
Yes