-
Notifications
You must be signed in to change notification settings - Fork 162
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
Add ANSI support for Subtract #535 #593
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
use std::any::Any; | ||
use std::fmt::{Display, Formatter}; | ||
use std::hash::Hasher; | ||
use std::sync::Arc; | ||
|
||
use arrow_array::{BooleanArray, RecordBatch}; | ||
use arrow_schema::{DataType, Schema}; | ||
use datafusion_common::Result; | ||
use datafusion_expr::{ColumnarValue, Operator}; | ||
use datafusion_expr::interval_arithmetic::Interval; | ||
use datafusion_expr::sort_properties::ExprProperties; | ||
use datafusion_physical_expr::expressions::BinaryExpr; | ||
use datafusion_physical_expr_common::physical_expr::{down_cast_any_ref, PhysicalExpr}; | ||
|
||
use crate::execution::datafusion::expressions::EvalMode; | ||
|
||
#[derive(Debug, Hash, Clone)] | ||
pub struct CometBinaryExpr { | ||
left: Arc<dyn PhysicalExpr>, | ||
op: Operator, | ||
right: Arc<dyn PhysicalExpr>, | ||
eval_mode: EvalMode, | ||
inner: Arc<BinaryExpr>, | ||
} | ||
|
||
impl CometBinaryExpr { | ||
pub fn new( | ||
left: Arc<dyn PhysicalExpr>, | ||
op: Operator, | ||
right: Arc<dyn PhysicalExpr>, | ||
eval_mode: EvalMode, | ||
) -> Self { | ||
Self { | ||
left: Arc::clone(&left), | ||
op, | ||
right: Arc::clone(&right), | ||
eval_mode, | ||
inner: Arc::new(BinaryExpr::new(left, op, right)), | ||
} | ||
} | ||
} | ||
|
||
impl Display for CometBinaryExpr { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
self.inner.fmt(f) | ||
} | ||
} | ||
|
||
impl PhysicalExpr for CometBinaryExpr { | ||
fn as_any(&self) -> &dyn Any { | ||
self.inner.as_any() | ||
} | ||
|
||
fn data_type(&self, input_schema: &Schema) -> Result<DataType> { | ||
self.inner.data_type(input_schema) | ||
} | ||
|
||
fn nullable(&self, input_schema: &Schema) -> Result<bool> { | ||
self.inner.nullable(input_schema) | ||
} | ||
|
||
fn evaluate(&self, batch: &RecordBatch) -> Result<ColumnarValue> { | ||
// TODO: Do some work here | ||
self.inner.evaluate(batch) | ||
} | ||
|
||
fn evaluate_selection( | ||
&self, | ||
batch: &RecordBatch, | ||
selection: &BooleanArray, | ||
) -> Result<ColumnarValue> { | ||
self.inner.evaluate_selection(batch, selection) | ||
} | ||
|
||
fn children(&self) -> Vec<&Arc<dyn PhysicalExpr>> { | ||
self.inner.children() | ||
} | ||
|
||
fn with_new_children( | ||
self: Arc<Self>, | ||
children: Vec<Arc<dyn PhysicalExpr>>, | ||
) -> Result<Arc<dyn PhysicalExpr>> { | ||
Arc::clone(&self.inner).with_new_children(children) | ||
} | ||
|
||
fn evaluate_bounds(&self, children: &[&Interval]) -> Result<Interval> { | ||
self.inner.evaluate_bounds(children) | ||
} | ||
|
||
fn propagate_constraints( | ||
&self, | ||
interval: &Interval, | ||
children: &[&Interval], | ||
) -> Result<Option<Vec<Interval>>> { | ||
self.inner.propagate_constraints(interval, children) | ||
} | ||
|
||
fn dyn_hash(&self, state: &mut dyn Hasher) { | ||
self.inner.dyn_hash(state) | ||
} | ||
|
||
fn get_properties(&self, children: &[ExprProperties]) -> Result<ExprProperties> { | ||
self.inner.get_properties(children) | ||
} | ||
} | ||
|
||
impl PartialEq<dyn Any> for CometBinaryExpr { | ||
fn eq(&self, other: &dyn Any) -> bool { | ||
down_cast_any_ref(other) | ||
.downcast_ref::<Self>() | ||
.map(|x| self.left.eq(&x.left) && self.op == x.op && self.right.eq(&x.right)) | ||
.unwrap_or(false) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -219,6 +219,7 @@ message Subtract { | |
Expr right = 2; | ||
bool fail_on_error = 3; | ||
DataType return_type = 4; | ||
EvalMode eval_mode = 5; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious, if a Substrait plan was to send one of the options how it would map to this new functionality? How does ANSI map to an option? https://substrait.io/extensions/functions_arithmetic/#subtract |
||
} | ||
|
||
message Multiply { | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead, set this
fail_on_error
to true when ANSI enabled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. It makes sense & i will refactor, earlier i was referecing
Abs
.