Elusion ๐ฆ DataFrame Library for Everybody!

Elusion is a high-performance DataFrame library, for in-memory data formats (CSV, JSON, PARQUET, DELTA). Built on top of DataFusion SQL query engine, for managing and querying data using a DataFrame-like interface. Designed for developers who need a powerful abstraction over data transformations, Elusion simplifies complex operations such as filtering, joining, aggregating, and more with an intuitive, chainable API.
Key Features
๐ High-Performance DataFrame Operations
- Load and process data from CSV, PARQUET, JSON, DELTA table files with ease.
- Perform SQL-like transformations such as
SELECT,AGG,STRING FUNCTIONS,JOINFILTER,GROUP BY, andWINDOW.
๐ Aggregations and Analytics
- Built-in support for Aggregated functions like
SUM,AVG,MEAN,MEDIAN,MIN,COUNT,MAXand more. - Advanced Scalar Math functions like
ABS,FLOOR,CEIL,SQRT,ISNAN,ISZERO,PI,POWERand more.
๐ Flexible Joins
- Join tables with various join types (
INNER,LEFT,RIGHT,FULL, etc.). - Intuitive syntax for specifying join conditions and aliases.
๐ช Window Functions
- Add analytical window functions like
RANK,DENSE_RANK,ROW_NUMBER, and custom partition-based calculations.
๐ช PIVOT and UNPIVOT Functions
๐งน Clean Query Construction
- Construct readable and reusable SQL queries.
- Support for Common Table Expressions (CTEs), subqueries, and set operations (
UNION,UNION ALL,INTERSECT,EXCEPT).
๐ ๏ธ Easy-to-Use API
-
Chainable and intuitive API for building queries.
-
Readable debug output of generated SQL for verification.
-
Data Preview: Preview your data easily by displaying a subset of rows in the terminal.
-
Composable Queries: Chain transformations seamlessly to build reusable and testable workflows.
Installation
To add Elusion to your Rust project, include the following lines in your Cargo.toml under [dependencies]:
= "0.5.8"
= { = "1.42.0", = ["rt-multi-thread"] }
Rust version needed
>= 1.81
Usage examples:
MAIN function
use *; // Import everything needed
async
Schema
SCHEMA IS AUTOMATICALLY INFERED since v0.2.5
LOADING Files into CustomDataFrame
File extensions are automatically recognized
All you have to do is to provide path to your file
Currently supported data files: CSV, PARQUET, JSON, DELTA
let csv_data = "C:\\Borivoj\\RUST\\Elusion\\sales_data.csv";
let parquet_path = "C:\\Borivoj\\RUST\\Elusion\\prod_data.parquet";
let json_path = "C:\\Borivoj\\RUST\\Elusion\\db_data.json";
let delta_path = "C:\\Borivoj\\RUST\\Elusion\\agg_sales"; // for DELTA you just specify folder name without extension
Creating CustomDataFrame
2 arguments needed: Path, Table Alias
let df_sales = new.await?;
let df_customers = new.await?;
RULE of thumb:
ALL Column names and Dataframe alias names, will be TRIM(), REPLACE(" ", "_")
ALIAS column names in SELECT() function (AS is case insensitive)
let customers_alias = df_customers
.select;
Where to use which Functions:
Scalar and Operators -> in SELECT() function
Aggregation Functions -> in AGG() function
String Column Functions -> in STRING_FUNCTIONS() function
Numerical Operators (supported +, -, * , / , %)
let num_ops_sales = sales_order_df.clone
.select
.filter
.order_by
.limit;
let num_ops_res = num_ops_sales.elusion.await?;
num_ops_res.display.await?;
FILTERING
let filter_df = sales_order_df
.select
.filter_many
.order_by
.limit;
let filtered = filter_df.elusion.await?;
filtered.display.await?;
SCALAR functions
let scalar_df = sales_order_df
.select
.filter
.order_by
.limit;
let scalar_res = scalar_df.elusion.await?;
scalar_res.display.await?;
AGGREGATE functions with nested Scalar functions
let scalar_df = sales_order_df
.select
.agg
.group_by
.filter
.order_by
.limit;
let scalar_res = scalar_df.elusion.await?;
scalar_res.display.await?;
Numerical Operators, Scalar Functions, Aggregated Functions...
let mix_query = sales_order_df
.select
.agg
.filter
.group_by_all
.order_by_many;
let mix_res = mix_query.elusion.await?;
mix_res.display.await?;
Supported Aggregation functions
SUM, AVG, MEAN, MEDIAN, MIN, COUNT, MAX,
LAST_VALUE, FIRST_VALUE,
GROUPING, STRING_AGG, ARRAY_AGG, VAR, VAR_POP,
VAR_POPULATION, VAR_SAMP, VAR_SAMPLE,
BIT_AND, BIT_OR, BIT_XOR, BOOL_AND, BOOL_OR
Supported Scalar Math Functions
ABS, FLOOR, CEIL, SQRT, ISNAN, ISZERO,
PI, POW, POWER, RADIANS, RANDOM, ROUND,
FACTORIAL, ACOS, ACOSH, ASIN, ASINH,
COS, COSH, COT, DEGREES, EXP,
SIN, SINH, TAN, TANH, TRUNC, CBRT,
ATAN, ATAN2, ATANH, GCD, LCM, LN,
LOG, LOG10, LOG2, NANVL, SIGNUM
JOINs
JOIN example with 2 dataframes, AGGREGATION, GROUP BY
let single_join = df_sales
.join
.select
.agg
.group_by
.having
.order_by // true is ascending, false is descending
.limit;
let join_df1 = single_join.elusion.await?;
join_df1.display.await?;
JOIN with 3 dataframes, AGGREGATION, GROUP BY, HAVING, SELECT, ORDER BY
let many_joins = df_sales
.join_many
.select
.agg
.group_by
.having_many
.order_by_many
.limit;
let join_df3 = many_joins.elusion.await?;
join_df3.display.await?;
JOIN with 3 dataframes, STRING FUNCTIONS, AGGREGATION, GROUP BY, HAVING_MANY, ORDER BY
let str_func_joins = df_sales
.join_many
.select
.string_functions
.agg
.group_by_all
.having_many
.order_by_many;
let join_str_df3 = str_func_joins.elusion.await?;
join_str_df3.display.await?;
Currently implemented join types
"INNER", "LEFT", "RIGHT", "FULL",
"LEFT SEMI", "RIGHT SEMI",
"LEFT ANTI", "RIGHT ANTI", "LEFT MARK"
STRING FUNCTIONS
let string_functions_df = df_sales
.join_many
.select
.string_functions
.agg
.filter
.group_by_all
.having
.order_by;
let str_df = string_functions_df.elusion.await?;
str_df.display.await?;
Currently Available String functions
1.Basic String Functions:
TRIM - Remove leading/trailing spaces
LTRIM - Remove leading spaces
RTRIM - Remove trailing spaces
UPPER - Convert to uppercase
LOWER - Convert to lowercase
LENGTH or LEN - Get string length
LEFT - Extract leftmost characters
RIGHT - Extract rightmost characters
SUBSTRING - Extract part of string
2. String concatenation:
CONCAT - Concatenate strings
CONCAT_WS - Concatenate with separator
3. String Position and Search:
POSITION - Find position of substring
STRPOS - Find position of substring
INSTR - Find position of substring
LOCATE - Find position of substring
4. String Replacement and Modification:
REPLACE - Replace all occurrences of substring
TRANSLATE - Replace characters
OVERLAY - Replace portion of string
REPEAT - Repeat string
REVERSE - Reverse string characters
5. String Pattern Matching:
LIKE - Pattern matching with wildcards
REGEXP or RLIKE - Pattern matching with regular expressions
6. String Padding:
LPAD - Pad string on left
RPAD - Pad string on right
SPACE - Generate spaces
7. String Case Formatting:
INITCAP - Capitalize first letter of each word
8. String Extraction:
SPLIT_PART - Split string and get nth part
SUBSTR - Get substring
9. String Type Conversion:
TO_CHAR - Convert to string
CAST - Type conversion
CONVERT - Type conversion
WINDOW functions
Aggregate, Ranking and Analytical functions
let window_query = df_sales.clone
.join
.select
//aggregated window functions
.window
.window
.window
.window
.window
//ranking window functions
.window
.window
.window
.window
.window
// analytical window functions
.window
.window
.window
.window
.window
let window_df = window_query.elusion.await?;
window_df.display.await?;
Rolling Window Functions
let rollin_query = df_sales.clone
.join
.select
//aggregated rolling windows
.window
.window;
let rollin_df = rollin_query.elusion.await?;
rollin_df.display.await?;
UNION, UNION ALL, EXCEPT, INTERSECT
UNION: Combines rows from both, removing duplicates
UNION ALL: Combines rows from both, keeping duplicates
EXCEPT: Difference of two sets (only rows in left minus those in right).
INTERSECT: Intersection of two sets (only rows in both).
//UNION
let df1 = df_sales
.join
.select
.string_functions;
let df2 = df_sales
.join
.select
.string_functions;
let union_df = df1.union;
let union_df_final = union_df.elusion.await?;
union_df_final.display.await?;
//UNION ALL
let union_all_df = df1.union_all;
//EXCEPT
let except_df = df1.except;
//INTERSECT
let intersect_df = df1.intersect;
PIVOT and UNPIVOT
Pivot and Unpivot functions are ASYNC function
They should be used separatelly from other functions: 1. directly on initial CustomDataFrame, 2. after .elusion() evaluation.
Future needs to be in final state so .await? must be used
// PIVOT
// directly on initial CustomDataFrame
let sales_p = "C:\\Borivoj\\RUST\\Elusion\\SalesData2022.csv";
let df_sales = new.await?;
let pivoted = df_sales
.pivot.await?;
let result_pivot = pivoted.elusion.await?;
result_pivot.display.await?;
// after .elusion() evaluation
let sales_path = "C:\\Borivoj\\RUST\\Elusion\\sales_order_report.csv";
let sales_order_df = new.await?;
let scalar_df = sales_order_df
.select
.filter
.order_by
.limit;
let scalar_res = scalar_df.elusion.await?;
scalar_res.display.await?;
let pivoted_scalar = scalar_res
.pivot.await?;
let pitvoted_scalar = pivoted_scalar.elusion.await?;
pitvoted_scalar.display.await?;
// UNPIVOT
let unpivoted = result_pivot
.unpivot.await?;
let result_unpivot = unpivoted.elusion.await?;
result_unpivot.display.await?;
// example 2
let unpivot_scalar = scalar_res
.unpivot.await?;
let result_unpivot_scalar = unpivot_scalar.elusion.await?;
result_unpivot_scalar.display.await?;
JSON files
Currently supported files can include: Arrays, Objects. Best usage if you can make it flat ("key":"value")
for JSON, all field types are infered to VARCHAR/TEXT/STRING
// example json structure
let json_path = "C:\\Borivoj\\RUST\\Elusion\\test.json";
let json_df = new.await?;
// example json structure
let json_path = "C:\\Borivoj\\RUST\\Elusion\\test2.json";
let json_df = new.await?;
WRITERS
Writing to Parquet File
We have 2 writing modes: Overwrite and Append
// overwrite existing file
result_df
.write_to_parquet
.await
.expect;
// append to exisiting file
result_df
.write_to_parquet
.await
.expect;
Writing to CSV File
CSV Writing options are mandatory
has_headers: TRUE is dynamically set for Overwrite mode, and FALSE for Append mode.
let custom_csv_options = CsvWriteOptions ;
We have 2 writing modes: Overwrite and Append
// overwrite existing file
result_df
.write_to_csv
.await
.expect;
// append to exisiting file
result_df
.write_to_csv
.await
.expect;
Writing to DELTA table / lake
We can write to delta in 2 modes Overwrite and Append
Partitioning column is optional
DISCLAIMER: if you decide to use column for partitioning, make sure that you don't need that column as you wont be able to read it back to dataframe
DISCLAIMER 2: once you decide to use partitioning column for writing your delta table, if you want to APPEND to it, Append also need to have same column for partitioning
// Overwrite
result_df
.write_to_delta_table
.await
.expect;
// Append
result_df
.write_to_delta_table
.await
.expect;
License
Elusion is distributed under the MIT License. However, since it builds upon DataFusion, which is distributed under the Apache License 2.0, some parts of this project are subject to the terms of the Apache License 2.0. For full details, see the LICENSE.txt file.
Acknowledgments
This library leverages the power of Rust's type system and libraries like DataFusion , Arrow for efficient query processing. Special thanks to the open-source community for making this project possible.
๐ง Disclaimer: Under Development ๐ง
This crate is currently under active development and testing. It is not considered stable or ready for production use.
We are actively working to improve the features, performance, and reliability of this library. Breaking changes might occur between versions as we continue to refine the API and functionality.
If you want to contribute or experiment with the crate, feel free to do so, but please be aware of the current limitations and evolving nature of the project.
Thank you for your understanding and support!
Where you can find me:
LindkedIn - LinkedIn YouTube channel - YouTube Udemy Instructor - Udemy