Are there examples of using juliac and trimming for processing CSV files? I.e. is there a trimmable CSV parser? I’m curious about the difficulty of reading in tables that might have different numbers of columns but should be basically all numeric data barring an ID column and the headers.
Hey, sorry for the slow response, but this has been a goal of mine for a while with CSV.jl. We recently got the 1.0 release out and as a follow-up, I wanted to get trimming working as well. Here’s an AI description/summary of how it works in the new 1.3 release:
Following up here: CSV.jl 1.3.0 adds trimmable reads through CSV.Rows and CSV.File when you provide the column names and types ahead of time.
For example, with CSV and Tables installed in your project, this sums two numeric columns alongside a string ID:
# reader.jl — input header: id,x,y
using CSV, Tables
const SCHEMA = Tables.Schema((:id, :x, :y), (String, Float64, Float64))
function (@main)(args::Vector{String})::Cint
total = 0.0
for row in CSV.Rows(args[1]; schema=SCHEMA)
total += row.x + row.y
end
Core.println(string(total))
return 0
end
Compile and run with Julia 1.13 and juliac:
juliac --project=. --experimental --trim=safe --output-exe reader reader.jl
./reader data.csv
The reader validates the header, row widths, and values against the schema.
For different column counts, you can include several constant schemas and choose between them at runtime. The current requirement is that those layouts are known when compiling; arbitrary layouts discovered only at runtime aren’t supported by this trimmed path yet. There are more examples and details here.