forked from apache/datafusion
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '1dd535451198777693ac962a21b79a680bd4b7e8' into chunchun…
…/update-df-apr-week-1-2
- Loading branch information
Showing
26 changed files
with
972 additions
and
655 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
|
||
[package] | ||
name = "datafusion-physical-expr-common" | ||
description = "Common functionality of physical expression for DataFusion query engine" | ||
keywords = ["arrow", "query", "sql"] | ||
readme = "README.md" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
homepage = { workspace = true } | ||
repository = { workspace = true } | ||
license = { workspace = true } | ||
authors = { workspace = true } | ||
rust-version = { workspace = true } | ||
|
||
[lib] | ||
name = "datafusion_physical_expr_common" | ||
path = "src/lib.rs" | ||
|
||
[dependencies] | ||
arrow = { workspace = true } | ||
datafusion-common = { workspace = true, default-features = true } | ||
datafusion-expr = { workspace = true } |
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,27 @@ | ||
<!--- | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
--> | ||
|
||
# DataFusion Core Physical Expressions | ||
|
||
[DataFusion][df] is an extensible query execution framework, written in Rust, that uses Apache Arrow as its in-memory format. | ||
|
||
This crate is a submodule of DataFusion that provides shared APIs for implementing | ||
physical expressions such as `PhysicalExpr` and `PhysicalSortExpr`. | ||
|
||
[df]: https://crates.io/crates/datafusion |
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,102 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
pub mod utils; | ||
|
||
use std::any::Any; | ||
use std::fmt::Debug; | ||
use std::sync::Arc; | ||
|
||
use crate::physical_expr::PhysicalExpr; | ||
use crate::sort_expr::PhysicalSortExpr; | ||
|
||
use arrow::datatypes::Field; | ||
use datafusion_common::{not_impl_err, Result}; | ||
use datafusion_expr::{Accumulator, GroupsAccumulator}; | ||
|
||
/// An aggregate expression that: | ||
/// * knows its resulting field | ||
/// * knows how to create its accumulator | ||
/// * knows its accumulator's state's field | ||
/// * knows the expressions from whose its accumulator will receive values | ||
/// | ||
/// Any implementation of this trait also needs to implement the | ||
/// `PartialEq<dyn Any>` to allows comparing equality between the | ||
/// trait objects. | ||
pub trait AggregateExpr: Send + Sync + Debug + PartialEq<dyn Any> { | ||
/// Returns the aggregate expression as [`Any`] so that it can be | ||
/// downcast to a specific implementation. | ||
fn as_any(&self) -> &dyn Any; | ||
|
||
/// the field of the final result of this aggregation. | ||
fn field(&self) -> Result<Field>; | ||
|
||
/// the accumulator used to accumulate values from the expressions. | ||
/// the accumulator expects the same number of arguments as `expressions` and must | ||
/// return states with the same description as `state_fields` | ||
fn create_accumulator(&self) -> Result<Box<dyn Accumulator>>; | ||
|
||
/// the fields that encapsulate the Accumulator's state | ||
/// the number of fields here equals the number of states that the accumulator contains | ||
fn state_fields(&self) -> Result<Vec<Field>>; | ||
|
||
/// expressions that are passed to the Accumulator. | ||
/// Single-column aggregations such as `sum` return a single value, others (e.g. `cov`) return many. | ||
fn expressions(&self) -> Vec<Arc<dyn PhysicalExpr>>; | ||
|
||
/// Order by requirements for the aggregate function | ||
/// By default it is `None` (there is no requirement) | ||
/// Order-sensitive aggregators, such as `FIRST_VALUE(x ORDER BY y)` should implement this | ||
fn order_bys(&self) -> Option<&[PhysicalSortExpr]> { | ||
None | ||
} | ||
|
||
/// Human readable name such as `"MIN(c2)"`. The default | ||
/// implementation returns placeholder text. | ||
fn name(&self) -> &str { | ||
"AggregateExpr: default name" | ||
} | ||
|
||
/// If the aggregate expression has a specialized | ||
/// [`GroupsAccumulator`] implementation. If this returns true, | ||
/// `[Self::create_groups_accumulator`] will be called. | ||
fn groups_accumulator_supported(&self) -> bool { | ||
false | ||
} | ||
|
||
/// Return a specialized [`GroupsAccumulator`] that manages state | ||
/// for all groups. | ||
/// | ||
/// For maximum performance, a [`GroupsAccumulator`] should be | ||
/// implemented in addition to [`Accumulator`]. | ||
fn create_groups_accumulator(&self) -> Result<Box<dyn GroupsAccumulator>> { | ||
not_impl_err!("GroupsAccumulator hasn't been implemented for {self:?} yet") | ||
} | ||
|
||
/// Construct an expression that calculates the aggregate in reverse. | ||
/// Typically the "reverse" expression is itself (e.g. SUM, COUNT). | ||
/// For aggregates that do not support calculation in reverse, | ||
/// returns None (which is the default value). | ||
fn reverse_expr(&self) -> Option<Arc<dyn AggregateExpr>> { | ||
None | ||
} | ||
|
||
/// Creates accumulator implementation that supports retract | ||
fn create_sliding_accumulator(&self) -> Result<Box<dyn Accumulator>> { | ||
not_impl_err!("Retractable Accumulator hasn't been implemented for {self:?} yet") | ||
} | ||
} |
Oops, something went wrong.