-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add toplevel collect() function and add python adapter
- Loading branch information
Showing
9 changed files
with
201 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,136 @@ | ||
use polars::prelude::*; | ||
use pyo3::exceptions::PyTypeError; | ||
use pyo3::prelude::*; | ||
use pyo3_polars::PyDataFrame; | ||
|
||
use cryo_cli::parse_opts; | ||
use cryo_cli::Args; | ||
use cryo_freeze::collect; | ||
|
||
|
||
#[pyfunction( | ||
signature = ( | ||
datatype, | ||
blocks, | ||
*, | ||
align = false, | ||
reorg_buffer = 0, | ||
include_columns = None, | ||
exclude_columns = None, | ||
columns = None, | ||
hex = false, | ||
sort = None, | ||
rpc = None, | ||
network_name = None, | ||
requests_per_second = None, | ||
max_concurrent_requests = None, | ||
max_concurrent_chunks = None, | ||
dry = false, | ||
chunk_size = 1000, | ||
n_chunks = None, | ||
output_dir = ".".to_string(), | ||
file_suffix = None, | ||
overwrite = false, | ||
csv = false, | ||
json = false, | ||
row_group_size = None, | ||
n_row_groups = None, | ||
no_stats = false, | ||
compression = vec!["lz4".to_string()], | ||
contract = None, | ||
topic0 = None, | ||
topic1 = None, | ||
topic2 = None, | ||
topic3 = None, | ||
inner_request_size = 1, | ||
) | ||
)] | ||
#[allow(clippy::too_many_arguments)] | ||
pub fn _collect( | ||
py: Python<'_>, | ||
datatype: Vec<String>, | ||
blocks: Vec<String>, | ||
align: bool, | ||
reorg_buffer: u64, | ||
include_columns: Option<Vec<String>>, | ||
exclude_columns: Option<Vec<String>>, | ||
columns: Option<Vec<String>>, | ||
hex: bool, | ||
sort: Option<Vec<String>>, | ||
rpc: Option<String>, | ||
network_name: Option<String>, | ||
requests_per_second: Option<u32>, | ||
max_concurrent_requests: Option<u64>, | ||
max_concurrent_chunks: Option<u64>, | ||
dry: bool, | ||
chunk_size: u64, | ||
n_chunks: Option<u64>, | ||
output_dir: String, | ||
file_suffix: Option<String>, | ||
overwrite: bool, | ||
csv: bool, | ||
json: bool, | ||
row_group_size: Option<usize>, | ||
n_row_groups: Option<usize>, | ||
no_stats: bool, | ||
compression: Vec<String>, | ||
contract: Option<String>, | ||
topic0: Option<String>, | ||
topic1: Option<String>, | ||
topic2: Option<String>, | ||
topic3: Option<String>, | ||
inner_request_size: u64, | ||
) -> PyResult<&PyAny> { | ||
let args = Args { | ||
datatype, | ||
blocks, | ||
align, | ||
reorg_buffer, | ||
include_columns, | ||
exclude_columns, | ||
columns, | ||
hex, | ||
sort, | ||
rpc, | ||
network_name, | ||
requests_per_second, | ||
max_concurrent_requests, | ||
max_concurrent_chunks, | ||
dry, | ||
chunk_size, | ||
n_chunks, | ||
output_dir, | ||
file_suffix, | ||
overwrite, | ||
csv, | ||
json, | ||
row_group_size, | ||
n_row_groups, | ||
no_stats, | ||
compression, | ||
contract, | ||
topic0, | ||
topic1, | ||
topic2, | ||
topic3, | ||
inner_request_size, | ||
}; | ||
|
||
pyo3_asyncio::tokio::future_into_py(py, async move { | ||
match run(args).await { | ||
Ok(()) => Ok(Python::with_gil(|py| py.None())), | ||
match run_collect(args).await { | ||
// Ok(df) => Ok(Python::with_gil(|py| py.None())), | ||
Ok(df) => Ok(PyDataFrame(df)), | ||
Err(_e) => Err(PyErr::new::<PyTypeError, _>("failed")), | ||
} | ||
}) | ||
} | ||
|
||
async fn run_collect(args: Args) -> PolarsResult<DataFrame> { | ||
let (query, source, _sink) = match parse_opts(&args).await { | ||
Ok(opts) => opts, | ||
Err(_e) => panic!(), | ||
}; | ||
match collect(query.into(), source).await { | ||
Ok(df) => Ok(df), | ||
Err(_e) => panic!(), | ||
} | ||
} |
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