sarutak commented on code in PR #60314:
URL: https://github.com/apache/spark/pull/60314#discussion_r4595579797


##########
sql/native/rust/src/export.rs:
##########
@@ -149,10 +149,7 @@ pub const fn library<S: Exported>() -> SparkDsLibrary {
         abort_data_writer: when!(write, abort_data_writer),
         close_data_writer: when!(write, close_data_writer),
         default_read_limit: when!(micro_batch_read, default_read_limit::<S>),
-        // SPARK-61200 added push_domains to version 1. The SDK does not 
expose it yet
-        // (SPARK-61306): without it, Spark pushes no filters down, and 
evaluates them after
-        // reading.
-        push_domains: None,
+        push_domains: when!(read, push_domains::<S>),

Review Comment:
   A design question: this installs `push_domains` for every source with batch 
reads, also for a builder that keeps the default. On the Spark side, 
`supportsDomainPushdown` only checks whether the function is in the table 
([NativeDataSource.scala#L108-L111](https://github.com/apache/spark/blob/36004905da9523bf8f60aea7bc118f720c123afd/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ffi/NativeDataSource.scala#L108-L111)),
 and `pushPredicates` relies on that to avoid creating a planner for a source 
that takes no domain 
([ColumnarTable.scala#L142-L144](https://github.com/apache/spark/blob/36004905da9523bf8f60aea7bc118f720c123afd/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/columnar/ColumnarTable.scala#L142-L144)):
 "Spark would create its reader while it optimizes the query, and derive 
domains only to drop them". With this PR, for every Rust source with batch 
reads, a batch scan whose filters give a domain now creates its source and 
reader (`
 create` and `create_reader`, so `DataSource::new` and `new_scan`) while Spark 
optimizes the query, rather than later in `toBatch`, and Spark exports the 
domains and the SDK converts them, even when the builder uses none of them. 
Results do not change, but the "behaves as before" in the description does not 
quite hold for when the builder is created.
   
   Would an opt-in constant fit here, defaulting to false like 
`BatchWrite::SUPPORTS_TRUNCATE`, and deciding whether the SDK installs the 
function as `DataSource::INFERS_SCHEMA` does for `schema`? For example `const 
PUSHES_DOMAINS: bool = false;` on `ScanBuilder` and `push_domains: when!(read 
&& <S::ScanBuilder as ScanBuilder>::PUSHES_DOMAINS, push_domains::<S>)`. The 
cost is that a builder that overrides `push_domains` without setting the 
constant is never called, so the docs of both would need to say so. It may be 
easier to decide this before the SDK is released: going from always installed 
to opt-in later would make a connector that already overrides `push_domains` 
compile as before but silently lose the pushdown. If you prefer to keep it as 
is, could you mention, in the user-facing section of the description, in the 
`ScanBuilder` docs and in the README (line 498, "so a connector can ignore the 
method"), that Spark now creates the reader of such a scan while it optimizes 
the query
 , also for a builder that uses no domain?



##########
sql/native/rust/src/abi.rs:
##########
@@ -766,6 +768,58 @@ pub unsafe fn messages<'a>(
         .collect()
 }
 
+/// A domain that Spark pushes: the path of its column, by the index of the 
column in the
+/// schema that create_reader got and then of its field in each struct, and 
its ranges.
+pub struct PushedDomain {
+    pub path: Vec<usize>,
+    pub null_allowed: bool,
+    pub nan_allowed: bool,
+    pub ranges: Option<StructArray>,
+}
+
+/// Reads the domains that Spark pushes, moving their ranges to take ownership 
of them.
+///
+/// # Safety
+/// The arguments must follow the push_domains contract of the C header.
+pub unsafe fn domains(
+    domains: *const *const SparkDsDomain,
+    count: i64,
+) -> Result<Vec<PushedDomain>> {
+    unsafe { slice(domains, count)? }
+        .iter()
+        .map(|&domain| {
+            let domain = unsafe { input(domain)? };
+            let path = unsafe { slice(domain.path, domain.path_length)? }
+                .iter()
+                .map(|&index| {
+                    usize::try_from(index)
+                        .map_err(|_| format!("the path of a domain has a 
negative index {index}"))
+                })
+                .collect::<std::result::Result<_, _>>()?;
+            let ranges = if domain.ranges.is_null() {
+                None
+            } else {
+                if domain.ranges_schema.is_null() {
+                    return Err("the ranges of a domain have no schema".into());
+                }

Review Comment:
   Nit: no test covers this check. Replacing the condition with `false` keeps 
all the tests passing, and without it `ArrowSchema::from_raw` would dereference 
a null pointer and crash the JVM. A case in 
`rejects_invalid_paths_and_a_wrong_number_of_results` with non-NULL `ranges` 
and NULL `ranges_schema` would pin the error.



##########
sql/native/rust/src/domain.rs:
##########
@@ -0,0 +1,571 @@
+// 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.
+
+//! The domains of the columns that the filters of a query constrain, which a 
scan gets in
+//! [`ScanBuilder::push_domains`](crate::ScanBuilder::push_domains).
+
+use std::ops::Bound;
+
+use arrow_array::cast::AsArray;
+use arrow_array::types::{
+    Date32Type, Decimal128Type, Float32Type, Float64Type, Int16Type, 
Int32Type, Int64Type,
+    Int8Type, TimestampMicrosecondType,
+};
+use arrow_array::{Array, ArrayRef, BooleanArray, StructArray};
+use arrow_schema::{DataType, Fields, TimeUnit};
+use serde::{Deserialize, Serialize};
+
+use crate::{abi, Result};
+
+/// The domain of a column: the values that the column can have in the rows 
that match the
+/// filters of a query. A value is in the domain when it is:
+///
+/// - null, if [`null_allowed`](Self::null_allowed);
+/// - NaN, if [`nan_allowed`](Self::nan_allowed), for a `float` or `double` 
column;
+/// - another value, if [`ranges`](Self::ranges) is `None`, or if it is in one 
of the ranges.
+///
+/// A scan can skip the data that has no value in the domain of a column, such 
as a file or a
+/// row group whose statistics show that its values are all below the ranges, 
or a row whose
+/// value is outside them. It must never skip a row whose values are all in 
their domains, since
+/// Spark cannot detect it. Spark evaluates the filters again after reading, 
so the rows that a
+/// scan returns need not match them.
+///
+/// Values compare in the order of Spark SQL:
+///
+/// - numbers, dates and timestamps by their values. The bounds of the ranges 
of a `float` or
+///   `double` column are never NaN, and -0.0 is equal to 0.0: compare them 
with `<` and `==`,
+///   not with a total order, such as [`f64::total_cmp`], that puts -0.0 
before 0.0. Data that
+///   has NaN values, or may have, can only be skipped if `nan_allowed` is 
false;
+/// - strings by their UTF-8 bytes, as Rust compares `str`;
+/// - binary values as unsigned bytes, in lexicographic order, as Rust 
compares `[u8]`;
+/// - booleans with false before true.
+///
+/// A domain is serializable, so that the factory of a scan can carry it to 
the executors.
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[non_exhaustive]
+pub struct Domain {
+    /// The column, by its name in 
[`ScanInfo::schema`](crate::ScanInfo::schema), and then by the
+    /// name of its field in each struct: `["point", "x"]` is the field `x` of 
the column
+    /// `point`.
+    pub path: Vec<String>,
+    /// Whether null is in the domain. A field of a struct is null in the rows 
where the struct,
+    /// or a struct that contains it, is null, whatever the child array of the 
field holds there:
+    /// Spark never allows null for a field of a struct, since statistics 
computed from that
+    /// child array may not count these rows as nulls.
+    pub null_allowed: bool,
+    /// Whether NaN is in the domain. Always false for the columns of other 
types than `float`
+    /// and `double`.
+    pub nan_allowed: bool,
+    /// The ranges of the other values in the domain, sorted, and without 
overlaps, or `None` if
+    /// they are all in it. With an empty list, no value other than null or 
NaN is in the domain.
+    pub ranges: Option<Vec<ValueRange>>,
+}
+
+impl Domain {
+    /// A domain without null or NaN, created outside Spark, for example in a 
test. Set
+    /// [`null_allowed`](Self::null_allowed) and 
[`nan_allowed`](Self::nan_allowed) for others.
+    pub fn new(path: Vec<String>, ranges: Option<Vec<ValueRange>>) -> Self {
+        Self {
+            path,
+            null_allowed: false,
+            nan_allowed: false,
+            ranges,
+        }
+    }
+
+    /// The domain that Spark passes for the column at the path of `pushed`, 
by the indices of the
+    /// column in `fields`, the schema that `create_reader` got, and then of 
its field in each
+    /// struct, or `None` if the SDK has no [`Value`] for the type of the 
column, which a later
+    /// version of Spark may pass.
+    pub(crate) fn from_abi(fields: &Fields, pushed: &abi::PushedDomain) -> 
Result<Option<Self>> {
+        let path = &pushed.path;
+        let invalid = || format!("the path {path:?} of a domain is not a 
column of the scan");
+        let (&last, parents) = path.split_last().ok_or_else(invalid)?;
+        let mut names = Vec::with_capacity(path.len());
+        let mut fields = fields;
+        for &index in parents {
+            let field = fields.get(index).ok_or_else(invalid)?;
+            let DataType::Struct(children) = field.data_type() else {
+                return Err(invalid().into());
+            };
+            names.push(field.name().clone());
+            fields = children;
+        }
+        let field = fields.get(last).ok_or_else(invalid)?;
+        if !has_value(field.data_type()) {
+            return Ok(None);
+        }
+        names.push(field.name().clone());
+        let ranges = match 
pushed.ranges.as_ref().map(value_ranges).transpose()? {
+            Some(None) => return Ok(None),
+            ranges => ranges.flatten(),
+        };

Review Comment:
   Nit: the header says `low` and `high` have the Arrow type of the column, but 
this does not check it. Since `has_value` already accepted the column type, 
`Some(None) => return Ok(None)` is only reached if Spark breaks that promise 
(no test reaches it either: turning it into `Some(None) => None` keeps all the 
tests passing). And a bound of another type that has a `Value`, e.g. 
`decimal(12, 4)` bounds for a `decimal(10, 2)` column, or `Utf8` bounds for an 
`Int64` column, gets through with a `Value` of the bounds' type, unlike the doc 
of `Value` ("It has the type of its column"). Comparing the data types of `low` 
and `high` with `field.data_type()`, and skipping or rejecting the domain when 
they differ, would make the doc hold, and the `Some(None)` arm would no longer 
be reachable.



##########
sql/native/rust/src/abi.rs:
##########
@@ -766,6 +768,58 @@ pub unsafe fn messages<'a>(
         .collect()
 }
 
+/// A domain that Spark pushes: the path of its column, by the index of the 
column in the
+/// schema that create_reader got and then of its field in each struct, and 
its ranges.
+pub struct PushedDomain {
+    pub path: Vec<usize>,
+    pub null_allowed: bool,
+    pub nan_allowed: bool,
+    pub ranges: Option<StructArray>,
+}
+
+/// Reads the domains that Spark pushes, moving their ranges to take ownership 
of them.
+///
+/// # Safety
+/// The arguments must follow the push_domains contract of the C header.
+pub unsafe fn domains(
+    domains: *const *const SparkDsDomain,
+    count: i64,
+) -> Result<Vec<PushedDomain>> {
+    unsafe { slice(domains, count)? }
+        .iter()
+        .map(|&domain| {
+            let domain = unsafe { input(domain)? };
+            let path = unsafe { slice(domain.path, domain.path_length)? }
+                .iter()
+                .map(|&index| {
+                    usize::try_from(index)
+                        .map_err(|_| format!("the path of a domain has a 
negative index {index}"))
+                })
+                .collect::<std::result::Result<_, _>>()?;
+            let ranges = if domain.ranges.is_null() {
+                None
+            } else {
+                if domain.ranges_schema.is_null() {
+                    return Err("the ranges of a domain have no schema".into());
+                }
+                let array = unsafe { ArrowArray::from_raw(domain.ranges) };
+                let schema = unsafe { 
ArrowSchema::from_raw(domain.ranges_schema) };
+                let ranges = make_array(unsafe { from_ffi(array, &schema)? });

Review Comment:
   Nit: the write path imports Spark's Arrow data with 
`from_ffi_and_data_type`, `align_buffers` and `validate` 
([write.rs#L254-L269](https://github.com/apache/spark/blob/36004905da9523bf8f60aea7bc118f720c123afd/sql/native/rust/src/write.rs#L254-L269)),
 since "the Arrow Java allocator of Spark does not promise" the 16-byte 
alignment of decimal buffers, while this uses `from_ffi` and `make_array` 
without either. I could not make it fail: with Arrow Java 19 and its netty 
allocator on macOS arm64, decimal buffers were 16-byte aligned at 9 sizes from 
1 to 20000 rows, and arrow-rs 58.4.0 imported ranges exported as 
`NativeArrow.exportDomains` does (decimals up to 4000 rows, and strings) 
through the C Data Interface. It would still be more consistent to import the 
ranges the same way, e.g. `align_buffers` on the `ArrayData` before 
`make_array` (and `validate_full`, for the same guarantees as the write path), 
since a misaligned decimal buffer would make `make_array` panic, and so the 
push a
 nd the query would fail.



##########
sql/native/rust/src/lib.rs:
##########
@@ -285,6 +288,24 @@ pub trait ScanBuilder: Send + Sized + 'static {
     #[doc(hidden)]
     const SUPPORTED: bool = true;
 
+    /// Pushes the domains of the columns that the filters of the query 
constrain down to the
+    /// scan, so that it can skip data: see [`Domain`]. Spark derives them 
from the filters that
+    /// compare a column with literals, with `=`, `<>`, `<=>`, `<`, `<=`, `>`, 
`>=`, `IN`,
+    /// `IS NULL`, `IS NOT NULL` and `STARTS_WITH`, combined with `AND`, `OR` 
and `NOT`, for the
+    /// columns and the fields of structs of the types that a [`Value`] holds, 
except strings with
+    /// a non-binary collation. It calls this only with at least one domain, 
and at most one for
+    /// each column. A domain has all the values that its column has in the 
rows for which the
+    /// filters are true, and may have others: a column that only one side of 
an `OR` constrains
+    /// gets no domain from it, and filters such as `id + 1 > 5` constrain no 
column. Spark
+    /// evaluates all the filters after reading anyway.
+    ///
+    /// Return whether the scan uses each domain, in order: Spark shows the 
filters of the used
+    /// domains as pushed in the formatted plan of the query (`EXPLAIN 
FORMATTED`). The default
+    /// uses none.

Review Comment:
   Nit: Spark shows a filter as pushed only when every column that it 
constrains has a used domain 
([ColumnDomains.scala#L119-L123](https://github.com/apache/spark/blob/36004905da9523bf8f60aea7bc118f720c123afd/sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/columnar/ColumnDomains.scala#L119-L123)),
 e.g. not `(a = 1 AND b = 2) OR (a = 3 AND b = 4)` when only the domain of `a` 
is used. Something like "Spark shows a filter as pushed when the domains of all 
the columns that it constrains are used" might be more precise. The header says 
the same of `used`, and also mentions the SQL tab of the Spark UI, which could 
be added here. The same sentence is in the README (lines 497-498).



##########
sql/native/rust/src/domain.rs:
##########
@@ -0,0 +1,571 @@
+// 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.
+
+//! The domains of the columns that the filters of a query constrain, which a 
scan gets in
+//! [`ScanBuilder::push_domains`](crate::ScanBuilder::push_domains).
+
+use std::ops::Bound;
+
+use arrow_array::cast::AsArray;
+use arrow_array::types::{
+    Date32Type, Decimal128Type, Float32Type, Float64Type, Int16Type, 
Int32Type, Int64Type,
+    Int8Type, TimestampMicrosecondType,
+};
+use arrow_array::{Array, ArrayRef, BooleanArray, StructArray};
+use arrow_schema::{DataType, Fields, TimeUnit};
+use serde::{Deserialize, Serialize};
+
+use crate::{abi, Result};
+
+/// The domain of a column: the values that the column can have in the rows 
that match the
+/// filters of a query. A value is in the domain when it is:
+///
+/// - null, if [`null_allowed`](Self::null_allowed);
+/// - NaN, if [`nan_allowed`](Self::nan_allowed), for a `float` or `double` 
column;
+/// - another value, if [`ranges`](Self::ranges) is `None`, or if it is in one 
of the ranges.
+///
+/// A scan can skip the data that has no value in the domain of a column, such 
as a file or a
+/// row group whose statistics show that its values are all below the ranges, 
or a row whose
+/// value is outside them. It must never skip a row whose values are all in 
their domains, since
+/// Spark cannot detect it. Spark evaluates the filters again after reading, 
so the rows that a
+/// scan returns need not match them.
+///
+/// Values compare in the order of Spark SQL:
+///
+/// - numbers, dates and timestamps by their values. The bounds of the ranges 
of a `float` or
+///   `double` column are never NaN, and -0.0 is equal to 0.0: compare them 
with `<` and `==`,
+///   not with a total order, such as [`f64::total_cmp`], that puts -0.0 
before 0.0. Data that
+///   has NaN values, or may have, can only be skipped if `nan_allowed` is 
false;
+/// - strings by their UTF-8 bytes, as Rust compares `str`;
+/// - binary values as unsigned bytes, in lexicographic order, as Rust 
compares `[u8]`;
+/// - booleans with false before true.
+///
+/// A domain is serializable, so that the factory of a scan can carry it to 
the executors.
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[non_exhaustive]
+pub struct Domain {
+    /// The column, by its name in 
[`ScanInfo::schema`](crate::ScanInfo::schema), and then by the
+    /// name of its field in each struct: `["point", "x"]` is the field `x` of 
the column
+    /// `point`.
+    pub path: Vec<String>,
+    /// Whether null is in the domain. A field of a struct is null in the rows 
where the struct,
+    /// or a struct that contains it, is null, whatever the child array of the 
field holds there:
+    /// Spark never allows null for a field of a struct, since statistics 
computed from that
+    /// child array may not count these rows as nulls.
+    pub null_allowed: bool,
+    /// Whether NaN is in the domain. Always false for the columns of other 
types than `float`
+    /// and `double`.
+    pub nan_allowed: bool,
+    /// The ranges of the other values in the domain, sorted, and without 
overlaps, or `None` if
+    /// they are all in it. With an empty list, no value other than null or 
NaN is in the domain.
+    pub ranges: Option<Vec<ValueRange>>,
+}
+
+impl Domain {
+    /// A domain without null or NaN, created outside Spark, for example in a 
test. Set
+    /// [`null_allowed`](Self::null_allowed) and 
[`nan_allowed`](Self::nan_allowed) for others.
+    pub fn new(path: Vec<String>, ranges: Option<Vec<ValueRange>>) -> Self {
+        Self {
+            path,
+            null_allowed: false,
+            nan_allowed: false,
+            ranges,
+        }
+    }
+
+    /// The domain that Spark passes for the column at the path of `pushed`, 
by the indices of the
+    /// column in `fields`, the schema that `create_reader` got, and then of 
its field in each
+    /// struct, or `None` if the SDK has no [`Value`] for the type of the 
column, which a later
+    /// version of Spark may pass.
+    pub(crate) fn from_abi(fields: &Fields, pushed: &abi::PushedDomain) -> 
Result<Option<Self>> {
+        let path = &pushed.path;
+        let invalid = || format!("the path {path:?} of a domain is not a 
column of the scan");
+        let (&last, parents) = path.split_last().ok_or_else(invalid)?;
+        let mut names = Vec::with_capacity(path.len());
+        let mut fields = fields;
+        for &index in parents {
+            let field = fields.get(index).ok_or_else(invalid)?;
+            let DataType::Struct(children) = field.data_type() else {
+                return Err(invalid().into());
+            };
+            names.push(field.name().clone());
+            fields = children;
+        }
+        let field = fields.get(last).ok_or_else(invalid)?;
+        if !has_value(field.data_type()) {
+            return Ok(None);
+        }
+        names.push(field.name().clone());
+        let ranges = match 
pushed.ranges.as_ref().map(value_ranges).transpose()? {
+            Some(None) => return Ok(None),
+            ranges => ranges.flatten(),
+        };
+        Ok(Some(Self {
+            path: names,
+            null_allowed: pushed.null_allowed,
+            nan_allowed: pushed.nan_allowed,
+            ranges,
+        }))
+    }
+}
+
+/// A range of the values of a [`Domain`]. A single value is a range whose 
bounds are equal and
+/// included.
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+pub struct ValueRange {
+    /// The lower bound, or [`Bound::Unbounded`] if the range has none.
+    pub low: Bound<Value>,
+    /// The upper bound, or [`Bound::Unbounded`] if the range has none.
+    pub high: Bound<Value>,
+}
+
+impl ValueRange {
+    /// The range of a single value.
+    pub fn single(value: Value) -> Self {
+        Self {
+            low: Bound::Included(value.clone()),
+            high: Bound::Included(value),
+        }
+    }
+}
+
+/// A value of a column, in the bounds of the ranges of a [`Domain`]. It has 
the type of its
+/// column in [`ScanInfo::schema`](crate::ScanInfo::schema). New variants may 
be added for the
+/// types that a later version of Spark passes domains for: a connector 
ignores the domains of
+/// values that it does not handle.
+#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
+#[non_exhaustive]
+pub enum Value {
+    Boolean(bool),
+    /// A `tinyint`, `smallint`, `int`, or `bigint`.
+    Integer(i64),
+    /// A `float` or `double`, which is never NaN: a `float` is the exact 
value of the float.
+    Float(f64),
+    /// A `decimal(precision, scale)` of the precision and scale of its 
column, whose value is
+    /// `unscaled * 10^-scale`.
+    Decimal {
+        #[serde(with = "decimal_string")]
+        unscaled: i128,
+        precision: u8,
+        scale: i8,
+    },
+    String(String),
+    Binary(Vec<u8>),
+    /// A `date`, as days since 1970-01-01.
+    Date(i32),
+    /// A `timestamp`, as microseconds since the epoch.
+    Timestamp(i64),
+    /// A `timestamp_ntz`, as microseconds since 1970-01-01 00:00:00, without 
a time zone.
+    TimestampNtz(i64),
+}
+
+/// Encodes the unscaled value of a decimal as its decimal string. serde 
buffers the values of
+/// `flatten` fields and of `untagged` and internally tagged enums before 
decoding them, and its
+/// buffer has no 128-bit integers, so it could not decode an `i128` in a 
factory that uses them.
+mod decimal_string {
+    use serde::de::Error;
+    use serde::{Deserialize, Deserializer, Serializer};
+
+    pub fn serialize<S: Serializer>(unscaled: &i128, serializer: S) -> 
Result<S::Ok, S::Error> {
+        serializer.collect_str(unscaled)
+    }
+
+    pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> 
Result<i128, D::Error> {
+        String::deserialize(deserializer)?
+            .parse()
+            .map_err(D::Error::custom)
+    }
+}
+
+/// Whether the SDK has a [`Value`] for the values of a column of `data_type`: 
the types that
+/// [`values`] converts.
+fn has_value(data_type: &DataType) -> bool {
+    matches!(
+        data_type,
+        DataType::Boolean
+            | DataType::Int8
+            | DataType::Int16
+            | DataType::Int32
+            | DataType::Int64
+            | DataType::Float32
+            | DataType::Float64
+            | DataType::Decimal128(..)
+            | DataType::Utf8
+            | DataType::Binary
+            | DataType::Date32
+            | DataType::Timestamp(TimeUnit::Microsecond, _)
+    )
+}

Review Comment:
   Nit: `has_value` keeps its own copy of the types that `values` converts, and 
the tests only pin part of it. I removed one type at a time from `has_value` 
and ran `cargo test --workspace --locked`: removing `Boolean`, `Int8`, `Int16`, 
`Float32`, `Decimal128(..)`, `Binary`, `Date32` or 
`Timestamp(TimeUnit::Microsecond, _)` keeps all the tests passing, and the 
domains of such columns would then be dropped silently (results stay correct, 
only the skipping is lost). Only `Int32`, `Int64`, `Float64` and `Utf8` are 
caught. Either deriving it from `values`, e.g. 
`values(&arrow_array::new_empty_array(data_type)).is_some()`, or running each 
case of `converts_the_values_of_each_type_of_version_1` through 
`Domain::from_abi` with a column of that type, would close this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to