-
Notifications
You must be signed in to change notification settings - Fork 682
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
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 |
||
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); | ||
} |
There was a problem hiding this comment.
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