Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions datafusion/core/tests/physical_optimizer/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use std::any::Any;
use std::fmt::Formatter;
use std::sync::Arc;
use std::sync::{Arc, LazyLock};

use arrow::array::Int32Array;
use arrow::compute::SortOptions;
Expand Down Expand Up @@ -142,37 +142,49 @@ pub(crate) fn parquet_exec_with_stats(file_size: u64) -> Arc<DataSourceExec> {
}

pub fn schema() -> SchemaRef {
Arc::new(Schema::new(vec![
Field::new("a", DataType::Int64, true),
Field::new("b", DataType::Int64, true),
Field::new("c", DataType::Int64, true),
Field::new("d", DataType::Int32, true),
Field::new("e", DataType::Boolean, true),
]))
static SCHEMA: LazyLock<SchemaRef> = LazyLock::new(|| {
Arc::new(Schema::new(vec![
Field::new("a", DataType::Int64, true),
Field::new("b", DataType::Int64, true),
Field::new("c", DataType::Int64, true),
Field::new("d", DataType::Int32, true),
Field::new("e", DataType::Boolean, true),
]))
});
Arc::clone(&SCHEMA)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now each call to schema() clones an Arc rather than actually recreating the schema

}

pub fn create_test_schema() -> Result<SchemaRef> {
let nullable_column = Field::new("nullable_col", DataType::Int32, true);
let non_nullable_column = Field::new("non_nullable_col", DataType::Int32, false);
let schema = Arc::new(Schema::new(vec![nullable_column, non_nullable_column]));
static SCHEMA: LazyLock<SchemaRef> = LazyLock::new(|| {
let nullable_column = Field::new("nullable_col", DataType::Int32, true);
let non_nullable_column = Field::new("non_nullable_col", DataType::Int32, false);
Arc::new(Schema::new(vec![nullable_column, non_nullable_column]))
});
let schema = Arc::clone(&SCHEMA);
Ok(schema)
}

pub fn create_test_schema2() -> Result<SchemaRef> {
let col_a = Field::new("col_a", DataType::Int32, true);
let col_b = Field::new("col_b", DataType::Int32, true);
let schema = Arc::new(Schema::new(vec![col_a, col_b]));
static SCHEMA: LazyLock<SchemaRef> = LazyLock::new(|| {
let col_a = Field::new("col_a", DataType::Int32, true);
let col_b = Field::new("col_b", DataType::Int32, true);
Arc::new(Schema::new(vec![col_a, col_b]))
});
let schema = Arc::clone(&SCHEMA);
Ok(schema)
}

// Generate a schema which consists of 5 columns (a, b, c, d, e)
pub fn create_test_schema3() -> Result<SchemaRef> {
let a = Field::new("a", DataType::Int32, true);
let b = Field::new("b", DataType::Int32, false);
let c = Field::new("c", DataType::Int32, true);
let d = Field::new("d", DataType::Int32, false);
let e = Field::new("e", DataType::Int32, false);
let schema = Arc::new(Schema::new(vec![a, b, c, d, e]));
static SCHEMA: LazyLock<SchemaRef> = LazyLock::new(|| {
let a = Field::new("a", DataType::Int32, true);
let b = Field::new("b", DataType::Int32, false);
let c = Field::new("c", DataType::Int32, true);
let d = Field::new("d", DataType::Int32, false);
let e = Field::new("e", DataType::Int32, false);
Arc::new(Schema::new(vec![a, b, c, d, e]))
});
let schema = Arc::clone(&SCHEMA);
Ok(schema)
}

Expand Down