8000 Implement PyArrow Dataset TableProvider by kdbrooks · Pull Request #9 · apache/datafusion-python · GitHub
[go: up one dir, main page]

Skip to content

Implement PyArrow Dataset TableProvider #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change match on booleans to if else.
  • Loading branch information
kdbrooks committed Jul 22, 2022
commit 8967f4b848a93919e357dda4ccd04f706147e087
11 changes: 6 additions & 5 deletions src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ impl Dataset {
// Ensure that we were passed an instance of pyarrow.dataset.Dataset
let ds = PyModule::import(py, "pyarrow.dataset")?;
let ds_type: &PyType = ds.getattr("Dataset")?.downcast()?;
match dataset.is_instance(ds_type)? {
true => Ok(Dataset {
if dataset.is_instance(ds_type)? {
Ok(Dataset {
dataset: dataset.into(),
}),
false => Err(PyValueError::new_err(
})
} else {
Err(PyValueError::new_err(
"dataset argument must be a pyarrow.dataset.Dataset object",
)),
))
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions src/pyarrow_filter_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,13 @@ impl TryFrom<&Expr> for PyArrowFilterExpression {
let le = op_module.getattr("le")?;
let invert = op_module.getattr("invert")?;

// You can't do scalar <= field() <= scalar in PyArrow, no idea why
// scalar <= field() returns a boolean expression so we need to use and to combine these
let ret = and.call1((
le.call1((low, expr.clone_ref(py)))?,
le.call1((expr, high))?,
))?;

Ok(match negated {
true => invert.call1((ret,))?,
false => ret,
})
Ok(if *negated { invert.call1((ret,))? } else { ret })
}
Expr::InList {
expr,
Expand All @@ -180,10 +177,7 @@ impl TryFrom<&Expr> for PyArrowFilterExpression {
let ret = expr.call_method1("isin", (scalars,))?;
let invert = op_module.getattr("invert")?;

Ok(match negated {
true => invert.call1((ret,))?,
false => ret,
})
Ok(if *negated { invert.call1((ret,))? } else { ret })
}
_ => Err(DataFusionError::Common(format!(
"Unsupported Datafusion expression {:?}",
Expand Down
0