-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Fix bug in field level metadata matching code #8286
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ use datafusion::{ | |
}; | ||
use datafusion_common::DataFusionError; | ||
use log::info; | ||
use std::collections::HashMap; | ||
use std::fs::File; | ||
use std::io::Write; | ||
use std::path::Path; | ||
|
@@ -57,8 +58,8 @@ impl TestContext { | |
} | ||
} | ||
|
||
/// Create a SessionContext, configured for the specific test, if | ||
/// possible. | ||
/// Create a SessionContext, configured for the specific sqllogictest | ||
/// test(.slt file) , if possible. | ||
/// | ||
/// If `None` is returned (e.g. because some needed feature is not | ||
/// enabled), the file should be skipped | ||
|
@@ -67,7 +68,7 @@ impl TestContext { | |
// hardcode target partitions so plans are deterministic | ||
.with_target_partitions(4); | ||
|
||
let test_ctx = TestContext::new(SessionContext::new_with_config(config)); | ||
let mut test_ctx = TestContext::new(SessionContext::new_with_config(config)); | ||
|
||
let file_name = relative_path.file_name().unwrap().to_str().unwrap(); | ||
match file_name { | ||
|
@@ -86,10 +87,8 @@ impl TestContext { | |
"avro.slt" => { | ||
#[cfg(feature = "avro")] | ||
{ | ||
let mut test_ctx = test_ctx; | ||
info!("Registering avro tables"); | ||
register_avro_tables(&mut test_ctx).await; | ||
return Some(test_ctx); | ||
} | ||
#[cfg(not(feature = "avro"))] | ||
{ | ||
|
@@ -99,10 +98,11 @@ impl TestContext { | |
} | ||
"joins.slt" => { | ||
info!("Registering partition table tables"); | ||
|
||
let mut test_ctx = test_ctx; | ||
register_partition_table(&mut test_ctx).await; | ||
return Some(test_ctx); | ||
} | ||
"metadata.slt" => { | ||
info!("Registering metadata table tables"); | ||
register_metadata_tables(test_ctx.session_ctx()).await; | ||
} | ||
_ => { | ||
info!("Using default SessionContext"); | ||
|
@@ -299,3 +299,31 @@ fn table_with_many_types() -> Arc<dyn TableProvider> { | |
let provider = MemTable::try_new(Arc::new(schema), vec![vec![batch]]).unwrap(); | ||
Arc::new(provider) | ||
} | ||
|
||
/// Registers a table_with_metadata that contains both field level and Table level metadata | ||
pub async fn register_metadata_tables(ctx: &SessionContext) { | ||
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. I intend to port several existing metadata tests to sqllogictest as well |
||
let id = Field::new("id", DataType::Int32, true).with_metadata(HashMap::from([( | ||
String::from("metadata_key"), | ||
String::from("the id field"), | ||
)])); | ||
let name = Field::new("name", DataType::Utf8, true).with_metadata(HashMap::from([( | ||
String::from("metadata_key"), | ||
String::from("the name field"), | ||
)])); | ||
|
||
let schema = Schema::new(vec![id, name]).with_metadata(HashMap::from([( | ||
String::from("metadata_key"), | ||
String::from("the entire schema"), | ||
)])); | ||
|
||
let batch = RecordBatch::try_new( | ||
Arc::new(schema), | ||
vec![ | ||
Arc::new(Int32Array::from(vec![Some(1), None, Some(3)])) as _, | ||
Arc::new(StringArray::from(vec![None, Some("bar"), Some("baz")])) as _, | ||
], | ||
) | ||
.unwrap(); | ||
|
||
ctx.register_batch("table_with_metadata", batch).unwrap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# 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. | ||
|
||
########## | ||
## Tests for tables that has both metadata on each field as well as metadata on | ||
## the schema itself. | ||
########## | ||
|
||
## Note that table_with_metadata is defined using Rust code | ||
## in the test harness as there is no way to define schema | ||
## with metadata in SQL. | ||
|
||
query IT | ||
select * from table_with_metadata; | ||
---- | ||
1 NULL | ||
NULL bar | ||
3 baz | ||
|
||
query I rowsort | ||
SELECT ( | ||
SELECT id FROM table_with_metadata | ||
) UNION ( | ||
SELECT id FROM table_with_metadata | ||
); | ||
---- | ||
1 | ||
3 | ||
NULL | ||
|
||
query I rowsort | ||
SELECT "data"."id" | ||
FROM | ||
( | ||
(SELECT "id" FROM "table_with_metadata") | ||
UNION | ||
(SELECT "id" FROM "table_with_metadata") | ||
) as "data", | ||
( | ||
SELECT "id" FROM "table_with_metadata" | ||
) as "samples" | ||
WHERE "data"."id" = "samples"."id"; | ||
---- | ||
1 | ||
3 | ||
|
||
statement ok | ||
drop table table_with_metadata; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 fix -- look up metadata by column index rather than name