How to Ignore the Transform of a field in a base Transform.c3typ that you are dependent on

#1

In a package that my customer package depends on, I have the following transform for a field:

baseFolder/src/TransformTypeA.c3typ
type TransformTypeA {

typeFieldA: ~ expression ‘{“timestamp”:“timestamp”,“value”:“canonicalFieldA”}’

}

I no longer want to map this field to my customer version of TypeA, I instead want to map it to a different field. I can create this new mapping:

customerFolder/src/TransformTypeA.c3typ
type TransformTypeA {

typeFieldB: ~ expression ‘{“timestamp”:“timestamp”,“value”:“canonicalFieldA”}’

}

But the typeFieldA will still be transformed due to the earlier definition. Is the best was to negate this to explicitly overwrite the expression in the Base TypeA? Or is there a better way?

customerFolder/src/TransformTypeA.c3typ
type TransformTypeA {

typeFieldA: ~ expression '{“timestamp”:"",“value”:""}'
typeFieldB: ~ expression ‘{“timestamp”:“timestamp”,“value”:“canonicalFieldA”}’

}

0 Likes

#2

Your example is correct. You can override the transform for typeFieldA exactly as in your example

0 Likes

#3

Thanks for your quick response, Riley. We tested the above and we got the below error.

Additionally, we actually do not want to overwrite the status typeFieldA with an empty value, because that field is populated through other means. We simply want to no longer transform the field in the same way, not overwrite the mapping with an empty object.

Error
<<<
errorMsg: wrapped org.mozilla.javascript.EvaluatorException: Empty expression. at c3.love.js.ExprParser.parseExpression (ExprParser.java:107)c3.love.exceptions.C3RuntimeException: wrapped org.mozilla.javascript.EvaluatorException: Empty expression. at c3.love.js.ExprParser.parseExpression (ExprParser.java:107) at c3.love.exceptions.C3RuntimeException.wrapIt(C3RuntimeException.java:115) at c3.love.exceptions.C3RuntimeException.wrapIt(C3RuntimeException.java:73) at c3.engine.database.DatabaseEngine.execute(DatabaseEngine.java:1340) at c3.engine.database.DatabaseEngine.execute(DatabaseEngine.java:343) at c3.server.impl.Task.doFilter(Task.java:247) at

0 Likes

#4

We added a conditional statement to the expression transforming typeFieldA such that the condition would never be met by any incoming files. It is a formidable workaround.

0 Likes

#5

How about just putting dummy values for timestamp and value keys, instead of empty strings? (As both keys and values are strings, they must contain something; it could be empty strings inside, too, but I guess you’d have to escape the inner double quotes.) Even better, instead of an object, it could be a simple value: typeFieldA: ~ expression '0' (I am guessing, not sure about what’s possible yet).

0 Likes

#6

Alex,
The key for us was that typeFieldA was still being populated, but through another Transformation, so we did not want to put dummy values, because it would overwrite what was populated in that field through another transform. We needed to omit the transformation to that typeFieldA entirely, so that when loading data from the above transform, it would not write to that field and change data that should not be changed.

With regards to changing the format of the data field in your transform, you must give an object with the fields defined on the data type defined for the typeField you are mapping to, otherwise you will get an error on data load because you’ll be trying to transform to a field of format: {timestamp: datetime, value: string} with some other format, in your example, a plain string.

0 Likes

#7

The Conditional statement we added looks like this:

remix type TransformTypeA {

typeFieldA: ~ expression “0==1 ? {timestamp:timestamp,value: canonicalFieldA} : null”
}

However, please note that we were loading to a TimedValue field (note the object format of the expression), and null fields may be handled differently by data fields with primitive data types (booleans, strings, ints, etc.). Please test it out before using on a primitive data type transform.

0 Likes