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

feat: support IN list on Dictionary #3975

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion datafusion/common/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ impl std::hash::Hash for ScalarValue {
/// return a reference to the values array and the index into it for a
/// dictionary array
#[inline]
fn get_dict_value<K: ArrowDictionaryKeyType>(
pub fn get_dict_value<K: ArrowDictionaryKeyType>(
array: &ArrayRef,
index: usize,
) -> (&ArrayRef, Option<usize>) {
Expand Down
77 changes: 72 additions & 5 deletions datafusion/core/tests/sql/predicates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,10 +428,9 @@ async fn csv_in_set_test() -> Result<()> {
}

#[tokio::test]
#[ignore]
// https://github.com/apache/arrow-datafusion/issues/3936
async fn in_set_string_dictionaries() -> Result<()> {
let input = vec![Some("foo"), Some("bar"), None, Some("fazzz")]
async fn in_list_string_dictionaries() -> Result<()> {
// let input = vec![Some("foo"), Some("bar"), None, Some("fazzz")]
let input = vec![Some("foo"), Some("bar"), Some("fazzz")]
.into_iter()
.collect::<DictionaryArray<Int32Type>>();

Expand All @@ -440,7 +439,29 @@ async fn in_set_string_dictionaries() -> Result<()> {
let ctx = SessionContext::new();
ctx.register_batch("test", batch)?;

let sql = "SELECT * FROM test WHERE c1 IN ('foo', 'Bar', 'fazz')";
let sql = "SELECT * FROM test WHERE c1 IN ('Bar')";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec!["++", "++"];
assert_batches_eq!(expected, &actual);

let sql = "SELECT * FROM test WHERE c1 IN ('foo')";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec!["+-----+", "| c1 |", "+-----+", "| foo |", "+-----+"];
assert_batches_eq!(expected, &actual);

let sql = "SELECT * FROM test WHERE c1 IN ('bar', 'foo')";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+-----+", "| c1 |", "+-----+", "| foo |", "| bar |", "+-----+",
];
assert_batches_eq!(expected, &actual);

let sql = "SELECT * FROM test WHERE c1 IN ('Bar', 'foo')";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec!["+-----+", "| c1 |", "+-----+", "| foo |", "+-----+"];
assert_batches_eq!(expected, &actual);

let sql = "SELECT * FROM test WHERE c1 IN ('foo', 'Bar', 'fazzz')";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+-------+",
Expand All @@ -450,7 +471,53 @@ async fn in_set_string_dictionaries() -> Result<()> {
"| fazzz |",
"+-------+",
];
assert_batches_eq!(expected, &actual);
Ok(())
}

#[tokio::test]
async fn in_list_string_dictionaries_with_null() -> Result<()> {
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 test do not pass with method // 1

let input = vec![Some("foo"), Some("bar"), None, Some("fazzz")]
.into_iter()
.collect::<DictionaryArray<Int32Type>>();

let batch = RecordBatch::try_from_iter(vec![("c1", Arc::new(input) as _)]).unwrap();

let ctx = SessionContext::new();
ctx.register_batch("test", batch)?;

let sql = "SELECT * FROM test WHERE c1 IN ('Bar')";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec!["++", "++"];
assert_batches_eq!(expected, &actual);

let sql = "SELECT * FROM test WHERE c1 IN ('foo')";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec!["+-----+", "| c1 |", "+-----+", "| foo |", "+-----+"];
assert_batches_eq!(expected, &actual);

let sql = "SELECT * FROM test WHERE c1 IN ('bar', 'foo')";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+-----+", "| c1 |", "+-----+", "| foo |", "| bar |", "+-----+",
];
assert_batches_eq!(expected, &actual);

let sql = "SELECT * FROM test WHERE c1 IN ('Bar', 'foo')";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec!["+-----+", "| c1 |", "+-----+", "| foo |", "+-----+"];
assert_batches_eq!(expected, &actual);

let sql = "SELECT * FROM test WHERE c1 IN ('foo', 'Bar', 'fazzz')";
let actual = execute_to_batches(&ctx, sql).await;
let expected = vec![
"+-------+",
"| c1 |",
"+-------+",
"| foo |",
"| fazzz |",
"+-------+",
];
assert_batches_eq!(expected, &actual);
Ok(())
}
Expand Down