Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Schema::fields and Schema::metadata pub (public) #2239

Merged
merged 2 commits into from
Jul 31, 2022
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions arrow/src/datatypes/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ use super::Field;
/// memory layout.
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct Schema {
pub(crate) fields: Vec<Field>,
pub fields: Vec<Field>,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the entire change -- make these two fields pub

/// A map of key-value pairs containing additional meta data.
#[serde(skip_serializing_if = "HashMap::is_empty")]
#[serde(default)]
pub(crate) metadata: HashMap<String, String>,
pub metadata: HashMap<String, String>,
}

impl Schema {
Expand Down
46 changes: 46 additions & 0 deletions arrow/tests/schema.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// 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.

use arrow::datatypes::{DataType, Field, Schema};
use std::collections::HashMap;
/// The tests in this file ensure a `Schema` can be manipulated
/// outside of the arrow crate

#[test]
fn schema_destructure() {
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Add a test outside the crate to use that

Do we need to move outside the tests of other public members to make sure they can be used outside the arrow crate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need to move outside the tests of other public members to make sure they can be used outside the arrow crate?

If we have such tests then yes I think they need to be outside the crate. In general, actually, moving some of the arrow testing into separate integration tests might be good for the compile/test/change cycle.

However, I don't think we should go overboard and try to write tests for all pub fields -- I felt this was in particular special (mostly because I don't want someone in the future to remove the pub thinking it won't affect anyone)

let meta = [("foo".to_string(), "baz".to_string())]
.into_iter()
.collect::<HashMap<String, String>>();

let field = Field::new("c1", DataType::Utf8, false);
let schema = Schema::new(vec![field]).with_metadata(meta);

// Destructuring a Schema allows rewriting fields and metadata
// without copying
//
// Model this usecase below:

let Schema {
mut fields,
metadata,
} = schema;
fields.push(Field::new("c2", DataType::Utf8, false));

let new_schema = Schema::new(fields).with_metadata(metadata);

assert_eq!(new_schema.fields().len(), 2);
}