kosiew commented on code in PR #27348:
URL: https://github.com/apache/datafusion/pull/27348#discussion_r4768167888
##########
datafusion/proto/tests/cases/plans/sources.rs:
##########
@@ -61,6 +61,72 @@ use std::fmt::{Display, Formatter};
use std::sync::Arc;
use std::vec;
+#[test]
+fn parquet_decode_rejects_out_of_bounds_projection_bytes() {
+ // https://github.com/apache/datafusion/issues/27327: an empty schema with
+ // legacy projection [10] and no predicate must return an error, not panic.
+ let bytes = [0x0a, 0x06, 0x0a, 0x04, 0x12, 0x00, 0x20, 0x0a];
+ let ctx = SessionContext::new();
+ let err = datafusion_proto::bytes::physical_plan_from_bytes(&bytes,
&ctx.task_ctx())
+ .unwrap_err();
+ datafusion_common::assert_contains!(
+ err.to_string(),
+ "project index 10 out of bounds, max field 0"
+ );
+}
+
+#[test]
+fn parquet_decode_validates_legacy_projection() -> Result<()> {
+ let ctx = SessionContext::new();
+ let task_ctx = ctx.task_ctx();
+ let codec = DefaultPhysicalExtensionCodec {};
+ let schema = Arc::new(Schema::new(vec![Field::new("id", DataType::Int32,
false)]));
+
+ for with_predicate in [false, true] {
+ let mut source = ParquetSource::new(Arc::clone(&schema));
+ if with_predicate {
+ source = source.with_predicate(lit(true));
Review Comment:
Consider reusing the custom-predicate codec fixture with fields `[id,
label]` and projection `[1, 0]` to assert that the decoder receives `[label,
id]`. Decode success alone does not verify schema ordering.
##########
datafusion/datasource-parquet/src/source.rs:
##########
@@ -1264,12 +1264,9 @@ impl ParquetSource {
// must be decoded against the projected schema when a projection is
// present.
let predicate_schema = if !base_conf.projection.is_empty() {
- let projected_fields: Vec<_> = base_conf
- .projection
- .iter()
- .map(|&i| schema.field(i as usize).clone())
- .collect();
- Arc::new(Schema::new(projected_fields))
+ let projection: Vec<_> =
+ base_conf.projection.iter().map(|&i| i as usize).collect();
+ Arc::new(schema.project(&projection)?)
Review Comment:
Consider adding `ParquetScanExecNode.base_conf.projection` context to the
error while preserving the underlying Arrow error, so callers can identify
which projection field failed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]