Transform error using matchesRegex

I have a canonical type which does not differentiate between numeric and string values; all values come from the same Value field. I want to set up a transform to a TimedDataPoint type that will populate the value field for anything numerical, and populate a separate stringValue field for anything that does not represent a number.

I have set up the following expressions to do so:


value:         ~ expression 'matchesRegex(Value, "^-?([0-9]*[.])?[0-9]+$") ? number(Value) : null'
stringValue:   ~ expression '!matchesRegex(Value, "^-?([0-9]*[.])?[0-9]+$") ? Value : null'

This works fine from console when evaluating via Expr.eval(), but when I try running MyCanonicalType.process, MyCanonicalType.transformCanonical, or run canonical tests I end up with the following error:

“message” : “Error while transforming: {Transformation Type:TransformMyCanonicalTypeToPersistableType, Target Type:PersistableType, ErrorMsg:Transformation failed: PersistableType.stringValue.!matchesRegex(Value, “^-?([0-9]*[.])?[0-9]+$”) ? Value : null Error Msg: null }”,
“codes” : [ “TransformationError” ]

Does anyone know how to resolve this issue?

@scott.kruyswyk sorry about that, unfortunately we are still in this state where Expr.eval() uses a different version of the expression engine and data integration uses a much older version. Could it be the input Value field on the Source type is null? and matchesRegex requires the value of the field.

1 Like

Does matches (instead of matchesRegex) give you the same result?

1 Like

matches works as expected (on 7.8.10.233) Thanks @tony.li!