| Crates.io | dsq-core |
| lib.rs | dsq-core |
| version | 0.1.0 |
| created_at | 2025-12-15 18:01:23.01218+00 |
| updated_at | 2025-12-15 18:01:23.01218+00 |
| description | Core functionality for dsq - data processing with jq syntax |
| homepage | |
| repository | https://github.com/durableprogramming/dsq |
| max_upload_size | |
| id | 1986461 |
| size | 607,559 |
Core library for dsq data processing.
dsq-core provides the fundamental data processing capabilities for dsq, extending jq-compatible syntax to work with structured data formats like Parquet, Avro, CSV, and more. It leverages Polars DataFrames for high-performance data manipulation.
The core Value enum bridges between JSON-like values and Polars DataFrames:
use dsq_core::value::Value;
// JSON-like values
let json_val = Value::object([
("name".to_string(), Value::string("Alice")),
("age".to_string(), Value::int(30)),
].into());
// DataFrame values
let df_val = Value::dataframe(dataframe);
Comprehensive data operations library:
use dsq_core::ops::{Operation, basic::*};
// Select columns
let selected = select_columns(&data, &["name", "age"])?;
// Sort data
let sorted = sort_by_columns(&selected, &[SortOptions::desc("age")])?;
// Take first N rows
let result = head(&sorted, 10)?;
Input/output for multiple file formats:
use dsq_core::io;
// Read CSV file
let data = io::read_file("data.csv", &io::ReadOptions::default())?;
// Write to Parquet
io::write_file(&result, "output.parquet", &io::WriteOptions::default())?;
jq-compatible filter compilation and execution:
use dsq_core::filter::{FilterExecutor, ExecutorConfig};
// Execute jq-style filter
let mut executor = FilterExecutor::with_config(ExecutorConfig::default());
let result = executor.execute_str("map(select(.age > 30)) | sort_by(.name)", data)?;
Add this to your Cargo.toml:
[dependencies]
dsq-core = "0.1"
Or for the latest development version:
[dependencies]
dsq-core = { git = "https://github.com/durableprogramming/dsq", branch = "main" }
Full API documentation is available at docs.rs/dsq-core.
use dsq_core::{Value, ops, io};
// Read data from a file
let data = io::read_file("data.csv", &io::ReadOptions::default())?;
// Apply operations
let result = ops::OperationPipeline::new()
.select(vec!["name".to_string(), "age".to_string()])
.filter("age > 25")?
.sort_by(vec![ops::SortOptions::desc("age".to_string())])
.head(10)
.execute(data)?;
// Write to Parquet
io::write_file(&result, "output.parquet", &io::WriteOptions::default())?;
# Ok::<(), dsq_core::Error>(())
For more convenient usage, dsq-core provides a fluent API:
use dsq_core::api::Dsq;
// Chain operations easily
let result = Dsq::from_file("data.csv")?
.select(&["name", "age", "department"])
.filter_expr("age > 25")
.sort_by(&["department", "age"])
.group_by(&["department"])
.aggregate(&["department"], vec![
dsq_core::ops::aggregate::AggregationFunction::Count,
dsq_core::ops::aggregate::AggregationFunction::Mean("salary".to_string()),
])
.to_json()?;
dsq-core supports optional features for different use cases:
default - Includes all-formats, io, and filter for full functionalityall-formats - Enables all supported data formatsio - File I/O operations and format conversionfilter - jq-compatible filter compilation and executionrepl - Interactive REPL supportcli - Command-line interface componentscsv - CSV/TSV reading and writingjson - JSON and JSON Lines supportparquet - Apache Parquet format supportavro - Apache Avro format support (requires Polars avro feature)dsq-core builds on several key dependencies:
Contributions are welcome! Please see the main CONTRIBUTING.md file for guidelines.
Licensed under either of:
at your option.