Apache DataFusion SQL Query Engine
ARROW-4196: [Rust] Add explicit SIMD vectorization for arithmetic ops in "array_ops"
Paddy Horand2e8d3ebcd2e
diff --git a/rust/datafusion/examples/csv_sql.rs b/rust/datafusion/examples/csv_sql.rsindex 40959cbb62..86f0f7f5fa 100644--- a/rust/datafusion/examples/csv_sql.rs+++ b/rust/datafusion/examples/csv_sql.rs@@ -28,7 +28,8 @@ use arrow::datatypes::{DataType, Field, Schema};use datafusion::execution::context::ExecutionContext;use datafusion::execution::datasource::CsvDataSource;-/// This example demonstrates executing a simple query against an Arrow data source and fetching results+/// This example demonstrates executing a simple query against an Arrow data source and+/// fetching resultsfn main() {// create local execution contextlet mut ctx = ExecutionContext::new();diff --git a/rust/datafusion/src/dfparser.rs b/rust/datafusion/src/dfparser.rsindex 7abbd8dcf1..f438c037b8 100644--- a/rust/datafusion/src/dfparser.rs+++ b/rust/datafusion/src/dfparser.rs@@ -17,8 +17,8 @@//! SQL Parser//!-//! Note that most SQL parsing is now delegated to the sqlparser crate, which handles ANSI SQL but-//! this module contains DataFusion-specific SQL extensions.+//! Note that most SQL parsing is now delegated to the sqlparser crate, which handles ANSI+//! SQL but this module contains DataFusion-specific SQL extensions.use sqlparser::dialect::*;use sqlparser::sqlast::*;diff --git a/rust/datafusion/src/execution/aggregate.rs b/rust/datafusion/src/execution/aggregate.rsindex d8cbfdfbb5..127a1abe8f 100644--- a/rust/datafusion/src/execution/aggregate.rs+++ b/rust/datafusion/src/execution/aggregate.rs@@ -15,8 +15,8 @@// specific language governing permissions and limitations// under the License.-//! Execution of a simple aggregate relation containing MIN, MAX, COUNT, SUM aggregate functions-//! with optional GROUP BY columns+//! Execution of a simple aggregate relation containing MIN, MAX, COUNT, SUM aggregate+//! functions with optional GROUP BY columnsuse std::cell::RefCell;use std::rc::Rc;@@ -63,8 +63,8 @@ impl AggregateRelation {}}-/// Enumeration of types that can be used in a GROUP BY expression (all primitives except for-/// floating point numerics)+/// Enumeration of types that can be used in a GROUP BY expression (all primitives except+/// for floating point numerics)#[derive(Debug, PartialEq, Eq, Hash, Clone)]enum GroupByScalar {UInt8(u8),@@ -692,7 +692,8 @@ macro_rules! group_array_from_map_entries {}};}-/// Create array from `value` attribute in map entry (representing an aggregate scalar value)+/// Create array from `value` attribute in map entry (representing an aggregate scalar+/// value)macro_rules! aggr_array_from_map_entries {($BUILDER:ident, $TY:ident, $ENTRIES:expr, $COL_INDEX:expr) => {{let mut builder = $BUILDER::new($ENTRIES.len());@@ -803,9 +804,10 @@ impl AggregateRelation {}fn with_group_by(&mut self) -> Result<Option<RecordBatch>> {- //NOTE this whole method is currently very inefficient with too many per-row operations- // involving pattern matching and downcasting ... I'm sure this can be re-implemented in- // a much more efficient way that takes better advantage of Arrow+ //NOTE this whole method is currently very inefficient with too many per-row+ // operations involving pattern matching and downcasting ... I'm sure this+ // can be re-implemented in a much more efficient way that takes better+ // advantage of Arrow// create map to store aggregate resultslet mut map: FnvHashMap<Vec<GroupByScalar>, Rc<RefCell<AccumulatorSet>>> =@@ -877,7 +879,8 @@ impl AggregateRelation {}).collect::<Result<Vec<GroupByScalar>>>()?;- //TODO: find more elegant way to write this instead of hacking around ownership issues+ //TODO: find more elegant way to write this instead of hacking around+ // ownership issueslet updated = match map.get(&key) {Some(entry) => {diff --git a/rust/datafusion/src/execution/expression.rs b/rust/datafusion/src/execution/expression.rsindex fa6201a84d..48a90a3c61 100644--- a/rust/datafusion/src/execution/expression.rs+++ b/rust/datafusion/src/execution/expression.rs@@ -298,12 +298,13 @@ pub fn compile_scalar_expr() -> Result<RuntimeExpr> {match expr {&Expr::Literal(ref value) => match value {- //NOTE: this is a temporary hack .. due to the way expressions like 'a > 1' are- // evaluated, currently the left and right are evaluated separately and must result- // in arrays and then the '>' operator is evaluated against the two arrays. This works- // but is dumb ... I intend to optimize this soon to add special handling for- // binary expressions that involve literal values to avoid creating arrays of literals- // filed as https://github.com/andygrove/datafusion/issues/191+ //NOTE: this is a temporary hack .. due to the way expressions like 'a > 1'+ // are evaluated, currently the left and right are evaluated+ // separately and must result in arrays and then the '>' operator+ // is evaluated against the two arrays. This works but is dumb ...+ // I intend to optimize this soon to add special handling for+ // binary expressions that involve literal values to avoid creating arrays of+ // literals filed as https://github.com/andygrove/datafusion/issues/191ScalarValue::Int8(n) => literal_array!(n, Int8Array, Int8),ScalarValue::Int16(n) => literal_array!(n, Int16Array, Int16),ScalarValue::Int32(n) => literal_array!(n, Int32Array, Int32),diff --git a/rust/datafusion/src/execution/filter.rs b/rust/datafusion/src/execution/filter.rsindex ba20dca036..32c1628fec 100644--- a/rust/datafusion/src/execution/filter.rs+++ b/rust/datafusion/src/execution/filter.rs@@ -192,7 +192,8 @@ fn filter(array: &Arc<Array>, filter: &BooleanArray) -> Result<ArrayRef> {Ok(Arc::new(builder.finish()))}DataType::Utf8 => {- //TODO: this is inefficient and we should improve the Arrow impl to help make this more concise+ //TODO: this is inefficient and we should improve the Arrow impl to help make+ // this more conciselet b = a.as_any().downcast_ref::<BinaryArray>().unwrap();let mut values: Vec<String> = Vec::with_capacity(b.len());for i in 0..b.len() {diff --git a/rust/datafusion/src/lib.rs b/rust/datafusion/src/lib.rsindex 6ea2a36117..a93872ca5d 100644--- a/rust/datafusion/src/lib.rs+++ b/rust/datafusion/src/lib.rs@@ -15,8 +15,8 @@// specific language governing permissions and limitations// under the License.-//! DataFusion is a modern distributed compute platform implemented in Rust that uses Apache Arrow-//! as the memory model+//! DataFusion is a modern distributed compute platform implemented in Rust that uses+//! Apache Arrow as the memory modelextern crate arrow;#[macro_use]diff --git a/rust/datafusion/src/logicalplan.rs b/rust/datafusion/src/logicalplan.rsindex 7dd4602b30..5e3b17e47d 100644--- a/rust/datafusion/src/logicalplan.rs+++ b/rust/datafusion/src/logicalplan.rs@@ -316,8 +316,8 @@ impl fmt::Debug for Expr {}}-/// The LogicalPlan represents different types of relations (such as Projection, Selection, etc) and-/// can be created by the SQL query planner and the DataFrame API.+/// The LogicalPlan represents different types of relations (such as Projection,+/// Selection, etc) and can be created by the SQL query planner and the DataFrame API.#[derive(Serialize, Deserialize, Clone)]pub enum LogicalPlan {/// A Projection (essentially a SELECT with an expression list)diff --git a/rust/datafusion/src/sqlplanner.rs b/rust/datafusion/src/sqlplanner.rsindex fc8048f856..a45d5a48df 100644--- a/rust/datafusion/src/sqlplanner.rs+++ b/rust/datafusion/src/sqlplanner.rs@@ -313,7 +313,8 @@ impl SqlToRel {.map(|a| self.sql_to_rex(a, schema)).collect::<Result<Vec<Expr>>>()?;- // return type is same as the argument type for these aggregate functions+ // return type is same as the argument type for these aggregate+ // functionslet return_type = rex_args[0].get_type(schema).clone();Ok(Expr::AggregateFunction {@@ -326,7 +327,8 @@ impl SqlToRel {let rex_args = args.iter().map(|a| match a {- // this feels hacky but translate COUNT(1)/COUNT(*) to COUNT(first_column)+ // this feels hacky but translate COUNT(1)/COUNT(*) to+ // COUNT(first_column)ASTNode::SQLValue(sqlparser::sqlast::Value::Long(1)) => {Ok(Expr::Column(0))}