In-memory operations on query results.
A %Results{} struct contains a dataframe returned from Query.execute/1.
All functions in this module operate on data that has already been fetched.
Filtering
Stage 1: Prefer Query.where/2 for initial filtering** - it's more efficient.
Stage 2: Use Results.filter/2 to apply additional filters on already-fetched data.
This module handles stage 2.
Summary
Functions
Aggregate results by grouping on a column and counting occurrences.
Return the number of rows in the results.
Check if results are empty.
Apply additional predicate filters to already-fetched results.
Return the first row as a map, or nil if empty.
Join two result sets on a common column.
Sum a numeric column, returning 0 if the column doesn't exist.
Apply text search to results using case-insensitive substring matching.
Convert results to a list of maps (rows).
Types
@type join_how() :: :inner | :left | :right | :outer | :cross
@type join_opts() :: [join_opt()]
@type t() :: %DeltaQuery.Results{ dataframe: Explorer.DataFrame.t(), files_processed: non_neg_integer(), total_files: non_neg_integer() }
Functions
Aggregate results by grouping on a column and counting occurrences.
Returns a list of maps with the column value and count, sorted by count descending.
Examples
aggregated = Results.aggregate_by_column(results, :book_id)
# => [%{book_id: 1001, count: 5}, %{book_id: 1002, count: 3}]
@spec count(t()) :: non_neg_integer()
Return the number of rows in the results.
Examples
results |> Results.count()
# => 42
Check if results are empty.
Examples
results |> Results.empty?()
# => false
Apply additional predicate filters to already-fetched results.
Prefer Query.where/2 for initial filtering. This function applies filters in-memory
on data that has already been downloaded. Use it only for:
- Filtering joined results from multiple queries
- Applying filters determined after initial query execution
Returns {:ok, results} on success or {:error, reason} if any predicate is invalid.
Examples
# Filter joined results
{:ok, books} = Query.new("books") |> Query.execute()
{:ok, publishers} = Query.new("publishers") |> Query.execute()
joined = Results.join(books, publishers, on: "book_id")
{:ok, filtered} = Results.filter(joined, ["page_count > 300"])
Return the first row as a map, or nil if empty.
Examples
results |> Results.first()
# => %{"book_id" => 1001, "title" => "The Great Gatsby"}
Join two result sets on a common column.
Options
:on- Column name or list of column names to join on (required):how- Join type::left(default),:right,:inner,:outer,:cross
Examples
"books"
|> Query.new()
|> Query.execute!()
|> Results.join(publishers_result, on: "book_id")
|> Results.to_rows()
Sum a numeric column, returning 0 if the column doesn't exist.
Examples
results |> Results.sum("amount")
# => 12500.0
Apply text search to results using case-insensitive substring matching.
Searches across the specified columns and returns rows where any column contains the search text.
Examples
{:ok, searched} = Results.text_search(results, "fiction", ["genre", "title", "notes"])
Convert results to a list of maps (rows).
Examples
"books"
|> Query.new()
|> Query.execute!()
|> Results.to_rows()