Am I misusing daft by trying to process full rows ...
# daft-dev
p
Am I misusing daft by trying to process full rows and return different rows? I’m used to the spark workflow where I can pass a row into a UDF and yield a different Row object. Actual use case is to convert an arrow record batch to a list of protobuf (using the ‘protarrow’ package) and return a different protobuf after computing, finally reversing the process to get back to a new record batch. I have this working with the native runner using iter_partitions and iter_batches but I don’t believe I can take advantage of the ray cluster this way. Appreciate any advice!
👍 1
c
So unlike spark, daft is not natively row based, it is a columnar engine, so to get the best experience there is a subtle shift to thinking columns first instead of rows first. We do however support this by creating a column containing all of the columns
Copy code
import daft
from daft import DataType as dt

df = daft.from_pydict({
    "a": [1,2,3],
    "b": [True, False, False]
})


@daft.func(return_dtype = dt.struct({
    "c": dt.string(),
    "d": dt.list(dt.string())
}))
def process_row(data):
    c = f"hello: {data['a']}"
    d = [str(data['b'])]
    return {
        "c": c,
        "d": d
    }

df.select(process_row(daft.struct(*df.column_names)).unnest()).show()
if you're able to provide some code, I could likely help provide a more detailed example on the "daft" way of doing it!