-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
SELECT * FROM table WHERE <condition0> OR <condition1> OR ... succeeds with 50 conditions but overflows stack with 100 conditions.
To Reproduce
Adding this test to arrow-datafusion/datafusion/tests/sql.rs demonstrates the issue:
#[tokio::test]
async fn query_with_many_conditions() -> Result<()> {
let schema = Arc::new(Schema::new(vec![Field::new("c1", DataType::Utf8, true)]));
let data = RecordBatch::try_new(
schema.clone(),
vec![Arc::new(StringArray::from(vec!["foo", "bar"]))],
)
.unwrap();
let table = MemTable::try_new(schema, vec![vec![data]])?;
let mut ctx = ExecutionContext::new();
ctx.register_table("test", Arc::new(table)).unwrap();
let num_conditions = 50;
println!("attempted a query with {:?} conditions...", num_conditions);
let where_clause = (0..num_conditions)
.map(|i| format!("c1 = 'value{:?}'", i))
.collect::<Vec<String>>()
.join(" OR ");
let sql = format!("SELECT * from test where {};", where_clause);
execute_to_batches(&mut ctx, &sql).await;
println!("query succeeded with {:?} conditions", num_conditions);
let num_conditions = 100;
println!("attempted a query with {:?} conditions...", num_conditions);
let where_clause = (0..num_conditions)
.map(|i| format!("c1 = 'value{:?}'", i))
.collect::<Vec<String>>()
.join(" OR ");
let sql = format!("SELECT * from test where {};", where_clause);
execute_to_batches(&mut ctx, &sql).await;
println!("query succeeded with {:?} conditions", num_conditions);
Ok(())
}
Output:
running 1 test
attempted a query with 50 conditions...
query succeeded with 50 conditions
attempted a query with 100 conditions...
thread 'query_with_many_conditions' has overflowed its stack
fatal runtime error: stack overflow
error: test failed, to rerun pass '--test sql'
Expected behavior
Expected query to succeed.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working