From b4d89c4aaf9525f4fce4ff810e08ed217fd9f2c9 Mon Sep 17 00:00:00 2001 From: Vadim Piven Date: Tue, 11 Mar 2025 15:06:16 +0100 Subject: [PATCH] Fix broken `serde` feature (#15124) * Fix broked `serde` feature * Test `serde` feature * consolidate serde test into core_integration, update run --------- Co-authored-by: Andrew Lamb --- .github/workflows/rust.yml | 2 +- Cargo.lock | 1 + datafusion/core/Cargo.toml | 7 ++++- datafusion/core/tests/core_integration.rs | 5 ++++ datafusion/core/tests/serde/mod.rs | 34 +++++++++++++++++++++++ 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 datafusion/core/tests/serde/mod.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 99aaa7d6f2907..f9a8a456fbc7a 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -183,7 +183,7 @@ jobs: with: rust-version: stable - name: Run tests (excluding doctests) - run: cargo test --profile ci --exclude datafusion-examples --exclude ffi_example_table_provider --exclude datafusion-benchmarks --workspace --lib --tests --bins --features avro,json,backtrace,integration-tests + run: cargo test --profile ci --exclude datafusion-examples --exclude ffi_example_table_provider --exclude datafusion-benchmarks --workspace --lib --tests --bins --features serde,avro,json,backtrace,integration-tests - name: Verify Working Directory Clean run: git diff --exit-code diff --git a/Cargo.lock b/Cargo.lock index 8eaaad283b3bc..ba4a8b6200e5c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -453,6 +453,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85934a9d0261e0fa5d4e2a5295107d743b543a6e0484a835d4b8db2da15306f9" dependencies = [ "bitflags 2.8.0", + "serde", ] [[package]] diff --git a/datafusion/core/Cargo.toml b/datafusion/core/Cargo.toml index 438e2600a66d7..27e261739357b 100644 --- a/datafusion/core/Cargo.toml +++ b/datafusion/core/Cargo.toml @@ -73,7 +73,12 @@ recursive_protection = [ "datafusion-physical-optimizer/recursive_protection", "datafusion-sql/recursive_protection", ] -serde = ["dep:serde"] +serde = [ + "dep:serde", + # Enable `#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]` + # statements in `arrow-schema` crate + "arrow-schema/serde", +] string_expressions = ["datafusion-functions/string_expressions"] unicode_expressions = [ "datafusion-sql/unicode_expressions", diff --git a/datafusion/core/tests/core_integration.rs b/datafusion/core/tests/core_integration.rs index 66b4103160e7b..9bcb9e41f86a9 100644 --- a/datafusion/core/tests/core_integration.rs +++ b/datafusion/core/tests/core_integration.rs @@ -42,8 +42,13 @@ mod custom_sources_cases; /// Run all tests that are found in the `optimizer` directory mod optimizer; +/// Run all tests that are found in the `physical_optimizer` directory mod physical_optimizer; +/// Run all tests that are found in the `serde` directory +mod serde; + +/// Run all tests that are found in the `catalog` directory mod catalog; #[cfg(test)] diff --git a/datafusion/core/tests/serde/mod.rs b/datafusion/core/tests/serde/mod.rs new file mode 100644 index 0000000000000..05dde7a541867 --- /dev/null +++ b/datafusion/core/tests/serde/mod.rs @@ -0,0 +1,34 @@ +// 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. + +/// Ensure `serde` feature from `arrow-schema` crate is re-exported. +#[test] +#[cfg(feature = "serde")] +fn ensure_serde_support() { + use datafusion::arrow::datatypes::DataType; + + #[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize)] + struct WrappingStruct(DataType); + + let boolean = WrappingStruct(DataType::Boolean); + + let serialized = serde_json::to_string(&boolean).unwrap(); + assert_eq!("\"Boolean\"", serialized); + + let deserialized = serde_json::from_str(&serialized).unwrap(); + assert_eq!(boolean, deserialized); +}