Apache DataFusion SQL Query Engine
ARROW-4940: [Rust] Enable warnings for missing docs, add docs in datafusion
Owen Nelson061ca23fdb11
diff --git a/rust/datafusion/src/datasource/csv.rs b/rust/datafusion/src/datasource/csv.rsindex 79b3cd2b7a..fa2f54b107 100644--- a/rust/datafusion/src/datasource/csv.rs+++ b/rust/datafusion/src/datasource/csv.rs@@ -29,6 +29,7 @@ use crate::datasource::{RecordBatchIterator, ScanResult, Table};use crate::error::Result;/// Represents a CSV file with a provided schema+// TODO: usage example (rather than documenting `new()`)pub struct CsvFile {filename: String,schema: Arc<Schema>,@@ -36,6 +37,7 @@ pub struct CsvFile {}impl CsvFile {+ #[allow(missing_docs)]pub fn new(filename: &str, schema: &Schema, has_header: bool) -> Self {Self {filename: String::from(filename),@@ -66,12 +68,14 @@ impl Table for CsvFile {}/// Iterator over CSV batches+// TODO: usage example (rather than documenting `new()`)pub struct CsvBatchIterator {schema: Arc<Schema>,reader: csv::Reader<File>,}impl CsvBatchIterator {+ #[allow(missing_docs)]pub fn new(filename: &str,schema: Arc<Schema>,diff --git a/rust/datafusion/src/datasource/datasource.rs b/rust/datafusion/src/datasource/datasource.rsindex 7db351eeb5..7f9727aafb 100644--- a/rust/datafusion/src/datasource/datasource.rs+++ b/rust/datafusion/src/datasource/datasource.rs@@ -24,6 +24,8 @@ use arrow::record_batch::RecordBatch;use crate::error::Result;+/// Returned by implementors of `Table#scan`, this `RecordBatchIterator` is wrapped with an `Arc`+/// and `Mutex` so that it can be shared across threads as it is used.pub type ScanResult = Arc<Mutex<RecordBatchIterator>>;/// Source tablediff --git a/rust/datafusion/src/datasource/parquet.rs b/rust/datafusion/src/datasource/parquet.rsindex c30c38d077..c357c37328 100644--- a/rust/datafusion/src/datasource/parquet.rs+++ b/rust/datafusion/src/datasource/parquet.rs@@ -34,12 +34,14 @@ use parquet::reader::schema::parquet_to_arrow_schema;use crate::datasource::{RecordBatchIterator, ScanResult, Table};use crate::error::{ExecutionError, Result};+/// Table-based representation of a `ParquetFile`pub struct ParquetTable {filename: String,schema: Arc<Schema>,}impl ParquetTable {+ /// Attempt to initialize a new `ParquetTable` from a file pathpub fn try_new(filename: &str) -> Result<Self> {let file = File::open(filename)?;let parquet_file = ParquetFile::open(file, None, 0)?;@@ -67,6 +69,7 @@ impl Table for ParquetTable {}}+/// Loader and reader for parquet datapub struct ParquetFile {reader: SerializedFileReader<File>,/// Projection expressed as column indices into underlying parquet reader@@ -172,6 +175,7 @@ where}impl ParquetFile {+ /// Read parquet data from a `File`pub fn open(file: File,projection: Option<Vec<usize>>,diff --git a/rust/datafusion/src/error.rs b/rust/datafusion/src/error.rsindex 26d48b125f..828e961084 100644--- a/rust/datafusion/src/error.rs+++ b/rust/datafusion/src/error.rs@@ -25,10 +25,12 @@ use parquet::errors::ParquetError;use sqlparser::sqlparser::ParserError;+/// Result type for operations that could result in an `ExecutionError`pub type Result<T> = result::Result<T, ExecutionError>;/// DataFusion error#[derive(Debug)]+#[allow(missing_docs)]pub enum ExecutionError {/// Wraps an error from the Arrow crateArrowError(ArrowError),diff --git a/rust/datafusion/src/execution/expression.rs b/rust/datafusion/src/execution/expression.rsindex 6f10d88f83..5a593ba1b9 100644--- a/rust/datafusion/src/execution/expression.rs+++ b/rust/datafusion/src/execution/expression.rs@@ -32,9 +32,11 @@ use crate::logicalplan::{Expr, Operator, ScalarValue};/// Compiled Expression (basically just a closure to evaluate the expression at runtime)pub type CompiledExpr = Rc<Fn(&RecordBatch) -> Result<ArrayRef>>;+/// Similar to `CompiledExpr` but the closure transforms `ArrayRef` to another `ArrayRef`pub type CompiledCastFunction = Rc<Fn(&ArrayRef) -> Result<ArrayRef>>;/// Enumeration of supported aggregate functions+#[allow(missing_docs)] // seems like these variants are self-evidentpub enum AggregateType {Min,Max,diff --git a/rust/datafusion/src/execution/relation.rs b/rust/datafusion/src/execution/relation.rsindex 98a0b4adde..41daebb294 100644--- a/rust/datafusion/src/execution/relation.rs+++ b/rust/datafusion/src/execution/relation.rs@@ -30,6 +30,7 @@ use crate::error::Result;/// trait for all relations (a relation is essentially just an iterator over batches/// of data, with a known schema)pub trait Relation {+ /// Get the next `RecordBatch`, or `None` if the iterator is exhaustedfn next(&mut self) -> Result<Option<RecordBatch>>;/// get the schema for this relationdiff --git a/rust/datafusion/src/lib.rs b/rust/datafusion/src/lib.rsindex 0cce2289c6..8febb08dbe 100644--- a/rust/datafusion/src/lib.rs+++ b/rust/datafusion/src/lib.rs@@ -18,6 +18,8 @@//! DataFusion is a modern distributed compute platform implemented in Rust that uses//! Apache Arrow as the memory model+#![warn(missing_docs)]+extern crate arrow;#[macro_use]extern crate serde_derive;diff --git a/rust/datafusion/src/logicalplan.rs b/rust/datafusion/src/logicalplan.rsindex 2e2bee28a3..c2ac37b0fb 100644--- a/rust/datafusion/src/logicalplan.rs+++ b/rust/datafusion/src/logicalplan.rs@@ -28,11 +28,13 @@ use crate::optimizer::utils;/// Enumeration of supported function types (Scalar and Aggregate)#[derive(Serialize, Deserialize, Debug, Clone)]pub enum FunctionType {+ /// Simple function returning a value per DataFrameScalar,+ /// Aggregate functions produce a value by sampling multiple DataFramesAggregate,}-/// Logical representation of a UDF+/// Logical representation of a UDF (user-defined function)#[derive(Debug, Clone)]pub struct FunctionMeta {/// Function name@@ -46,6 +48,7 @@ pub struct FunctionMeta {}impl FunctionMeta {+ #[allow(missing_docs)]pub fn new(name: String,args: Vec<Field>,@@ -59,60 +62,96 @@ impl FunctionMeta {function_type,}}+ /// Getter for the function namepub fn name(&self) -> &String {&self.name}+ /// Getter for the arg listpub fn args(&self) -> &Vec<Field> {&self.args}+ /// Getter for the `DataType` the function returnspub fn return_type(&self) -> &DataType {&self.return_type}+ /// Getter for the `FunctionType`pub fn function_type(&self) -> &FunctionType {&self.function_type}}+/// Operators applied to expressions#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]pub enum Operator {+ /// Expressions are equalEq,+ /// Expressions are not equalNotEq,+ /// Left side is smaller than right sideLt,+ /// Left side is smaller or equal to right sideLtEq,+ /// Left side is greater than right sideGt,+ /// Left side is greater or equal to right sideGtEq,+ /// AdditionPlus,+ /// SubtractionMinus,+ /// Multiplication operator, like `*`Multiply,+ /// Division operator, like `/`Divide,+ /// Remainder operator, like `%`Modulus,+ /// Logical AND, like `&&`And,+ /// Logical OR, like `||`Or,+ /// Logical NOT, like `!`Not,+ /// Matches a wildcard patternLike,+ /// Does not match a wildcard patternNotLike,}/// ScalarValue enumeration#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]pub enum ScalarValue {+ /// null valueNull,+ /// true or false valueBoolean(bool),+ /// 32bit floatFloat32(f32),+ /// 64bit floatFloat64(f64),+ /// signed 8bit intInt8(i8),+ /// signed 16bit intInt16(i16),+ /// signed 32bit intInt32(i32),+ /// signed 64bit intInt64(i64),+ /// unsigned 8bit intUInt8(u8),+ /// unsigned 16bit intUInt16(u16),+ /// unsigned 32bit intUInt32(u32),+ /// unsigned 64bit intUInt64(u64),+ /// utf-8 encoded stringUtf8(Arc<String>),+ /// List of scalars packed as a structStruct(Vec<ScalarValue>),}impl ScalarValue {+ /// Getter for the `DataType` of the valuepub fn get_datatype(&self) -> DataType {match *self {ScalarValue::Boolean(_) => DataType::Boolean,@@ -141,8 +180,11 @@ pub enum Expr {Literal(ScalarValue),/// binary expression e.g. "age > 21"BinaryExpr {+ /// Left-hand side of the expressionleft: Arc<Expr>,+ /// The comparison operatorop: Operator,+ /// Right-hand side of the expressionright: Arc<Expr>,},/// unary IS NOT NULL@@ -151,26 +193,40 @@ pub enum Expr {IsNull(Arc<Expr>),/// cast a value to a different typeCast {+ /// The expression being castexpr: Arc<Expr>,+ /// The `DataType` the expression will yielddata_type: DataType,},/// sort expression- Sort { expr: Arc<Expr>, asc: bool },+ Sort {+ /// The expression to sort on+ expr: Arc<Expr>,+ /// The direction of the sort+ asc: bool,+ },/// scalar functionScalarFunction {+ /// Name of the functionname: String,+ /// List of expressions to feed to the functions as argumentsargs: Vec<Expr>,+ /// The `DataType` the expression will yieldreturn_type: DataType,},/// aggregate functionAggregateFunction {+ /// Name of the functionname: String,+ /// List of expressions to feed to the functions as argumentsargs: Vec<Expr>,+ /// The `DataType` the expression will yieldreturn_type: DataType,},}impl Expr {+ /// Find the `DataType` for the expressionpub fn get_type(&self, schema: &Schema) -> DataType {match self {Expr::Column(n) => schema.field(*n).data_type().clone(),@@ -199,6 +255,9 @@ impl Expr {}}+ /// Perform a type cast on the expression value.+ ///+ /// Will `Err` if the type cast cannot be performed.pub fn cast_to(&self, cast_to_type: &DataType, schema: &Schema) -> Result<Expr> {let this_type = self.get_type(schema);if this_type == *cast_to_type {@@ -216,6 +275,7 @@ impl Expr {}}+ /// Equalpub fn eq(&self, other: &Expr) -> Expr {Expr::BinaryExpr {left: Arc::new(self.clone()),@@ -224,6 +284,7 @@ impl Expr {}}+ /// Not equalpub fn not_eq(&self, other: &Expr) -> Expr {Expr::BinaryExpr {left: Arc::new(self.clone()),@@ -232,6 +293,7 @@ impl Expr {}}+ /// Greater thanpub fn gt(&self, other: &Expr) -> Expr {Expr::BinaryExpr {left: Arc::new(self.clone()),@@ -240,6 +302,7 @@ impl Expr {}}+ /// Greater than or equal topub fn gt_eq(&self, other: &Expr) -> Expr {Expr::BinaryExpr {left: Arc::new(self.clone()),@@ -248,6 +311,7 @@ impl Expr {}}+ /// Less thanpub fn lt(&self, other: &Expr) -> Expr {Expr::BinaryExpr {left: Arc::new(self.clone()),@@ -256,6 +320,7 @@ impl Expr {}}+ /// Less than or equal topub fn lt_eq(&self, other: &Expr) -> Expr {Expr::BinaryExpr {left: Arc::new(self.clone()),@@ -317,38 +382,63 @@ impl fmt::Debug for Expr {pub enum LogicalPlan {/// A Projection (essentially a SELECT with an expression list)Projection {+ /// The list of expressionsexpr: Vec<Expr>,+ /// The incoming logic planinput: Arc<LogicalPlan>,+ /// The schema descriptionschema: Arc<Schema>,},/// A Selection (essentially a WHERE clause with a predicate expression)- Selection { expr: Expr, input: Arc<LogicalPlan> },+ Selection {+ /// The expression+ expr: Expr,+ /// The incoming logic plan+ input: Arc<LogicalPlan>,+ },/// Represents a list of aggregate expressions with optional grouping expressionsAggregate {+ /// The incoming logic planinput: Arc<LogicalPlan>,+ /// Grouping expressionsgroup_expr: Vec<Expr>,+ /// Aggregate expressionsaggr_expr: Vec<Expr>,+ /// The schema descriptionschema: Arc<Schema>,},/// Represents a list of sort expressions to be applied to a relationSort {+ /// The sort expressionsexpr: Vec<Expr>,+ /// The incoming logic planinput: Arc<LogicalPlan>,+ /// The schema descriptionschema: Arc<Schema>,},/// A table scan against a table that has been registered on a contextTableScan {+ /// The name of the schemaschema_name: String,+ /// The name of the tabletable_name: String,+ /// The schema descriptionschema: Arc<Schema>,+ /// Optional column indices to use as a projectionprojection: Option<Vec<usize>>,},/// An empty relation with an empty schema- EmptyRelation { schema: Arc<Schema> },- // Represents the maximum number of records to return+ EmptyRelation {+ /// The schema description+ schema: Arc<Schema>,+ },+ /// Represents the maximum number of records to returnLimit {+ /// The expressionexpr: Expr,+ /// The logical planinput: Arc<LogicalPlan>,+ /// The schema descriptionschema: Arc<Schema>,},}@@ -450,6 +540,7 @@ impl fmt::Debug for LogicalPlan {}}+/// Verify a given type cast can be performedpub fn can_coerce_from(type_into: &DataType, type_from: &DataType) -> bool {use self::DataType::*;match type_into {diff --git a/rust/datafusion/src/optimizer/optimizer.rs b/rust/datafusion/src/optimizer/optimizer.rsindex 4fc184b794..d9ca44b49b 100644--- a/rust/datafusion/src/optimizer/optimizer.rs+++ b/rust/datafusion/src/optimizer/optimizer.rs@@ -23,5 +23,6 @@ use std::sync::Arc;/// An optimizer rules performs a transformation on a logical plan to produce an optimized logical plan.pub trait OptimizerRule {+ /// Perform optimizations on the planfn optimize(&mut self, plan: &LogicalPlan) -> Result<Arc<LogicalPlan>>;}diff --git a/rust/datafusion/src/optimizer/projection_push_down.rs b/rust/datafusion/src/optimizer/projection_push_down.rsindex 9ffa54b55f..a75982f1ef 100644--- a/rust/datafusion/src/optimizer/projection_push_down.rs+++ b/rust/datafusion/src/optimizer/projection_push_down.rs@@ -40,6 +40,7 @@ impl OptimizerRule for ProjectionPushDown {}impl ProjectionPushDown {+ #[allow(missing_docs)]pub fn new() -> Self {Self {}}diff --git a/rust/datafusion/src/optimizer/type_coercion.rs b/rust/datafusion/src/optimizer/type_coercion.rsindex b2ba38649c..9692c5d0cf 100644--- a/rust/datafusion/src/optimizer/type_coercion.rs+++ b/rust/datafusion/src/optimizer/type_coercion.rs@@ -83,6 +83,7 @@ impl OptimizerRule for TypeCoercionRule {}impl TypeCoercionRule {+ #[allow(missing_docs)]pub fn new() -> Self {Self {}}diff --git a/rust/datafusion/src/sql/parser.rs b/rust/datafusion/src/sql/parser.rsindex f438c037b8..dc46ce0991 100644--- a/rust/datafusion/src/sql/parser.rs+++ b/rust/datafusion/src/sql/parser.rs@@ -31,13 +31,20 @@ macro_rules! parser_err {};}+/// Types of files to parse as DataFrames#[derive(Debug, Clone)]pub enum FileType {+ /// Newline-delimited JSONNdJson,+ /// Apache Parquet columnar storageParquet,+ /// Comma separated valuesCSV,}+/// DataFrame AST Node representations.+///+/// Tokens parsed by `DFParser` are converted into these values.#[derive(Debug, Clone)]pub enum DFASTNode {/// ANSI SQL AST node@@ -210,6 +217,7 @@ impl DFParser {}}+ /// Parse an infix operatorpub fn parse_infix(&mut self,_expr: DFASTNode,diff --git a/rust/datafusion/src/sql/planner.rs b/rust/datafusion/src/sql/planner.rsindex 655694a1c6..50cb77dcdc 100644--- a/rust/datafusion/src/sql/planner.rs+++ b/rust/datafusion/src/sql/planner.rs@@ -31,7 +31,9 @@ use sqlparser::sqlast::*;/// The SchemaProvider trait allows the query planner to obtain meta-data about tables and/// functions referenced in SQL statementspub trait SchemaProvider {+ /// Getter for a field descriptionfn get_table_meta(&self, name: &str) -> Option<Arc<Schema>>;+ /// Getter for a UDF descriptionfn get_function_meta(&self, name: &str) -> Option<Arc<FunctionMeta>>;}