Transforming a Source with a child object to another Source with the same child object


#1

To avoid duplicating transform logic, I’m trying to transform multiple Sources that share a common child object to a common Source with the same child object. Then, I can define a single transform on the common Source to persist the child. Here is some sample code:

type Child {
  field: string
}

type SourceA mixes Source {
  child: Child
}

type SourceB mixes Source {
  child: Child
}

type CommonSource mixes Source {
  commonChild: Child
}

type SourceAToCommonSource mixes CommonSource transforms SourceA {
  commonChild: ~ expression "child"
}

type SourceBToCommonSource mixes CommonSource transforms SourceB {
  commonChild: ~ expression "child"
}

entity type PersistedChild {
    field: string
}

type CommonSourceToPersistedChild mixes PersistedChild transforms CommonSource {
    field: ~ expression "commonChild.field"
}

But, this throws the following errors:

Error while transforming: {Transformation Type:SourceAToCommonSource, Target Type:CommonSource, ErrorMsg:Transformation failed: CommonSource.commonChild.child Error Msg: No implementation found for c3.love.expr.ast.NameNode }
Error while transforming: {Transformation Type:SourceBToCommonSource, Target Type:CommonSource, ErrorMsg:Transformation failed: CommonSource.commonChild.child Error Msg: No implementation found for c3.love.expr.ast.NameNode }

Is this something the C3 platform can support?

This is with C3 platform version 7.8.2.262-1.


#2

With this pattern Source -> Canonical -> Entity I ran into this problem with trying to interact with reference type fields. I’d be curious how your results would differ if you changed the Source[a|b] transforms to to commonChild : ~ expression {field:"child.field"} I know it seems terrible, but I had a similar problem where I wanted to use ExactDimension from source to canonical and then just do a straight mapping from canonical to entity but I got errors similar to yours. I had a lot of strange behavior where json bodies were turned into string literals, etc. instead of reference types.