-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
104 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
use std::sync::Arc; | ||
|
||
use arrow_array::builder::{StringBuilder, UInt32Builder}; | ||
use arrow_array::RecordBatch; | ||
use arrow_schema::{DataType, Field, Schema}; | ||
use datafusion::common::Result as DFResult; | ||
use datafusion::execution::memory_pool::human_readable_size; | ||
use datafusion::functions_aggregate::expr_fn::sum; | ||
use datafusion::prelude::{col, lit, DataFrame, SessionContext}; | ||
use lazy_static::lazy_static; | ||
use vortex::compress::Compressor; | ||
use vortex::encoding::EncodingRef; | ||
use vortex::{Array, Context, IntoArray, ToArrayData}; | ||
use vortex_datafusion::SessionContextExt; | ||
use vortex_dict::DictEncoding; | ||
use vortex_fastlanes::{BitPackedEncoding, DeltaEncoding, FoREncoding}; | ||
|
||
lazy_static! { | ||
pub static ref CTX: Context = Context::default().with_encodings([ | ||
&BitPackedEncoding as EncodingRef, | ||
&DictEncoding, | ||
&FoREncoding, | ||
&DeltaEncoding, | ||
]); | ||
} | ||
|
||
fn toy_dataset_arrow() -> RecordBatch { | ||
// 64,000 rows of string and numeric data. | ||
// 8,000 values of first string, second string, third string, etc. | ||
|
||
let names = [ | ||
"Alexander", | ||
"Anastasia", | ||
"Archibald", | ||
"Bartholomew", | ||
"Benjamin", | ||
"Christopher", | ||
"Elizabeth", | ||
"Gabriella", | ||
]; | ||
|
||
let mut col1 = StringBuilder::with_capacity(640_000, 64_000_000); | ||
let mut col2 = UInt32Builder::with_capacity(640_000); | ||
for i in 0..640_000 { | ||
col1.append_value(names[i % 8]); | ||
col2.append_value(u32::try_from(i).unwrap()); | ||
} | ||
|
||
let col1 = col1.finish(); | ||
let col2 = col2.finish(); | ||
|
||
RecordBatch::try_new( | ||
Arc::new(Schema::new(vec![ | ||
Field::new("names", DataType::Utf8, false), | ||
Field::new("scores", DataType::UInt32, false), | ||
])), | ||
vec![Arc::new(col1), Arc::new(col2)], | ||
) | ||
.unwrap() | ||
} | ||
|
||
fn toy_dataset_vortex(compress: bool) -> Array { | ||
let uncompressed = toy_dataset_arrow().to_array_data().into_array(); | ||
|
||
if !compress { | ||
return uncompressed; | ||
} | ||
|
||
println!( | ||
"uncompressed size: {:?}", | ||
human_readable_size(uncompressed.nbytes()) | ||
); | ||
let compressor = Compressor::new(&CTX); | ||
let compressed = compressor.compress(&uncompressed, None).unwrap(); | ||
println!( | ||
"vortex compressed size: {:?}", | ||
human_readable_size(compressed.nbytes()) | ||
); | ||
compressed | ||
} | ||
|
||
fn filter_agg_query(df: DataFrame) -> DFResult<DataFrame> { | ||
// SELECT SUM(scores) FROM table WHERE scores >= 3000 AND scores <= 4000 | ||
df.filter(col("scores").gt_eq(lit(3_000)))? | ||
.filter(col("scores").lt_eq(lit(4_000)))? | ||
.aggregate(vec![col("names")], vec![sum(col("scores"))]) | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> DFResult<()> { | ||
let context = SessionContext::new(); | ||
|
||
let vortex_array = toy_dataset_vortex(true); | ||
|
||
let df = context.read_vortex(vortex_array)?; | ||
let result = filter_agg_query(df)?.collect().await?; | ||
println!("result: {:?}", result); | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters