Conditional filter with exists operator

I am trying to write a custom function which would work on a schema that is not fixed (it may follow some tag naming convention for example). I wonder if it is possible because when I try a simple predicate in filter() such as

  |> filter(fn: (r) => 
	if precision == 4 and exists r._g4 then contains(value: r._g4, set: values)
	else if precision == 8 and exists r._g8 then contains(value: r._g8, set: values)
	else false

with ‘exists’ operator, I still get error whenever a referenced property (tag _g8 in this example) is not present in input table, despite the ‘if exists’ condition should resolve to false for missing property, I assume…

Result: _result
Error: cannot add type constraint @ 4:17-7:12: type error 0:0-0:0: missing object properties (_g8)

@alespour I may be wrong, but I think the issue lies with the type inference currently implemented in Flux. We are currently in the process of completely overhauling the type inference system by replacing the type inference algorithm. I don’t know exactly when all of the new functionality will land, but it’s getting close.