Code Monkey home page Code Monkey logo

Comments (3)

devinjdangelo avatar devinjdangelo commented on August 16, 2024 1

Thank you for the report @samuelcolvin. I will look into this and try to make a self contained reproducer. This panic should not be possible. I suspect there could be a bug in how dictionary encoded arrays are handled in the relevant code, since that could cause this panic but I have yet to confirm.

from arrow-datafusion.

devinjdangelo avatar devinjdangelo commented on August 16, 2024

I was unable to reproduce this panic on main or v38. @samuelcolvin if you are able to provide more details about the parquet files which are triggering the issue (schema, sanitized values, directory structure) that may help reproduce.

Here is what I tried to reproduce:

datafusion-cli
DataFusion CLI v38.0.0
> COPY (values ('1', 'a', 'x'), ('2', 'b', 'y'), ('3', 'c', 'z')) TO 'test_files/scratch/copy/partitioned_table3/' STORED AS parquet PARTITIONED BY (column1, column3)
;
+-------+
| count |
+-------+
| 3     |
+-------+
1 row(s) fetched. 
Elapsed 0.003 seconds.

> CREATE EXTERNAL TABLE validate_partitioned_parquet3 STORED AS PARQUET 
LOCATION 'test_files/scratch/copy/partitioned_table3/' PARTITIONED BY (column1, column3);
0 row(s) fetched. 
Elapsed 0.001 seconds.

> COPY validate_partitioned_parquet3
TO 'test_files/scratch/copy/partitioned_table3_rewrite'
PARTITIONED BY (column1, column3)
STORED AS PARQUET;
+-------+
| count |
+-------+
| 3     |
+-------+
1 row(s) fetched. 
Elapsed 0.003 seconds.

And trying to force dictionary encoding where possible also runs without panic

DataFusion CLI v38.0.0
> COPY (values 
('c', arrow_cast('foo', 'Dictionary(Int32, Utf8)'), arrow_cast('foo2', 'Dictionary(Int32, Utf8)')), 
('d', arrow_cast('bar', 'Dictionary(Int32, Utf8)'), arrow_cast('bar2', 'Dictionary(Int32, Utf8)'))) 
to 'test_files/scratch/copy/part_dict_test' STORED AS PARQUET PARTITIONED BY (column2, column3);
+-------+
| count |
+-------+
| 2     |
+-------+
1 row(s) fetched. 
Elapsed 0.004 seconds.

> CREATE EXTERNAL TABLE dict_partitioned_test STORED AS PARQUET 
LOCATION 'test_files/scratch/copy/part_dict_test/' PARTITIONED BY (column2, column3);
0 row(s) fetched. 
Elapsed 0.001 seconds.

> select * from dict_partitioned_test;
+---------+---------+---------+
| column1 | column2 | column3 |
+---------+---------+---------+
| d       | bar     | bar2    |
| c       | foo     | foo2    |
+---------+---------+---------+
2 row(s) fetched. 
Elapsed 0.002 seconds.

> COPY (select column1, arrow_cast(column2, 'Dictionary(Int32, Utf8)') as column2, 
arrow_cast(column3, 'Dictionary(Int32, Utf8)') as column3 from dict_partitioned_test)
TO 'test_files/scratch/copy/part_dict_test_rewrite'
PARTITIONED BY (column2, column3)
STORED AS PARQUET;
+-------+
| count |
+-------+
| 2     |
+-------+
1 row(s) fetched. 
Elapsed 0.003 seconds.

The line that is panicking with index OOB would only happen if one of the partition arrays in the RecordBatch was extracted with fewer values than RecordBatch::num_rows().

For plain Utf8 arrays, this seems completely impossible given this code executes first (array.value(i) would panic first):

for i in 0..rb.num_rows() {
partition_values.push(array.value(i));
}

For dictionary encoded arrays, I could imagine something in the downcast / iteration code here producing fewer values. I thought that the iteration over the downcasted array should always produce exactly RecordBatch::num_rows() values, but perhaps there is a case where this is wrong.

let array = col_array.downcast_dict::<StringArray>()
.ok_or(exec_datafusion_err!("it is not yet supported to write to hive partitions with datatype {}",
dtype))?;
for val in array.values() {
partition_values.push(
val.ok_or(exec_datafusion_err!("Cannot partition by null value for column {}", col))?
);

Finally, the arrays constructed above are accessed like this:

for i in 0..rb.num_rows() {
let mut part_key = vec![];
for vals in all_partition_values.iter() {
part_key.push(vals[i].to_owned());
}
let builder = take_map.entry(part_key).or_insert(UInt64Builder::new());
builder.append_value(i as u64);
}

from arrow-datafusion.

alamb avatar alamb commented on August 16, 2024

Has this been fixed @samuelcolvin ?

from arrow-datafusion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.