Skip to content

Commit 0966d98

Browse files
committed
Fix EOF error when joining multiple tables with jsonb_array_elements. Closes #192
1 parent 3dd82f7 commit 0966d98

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

quals.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,31 @@ func getQualValue(right unsafe.Pointer, node *C.ForeignScanState, ci *C.Conversi
316316
exprState := C.ExecInitExpr(valueExpression, (*C.PlanState)(unsafe.Pointer(node)))
317317
econtext := node.ss.ps.ps_ExprContext
318318
value = C.ExecEvalExpr(exprState, econtext, &isNull)
319+
log.Printf("[TRACE] getQualValue T_Param qual, value %v", value)
319320
case C.T_OpExpr:
321+
/* T_OpExpr may be something like
322+
where date_time_column > current_timestamp - interval '1 hr'
323+
or
324+
select * from
325+
aws_ec2_instance as i,
326+
jsonb_array_elements(i.block_device_mappings) as b,
327+
aws_ebs_volume as v
328+
where
329+
v.volume_id = b -> 'Ebs' ->> 'VolumeId';
330+
331+
evaluating jsonb_array_elements causes a crash, so exclude these quals from the evaluation
332+
*/
333+
320334
opExprQual := (*C.OpExpr)(right)
335+
336+
log.Printf("[TRACE] getQualValue T_OpExpr qual opno %d, opfuncid %d", opExprQual.opno, opExprQual.opfuncid)
337+
338+
// TACTICAL we know that trying to evaluate a qual deriving from a jsonb_array_elements function call causes
339+
// ExecEvalExpr to crash - so skip evaluation in that case
340+
if opExprQual.opfuncid == 3214 {
341+
log.Printf("[TRACE] skipping OpExpr evaluation as opfuncid 3214 (jsonb_array_elements) is not supported)")
342+
return nil, fmt.Errorf("QualDefsToQuals: unsupported qual value (type %s, opfuncid %d), skipping\n", C.GoString(C.tagTypeToString(C.fdw_nodeTag(valueExpression))), opExprQual.opfuncid)
343+
}
321344
typeOid = opExprQual.opresulttype
322345
exprState := C.ExecInitExpr(valueExpression, (*C.PlanState)(unsafe.Pointer(node)))
323346
econtext := node.ss.ps.ps_ExprContext

0 commit comments

Comments
 (0)