Skip to content

Commit d96eab3

Browse files
committed
refactor: move schema code to kernel module
Signed-off-by: Robert Pack <[email protected]>
1 parent d16f10c commit d96eab3

File tree

18 files changed

+37
-31
lines changed

18 files changed

+37
-31
lines changed

crates/core/src/delta_datafusion/schema_adapter.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::Debug;
22
use std::sync::Arc;
33

4-
use crate::operations::cast::cast_record_batch;
4+
use crate::kernel::schema::cast_record_batch;
55
use arrow_array::RecordBatch;
66
use arrow_schema::{Schema, SchemaRef};
77
use datafusion::common::{not_impl_err, ColumnStatistics};

crates/core/src/kernel/mod.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,20 @@
33
//! The Kernel module contains all the logic for reading and processing the Delta Lake transaction log.
44
55
use delta_kernel::engine::arrow_expression::ArrowEvaluationHandler;
6-
use std::{any::Any, sync::LazyLock};
6+
use std::sync::LazyLock;
77

88
pub mod arrow;
99
pub mod error;
1010
pub mod models;
1111
pub mod scalars;
12+
pub mod schema;
1213
mod snapshot;
1314
pub mod transaction;
1415

1516
pub use error::*;
1617
pub use models::*;
18+
pub use schema::*;
1719
pub use snapshot::*;
1820

19-
/// A trait for all kernel types that are used as part of data checking
20-
pub trait DataCheck {
21-
/// The name of the specific check
22-
fn get_name(&self) -> &str;
23-
/// The SQL expression to use for the check
24-
fn get_expression(&self) -> &str;
25-
26-
fn as_any(&self) -> &dyn Any;
27-
}
28-
2921
static ARROW_HANDLER: LazyLock<ArrowEvaluationHandler> =
3022
LazyLock::new(|| ArrowEvaluationHandler {});

crates/core/src/kernel/models/actions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ use maplit::hashset;
88
use serde::{Deserialize, Serialize};
99
use tracing::warn;
1010

11-
use super::schema::StructType;
12-
use super::StructTypeExt;
1311
use crate::kernel::{error::Error, DeltaResult};
12+
use crate::kernel::{StructType, StructTypeExt};
1413
use crate::TableProperty;
1514

1615
/// Defines a file format used in table

crates/core/src/kernel/models/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ use serde::{Deserialize, Serialize};
99

1010
pub(crate) mod actions;
1111
pub(crate) mod fields;
12-
mod schema;
1312

1413
pub use actions::*;
15-
pub use schema::*;
1614

1715
#[derive(Debug, Hash, PartialEq, Eq, Clone, Serialize, Deserialize)]
1816
/// The type of action that was performed on the table

crates/core/src/operations/cast/mod.rs renamed to crates/core/src/kernel/schema/cast/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ use arrow_cast::{cast_with_options, CastOptions};
99
use arrow_schema::{ArrowError, DataType, FieldRef, Fields, SchemaRef as ArrowSchemaRef};
1010
use std::sync::Arc;
1111

12-
pub(crate) mod merge_schema;
12+
mod merge_schema;
13+
pub(crate) use merge_schema::*;
1314

1415
use crate::DeltaResult;
1516

@@ -203,7 +204,6 @@ mod tests {
203204
use std::ops::Deref;
204205
use std::sync::Arc;
205206

206-
use super::merge_schema::{merge_arrow_schema, merge_delta_struct};
207207
use arrow::array::types::Int32Type;
208208
use arrow::array::{
209209
new_empty_array, new_null_array, Array, ArrayData, ArrayRef, AsArray, Int32Array,
@@ -215,11 +215,12 @@ mod tests {
215215
use delta_kernel::schema::MetadataValue;
216216
use itertools::Itertools;
217217

218+
use super::merge_schema::{merge_arrow_schema, merge_delta_struct};
219+
use super::{cast_record_batch, is_cast_required};
218220
use crate::kernel::{
219221
ArrayType as DeltaArrayType, DataType as DeltaDataType, StructField as DeltaStructField,
220222
StructType as DeltaStructType,
221223
};
222-
use crate::operations::cast::{cast_record_batch, is_cast_required};
223224

224225
#[test]
225226
fn test_merge_arrow_schema_with_dict() {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use std::any::Any;
2+
3+
pub mod cast;
4+
pub mod partitions;
5+
mod schema;
6+
7+
pub use cast::*;
8+
pub use schema::*;
9+
10+
/// A trait for all kernel types that are used as part of data checking
11+
pub trait DataCheck {
12+
/// The name of the specific check
13+
fn get_name(&self) -> &str;
14+
/// The SQL expression to use for the check
15+
fn get_expression(&self) -> &str;
16+
17+
fn as_any(&self) -> &dyn Any;
18+
}

crates/core/src/schema/partitions.rs renamed to crates/core/src/kernel/schema/partitions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ use std::convert::TryFrom;
66
use delta_kernel::expressions::Scalar;
77
use serde::{Serialize, Serializer};
88

9+
use super::{DataType, PrimitiveType};
910
use crate::errors::DeltaTableError;
10-
use crate::kernel::{scalars::ScalarExt, DataType, PrimitiveType};
11+
use crate::kernel::scalars::ScalarExt;
1112

1213
/// A special value used in Hive to represent the null partition in partitioned tables
1314
pub const NULL_PARTITION_VALUE_DATA_PATH: &str = "__HIVE_DEFAULT_PARTITION__";

crates/core/src/kernel/models/schema.rs renamed to crates/core/src/kernel/schema/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub use delta_kernel::schema::{
1010
use serde_json::Value;
1111

1212
use crate::kernel::error::Error;
13-
use crate::kernel::DataCheck;
13+
use crate::schema::DataCheck;
1414
use crate::table::GeneratedColumn;
1515

1616
/// Type alias for a top level schema

crates/core/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub mod kernel;
7575
pub mod logstore;
7676
pub mod operations;
7777
pub mod protocol;
78-
pub mod schema;
78+
pub use kernel::schema;
7979
pub mod table;
8080

8181
#[cfg(any(test, feature = "integration_test"))]

0 commit comments

Comments
 (0)