Skip to content

Apache DataFusion SQL Query Engine

minor: Improve docstrings (#4748)

Andrew Lambd8695a9c5854
diff --git a/datafusion/common/src/error.rs b/datafusion/common/src/error.rs
index 31e5f91d19..47b026d598 100644
--- a/datafusion/common/src/error.rs
+++ b/datafusion/common/src/error.rs
@@ -343,7 +343,7 @@ enum OtherErr<'a> {
impl DataFusionError {
/// Get deepest underlying [`DataFusionError`]
///
- /// [`DatafusionError`]s sometimes form a chain, such as `DatafusionError::ArrowError()` in order to conform
+ /// [`DataFusionError`]s sometimes form a chain, such as `DataFusionError::ArrowError()` in order to conform
/// to the correct error signature. Thus sometimes there is a chain several layers deep that can obscure the
/// original error. This function finds the lowest level DataFusionError possible.
///
diff --git a/datafusion/common/src/scalar.rs b/datafusion/common/src/scalar.rs
index b6a49fbf65..96bf7f5ed8 100644
--- a/datafusion/common/src/scalar.rs
+++ b/datafusion/common/src/scalar.rs
@@ -46,9 +46,11 @@ use arrow::{
use chrono::{Datelike, Duration, NaiveDate, NaiveDateTime};
/// Represents a dynamically typed, nullable single value.
-/// This is the single-valued counter-part of arrow's `Array`.
-/// https://arrow.apache.org/docs/python/api/datatypes.html
-/// https://github.com/apache/arrow/blob/master/format/Schema.fbs#L354-L375
+/// This is the single-valued counter-part to arrow's [`Array`].
+///
+/// See [datatypes](https://arrow.apache.org/docs/python/api/datatypes.html) for
+/// details on datatypes and the [format](https://github.com/apache/arrow/blob/master/format/Schema.fbs#L354-L375)
+/// for the definitive reference.
#[derive(Clone)]
pub enum ScalarValue {
/// represents `DataType::Null` (castable to/from any other type)
diff --git a/datafusion/common/src/table_reference.rs b/datafusion/common/src/table_reference.rs
index 17f1e231d5..d8ad835cae 100644
--- a/datafusion/common/src/table_reference.rs
+++ b/datafusion/common/src/table_reference.rs
@@ -15,7 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-// / Represents a resolved path to a table of the form "catalog.schema.table"
+/// A resolved path to a table of the form "catalog.schema.table"
#[derive(Debug, Clone, Copy)]
pub struct ResolvedTableReference<'a> {
/// The catalog (aka database) containing the table
@@ -161,7 +161,7 @@ impl<'a> TableReference<'a> {
}
}
- /// Forms a [`TableReferece`] by splitting `s` on periods `.`.
+ /// Forms a [`TableReference`] by splitting `s` on periods `.`.
///
/// Note that this function does NOT handle periods or name
/// normalization correctly (e.g. `"foo.bar"` will be parsed as
diff --git a/datafusion/common/src/test_util.rs b/datafusion/common/src/test_util.rs
index 3545fd270a..d6f80b8b16 100644
--- a/datafusion/common/src/test_util.rs
+++ b/datafusion/common/src/test_util.rs
@@ -25,7 +25,7 @@
/// Is a macro so test error
/// messages are on the same line as the failure;
///
-/// Both arguments must be convertable into Strings (Into<String>)
+/// Both arguments must be convertable into Strings ([`Into`]<[`String`]>)
#[macro_export]
macro_rules! assert_contains {
($ACTUAL: expr, $EXPECTED: expr) => {
@@ -48,7 +48,7 @@ macro_rules! assert_contains {
/// Is a macro so test error
/// messages are on the same line as the failure;
///
-/// Both arguments must be convertable into Strings (Into<String>)
+/// Both arguments must be convertable into Strings ([`Into`]<[`String`]>)
#[macro_export]
macro_rules! assert_not_contains {
($ACTUAL: expr, $UNEXPECTED: expr) => {
diff --git a/datafusion/expr/src/accumulator.rs b/datafusion/expr/src/accumulator.rs
index 4a6b7ea3d5..7e941d0cff 100644
--- a/datafusion/expr/src/accumulator.rs
+++ b/datafusion/expr/src/accumulator.rs
@@ -40,7 +40,7 @@ pub trait Accumulator: Send + Sync + Debug {
/// The state can be and often is a different type than the output
/// type of the [`Accumulator`].
///
- /// See [`merge_batch`] for more details on the merging process.
+ /// See [`Self::merge_batch`] for more details on the merging process.
///
/// Some accumulators can return multiple values for their
/// intermediate states. For example average, tracks `sum` and
@@ -58,7 +58,7 @@ pub trait Accumulator: Send + Sync + Debug {
/// Retracts an update (caused by the given inputs) to
/// accumulator's state.
///
- /// This is the inverse operation of [`update_batch`] and is used
+ /// This is the inverse operation of [`Self::update_batch`] and is used
/// to incrementally calculate window aggregates where the OVER
/// clause defines a bounded window.
fn retract_batch(&mut self, _values: &[ArrayRef]) -> Result<()> {
@@ -75,7 +75,7 @@ pub trait Accumulator: Send + Sync + Debug {
/// results of calling `[state]` on zero or more other accumulator
/// instances.
///
- /// `states` is an array of the same types as returned by [`state`]
+ /// `states` is an array of the same types as returned by [`Self::state`]
fn merge_batch(&mut self, states: &[ArrayRef]) -> Result<()>;
/// Returns the final aggregate value based on its current state.
diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rs
index 7b11df877f..003b7a37fb 100644
--- a/datafusion/expr/src/expr.rs
+++ b/datafusion/expr/src/expr.rs
@@ -240,7 +240,7 @@ impl BinaryExpr {
}
/// Get the operator precedence
- /// use https://www.postgresql.org/docs/7.0/operators.htm#AEN2026 as a reference
+ /// use <https://www.postgresql.org/docs/7.0/operators.htm#AEN2026> as a reference
pub fn precedence(&self) -> u8 {
match self.op {
Operator::Or => 5,
@@ -516,9 +516,9 @@ impl WindowFunction {
}
/// Grouping sets
-/// See https://www.postgresql.org/docs/current/queries-table-expressions.html#QUERIES-GROUPING-SETS
+/// See <https://www.postgresql.org/docs/current/queries-table-expressions.html#QUERIES-GROUPING-SETS>
/// for Postgres definition.
-/// See https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-groupby.html
+/// See <https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-groupby.html>
/// for Apache Spark definition.
#[derive(Clone, PartialEq, Eq, Hash)]
pub enum GroupingSet {
diff --git a/datafusion/expr/src/expr_fn.rs b/datafusion/expr/src/expr_fn.rs
index fbb406ad26..3c048327c8 100644
--- a/datafusion/expr/src/expr_fn.rs
+++ b/datafusion/expr/src/expr_fn.rs
@@ -39,7 +39,7 @@ pub fn col(ident: impl Into<Column>) -> Expr {
Expr::Column(ident.into())
}
-/// Return a new expression left <op> right
+/// Return a new expression `left <op> right`
pub fn binary_expr(left: Expr, op: Operator, right: Expr) -> Expr {
Expr::BinaryExpr(BinaryExpr::new(Box::new(left), op, Box::new(right)))
}
diff --git a/datafusion/expr/src/logical_plan/plan.rs b/datafusion/expr/src/logical_plan/plan.rs
index 23f26ad8d1..0a3a68dae1 100644
--- a/datafusion/expr/src/logical_plan/plan.rs
+++ b/datafusion/expr/src/logical_plan/plan.rs
@@ -1201,7 +1201,7 @@ pub struct DropView {
pub schema: DFSchemaRef,
}
-/// Set a Variable -- value in [`ConfigOptions`]
+/// Set a Variable's value -- value in [`ConfigOptions`]
#[derive(Clone)]
pub struct SetVariable {
/// The variable name
diff --git a/datafusion/expr/src/type_coercion/binary.rs b/datafusion/expr/src/type_coercion/binary.rs
index 6ecb62abd4..270ed5c8d3 100644
--- a/datafusion/expr/src/type_coercion/binary.rs
+++ b/datafusion/expr/src/type_coercion/binary.rs
@@ -88,7 +88,7 @@ pub fn binary_operator_data_type(
/// when the input argument types do not match the output argument
/// types
///
-/// Tracking issue is https://github.com/apache/arrow-datafusion/issues/3419
+/// Tracking issue is <https://github.com/apache/arrow-datafusion/issues/3419>
pub fn coerce_types(
lhs_type: &DataType,
op: &Operator,
diff --git a/datafusion/expr/src/type_coercion/functions.rs b/datafusion/expr/src/type_coercion/functions.rs
index d611b4dd0a..f58050eb94 100644
--- a/datafusion/expr/src/type_coercion/functions.rs
+++ b/datafusion/expr/src/type_coercion/functions.rs
@@ -26,7 +26,7 @@ use datafusion_common::{DataFusionError, Result};
/// each argument must be coerced to match `signature`.
///
/// For more details on coercion in general, please see the
-/// [`type_coercion`](datafusion_expr::type_coercion) module.
+/// [`type_coercion`](crate::type_coercion) module.
pub fn data_types(
current_types: &[DataType],
signature: &Signature,
diff --git a/datafusion/expr/src/utils.rs b/datafusion/expr/src/utils.rs
index 87c7b2597f..758cb75148 100644
--- a/datafusion/expr/src/utils.rs
+++ b/datafusion/expr/src/utils.rs
@@ -258,7 +258,7 @@ pub fn generate_sort_key(
}
/// Compare the sort expr as PostgreSQL's common_prefix_cmp():
-/// https://github.com/postgres/postgres/blob/master/src/backend/optimizer/plan/planner.c
+/// <https://github.com/postgres/postgres/blob/master/src/backend/optimizer/plan/planner.c>
pub fn compare_sort_expr(
sort_expr_a: &Expr,
sort_expr_b: &Expr,
diff --git a/datafusion/expr/src/window_frame.rs b/datafusion/expr/src/window_frame.rs
index 100ea8e1de..94020a4f8f 100644
--- a/datafusion/expr/src/window_frame.rs
+++ b/datafusion/expr/src/window_frame.rs
@@ -147,9 +147,9 @@ impl WindowFrame {
/// There are five ways to describe starting and ending frame boundaries:
///
/// 1. UNBOUNDED PRECEDING
-/// 2. <expr> PRECEDING
+/// 2. `<expr>` PRECEDING
/// 3. CURRENT ROW
-/// 4. <expr> FOLLOWING
+/// 4. `<expr>` FOLLOWING
/// 5. UNBOUNDED FOLLOWING
///
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -157,9 +157,9 @@ pub enum WindowFrameBound {
/// 1. UNBOUNDED PRECEDING
/// The frame boundary is the first row in the partition.
///
- /// 2. <expr> PRECEDING
- /// <expr> must be a non-negative constant numeric expression. The boundary is a row that
- /// is <expr> "units" prior to the current row.
+ /// 2. `<expr>` PRECEDING
+ /// `<expr>` must be a non-negative constant numeric expression. The boundary is a row that
+ /// is `<expr>` "units" prior to the current row.
Preceding(ScalarValue),
/// 3. The current row.
///
@@ -168,7 +168,7 @@ pub enum WindowFrameBound {
/// This is true regardless of whether CURRENT ROW is used as the starting or ending frame
/// boundary.
CurrentRow,
- /// 4. This is the same as "<expr> PRECEDING" except that the boundary is <expr> units after the
+ /// 4. This is the same as "`<expr>` PRECEDING" except that the boundary is `<expr>` units after the
/// current rather than before the current row.
///
/// 5. UNBOUNDED FOLLOWING
diff --git a/datafusion/sql/src/parser.rs b/datafusion/sql/src/parser.rs
index 4fbae50836..425135ee51 100644
--- a/datafusion/sql/src/parser.rs
+++ b/datafusion/sql/src/parser.rs
@@ -15,9 +15,7 @@
// specific language governing permissions and limitations
// under the License.
-//! SQL Parser
-//!
-//! Declares a SQL parser based on sqlparser that handles custom formats that we need.
+//! DataFusion SQL Parser based on [`sqlparser`]
use datafusion_common::parsers::CompressionTypeVariant;
use sqlparser::{
@@ -89,7 +87,7 @@ pub struct DescribeTable {
/// DataFusion Statement representations.
///
-/// Tokens parsed by `DFParser` are converted into these values.
+/// Tokens parsed by [`DFParser`] are converted into these values.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Statement {
/// ANSI SQL AST node
@@ -100,19 +98,24 @@ pub enum Statement {
DescribeTable(DescribeTable),
}
-/// SQL Parser
+/// DataFusion SQL Parser based on [`sqlparser`]
+///
+/// This parser handles DataFusion specific statements, delegating to
+/// [`Parser`](sqlparser::parser::Parser) for other SQL statements.
pub struct DFParser<'a> {
parser: Parser<'a>,
}
impl<'a> DFParser<'a> {
- /// Parse the specified tokens
+ /// Create a new parser for the specified tokens using the
+ /// [`GenericDialect`].
pub fn new(sql: &str) -> Result<Self, ParserError> {
let dialect = &GenericDialect {};
DFParser::new_with_dialect(sql, dialect)
}
- /// Parse the specified tokens with dialect
+ /// Create a new parser for the specified tokens with the
+ /// specified dialect.
pub fn new_with_dialect(
sql: &str,
dialect: &'a dyn Dialect,
@@ -125,13 +128,15 @@ impl<'a> DFParser<'a> {
})
}
- /// Parse a SQL statement and produce a set of statements with dialect
+ /// Parse a sql string into one or [`Statement`]s using the
+ /// [`GenericDialect`].
pub fn parse_sql(sql: &str) -> Result<VecDeque<Statement>, ParserError> {
let dialect = &GenericDialect {};
DFParser::parse_sql_with_dialect(sql, dialect)
}
- /// Parse a SQL statement and produce a set of statements
+ /// Parse a SQL string and produce one or more [`Statement`]s with
+ /// with the specified dialect.
pub fn parse_sql_with_dialect(
sql: &str,
dialect: &dyn Dialect,
@@ -159,7 +164,7 @@ impl<'a> DFParser<'a> {
Ok(stmts)
}
- /// Report unexpected token
+ /// Report an unexpected token
fn expected<T>(&self, expected: &str, found: Token) -> Result<T, ParserError> {
parser_err!(format!("Expected {}, found: {}", expected, found))
}
@@ -198,12 +203,13 @@ impl<'a> DFParser<'a> {
}
}
+ /// Parse a SQL `DESCRIBE` statement
pub fn parse_describe(&mut self) -> Result<Statement, ParserError> {
let table_name = self.parser.parse_object_name()?;
Ok(Statement::DescribeTable(DescribeTable { table_name }))
}
- /// Parse a SQL CREATE statement
+ /// Parse a SQL `CREATE` statementm handling `CREATE EXTERNAL TABLE`
pub fn parse_create(&mut self) -> Result<Statement, ParserError> {
if self.parser.parse_keyword(Keyword::EXTERNAL) {
self.parse_create_external_table()