Skip to content
This repository was archived by the owner on Jan 7, 2025. It is now read-only.

Commit 228e7ba

Browse files
jurplelskyzh
andauthored
Fix for TPC-H Q11 (#254)
Test failed with `test panicked: Column index 2 out of bounds 2 + 0` The 0 schema len was due to this part of the plan: ``` └── LogicalProjection ├── exprs:Cast │ ├── cast_to: Decimal128(38, 15) │ ├── child:Mul │ │ ├── Cast { cast_to: Float64, child: #0 } │ │ └── 0.0001(float) ``` Turns out, `BinOp` was being considered to have an empty schema length. Let me know if this fix does not take into account some case. --------- Signed-off-by: Alex Chi <[email protected]> Co-authored-by: Alex Chi <[email protected]>
1 parent 3c81da9 commit 228e7ba

File tree

4 files changed

+51
-47
lines changed

4 files changed

+51
-47
lines changed

optd-datafusion-repr/src/properties/schema.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,19 @@ impl SchemaPropertyBuilder {
117117
Schema { fields }
118118
}
119119
DfPredType::LogOp(_) => Schema {
120-
fields: vec![Field::placeholder(); children.len()],
120+
fields: vec![Field {
121+
typ: ConstantType::Bool,
122+
..Field::placeholder()
123+
}],
124+
},
125+
DfPredType::BinOp(_) => Schema {
126+
fields: vec![Field::placeholder()],
121127
},
122-
123128
DfPredType::Cast => Schema {
124-
fields: children[0]
125-
.fields
126-
.iter()
127-
.map(|field| Field {
128-
typ: children[1].fields[0].typ,
129-
..field.clone()
130-
})
131-
.collect(),
129+
fields: vec![Field {
130+
typ: children[1].fields[0].typ,
131+
..children[0].fields[0].clone()
132+
}],
132133
},
133134
DfPredType::DataType(data_type) => Schema {
134135
fields: vec![Field {
@@ -144,7 +145,9 @@ impl SchemaPropertyBuilder {
144145
// The real type should be the column type.
145146
fields: vec![Field::placeholder()],
146147
},
147-
_ => Schema { fields: vec![] },
148+
_ => Schema {
149+
fields: vec![Field::placeholder()], // all predicates produce at least one column
150+
},
148151
}
149152
}
150153
}

optd-sqlplannertest/tests/tpch/tpch-11-15.planner.sql

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -195,45 +195,46 @@ LogicalSort
195195
PhysicalSort
196196
├── exprs:SortOrder { order: Desc }
197197
│ └── #1
198-
└── PhysicalNestedLoopJoin
199-
├── join_type: Inner
200-
├── cond:Gt
201-
│ ├── Cast { cast_to: Decimal128(38, 15), child: #1 }
202-
│ └── #0
203-
├── PhysicalAgg
204-
│ ├── aggrs:Agg(Sum)
205-
│ │ └── Mul
206-
│ │ ├── #2
207-
│ │ └── Cast { cast_to: Decimal128(10, 0), child: #1 }
208-
│ ├── groups: [ #0 ]
209-
│ └── PhysicalProjection { exprs: [ #11, #13, #14 ] }
210-
│ └── PhysicalHashJoin { join_type: Inner, left_keys: [ #4 ], right_keys: [ #1 ] }
211-
│ ├── PhysicalHashJoin { join_type: Inner, left_keys: [ #0 ], right_keys: [ #3 ] }
212-
│ │ ├── PhysicalFilter
213-
│ │ │ ├── cond:Eq
214-
│ │ │ │ ├── #1
215-
│ │ │ │ └── "CHINA"
216-
│ │ │ └── PhysicalScan { table: nation }
217-
│ │ └── PhysicalScan { table: supplier }
218-
│ └── PhysicalScan { table: partsupp }
219-
└── PhysicalProjection
220-
├── exprs:Cast
221-
│ ├── cast_to: Decimal128(38, 15)
222-
│ ├── child:Mul
223-
│ │ ├── Cast { cast_to: Float64, child: #0 }
224-
│ │ └── 0.0001(float)
198+
└── PhysicalProjection { exprs: [ #1, #2 ] }
199+
└── PhysicalNestedLoopJoin
200+
├── join_type: Inner
201+
├── cond:Gt
202+
│ ├── Cast { cast_to: Decimal128(38, 15), child: #2 }
203+
│ └── #0
204+
├── PhysicalProjection
205+
│ ├── exprs:Cast
206+
│ │ ├── cast_to: Decimal128(38, 15)
207+
│ │ ├── child:Mul
208+
│ │ │ ├── Cast { cast_to: Float64, child: #0 }
209+
│ │ │ └── 0.0001(float)
225210
211+
│ └── PhysicalAgg
212+
│ ├── aggrs:Agg(Sum)
213+
│ │ └── Mul
214+
│ │ ├── #1
215+
│ │ └── Cast { cast_to: Decimal128(10, 0), child: #0 }
216+
│ ├── groups: []
217+
│ └── PhysicalProjection { exprs: [ #13, #14 ] }
218+
│ └── PhysicalHashJoin { join_type: Inner, left_keys: [ #4 ], right_keys: [ #1 ] }
219+
│ ├── PhysicalHashJoin { join_type: Inner, left_keys: [ #0 ], right_keys: [ #3 ] }
220+
│ │ ├── PhysicalFilter
221+
│ │ │ ├── cond:Eq
222+
│ │ │ │ ├── #1
223+
│ │ │ │ └── "CHINA"
224+
│ │ │ └── PhysicalScan { table: nation }
225+
│ │ └── PhysicalScan { table: supplier }
226+
│ └── PhysicalScan { table: partsupp }
226227
└── PhysicalAgg
227228
├── aggrs:Agg(Sum)
228229
│ └── Mul
229-
│ ├── #1
230-
│ └── Cast { cast_to: Decimal128(10, 0), child: #0 }
231-
├── groups: []
232-
└── PhysicalProjection { exprs: [ #0, #1 ] }
233-
└── PhysicalHashJoin { join_type: Inner, left_keys: [ #2 ], right_keys: [ #0 ] }
234-
├── PhysicalProjection { exprs: [ #1, #2, #4 ] }
235-
│ └── PhysicalHashJoin { join_type: Inner, left_keys: [ #0 ], right_keys: [ #0 ] }
236-
│ ├── PhysicalProjection { exprs: [ #1, #2, #3 ] }
230+
│ ├── #2
231+
│ └── Cast { cast_to: Decimal128(10, 0), child: #1 }
232+
├── groups: [ #0 ]
233+
└── PhysicalProjection { exprs: [ #0, #1, #2 ] }
234+
└── PhysicalHashJoin { join_type: Inner, left_keys: [ #3 ], right_keys: [ #0 ] }
235+
├── PhysicalProjection { exprs: [ #0, #2, #3, #5 ] }
236+
│ └── PhysicalHashJoin { join_type: Inner, left_keys: [ #1 ], right_keys: [ #0 ] }
237+
│ ├── PhysicalProjection { exprs: [ #0, #1, #2, #3 ] }
237238
│ │ └── PhysicalScan { table: partsupp }
238239
│ └── PhysicalProjection { exprs: [ #0, #3 ] }
239240
│ └── PhysicalScan { table: supplier }

optd-sqlplannertest/tests/tpch/tpch-16-20.planner.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ PhysicalProjection
180180
├── cond:And
181181
│ ├── Eq
182182
│ │ ├── #0
183-
│ │ └── #13
183+
│ │ └── #26
184184
│ └── Lt
185185
│ ├── Cast { cast_to: Decimal128(30, 15), child: #13 }
186186
│ └── #25

0 commit comments

Comments
 (0)