Mixing transform logic into another transform


I mixed a transform into another transform to avoid code duplication. The following premise works:

abstract type AbstractSourceTypeToEntityType
  mixes EntityType
  transforms AbstractSourceType {
  entityField: ~ expression "sourceField"

type SourceTypeToEntityType
  mixes EntityType, AbstractSourceToEntityType
  transforms SourceType

With the above code, loading a SourceType will use the transform logic within AbstractSourceTypeToEntityType to persist an EntityType.

But, is this recommended by C3 IoT? If I change the mix-in order, the platform throws the following error:

type SourceTypeToEntityType
  mixes AbstractSourceToEntityType, EntityType
  transforms SourceType

Invalid target type EntityType for canonical SourceType

I’m wondering if this is an unsupported hack or if I can rely on this method to avoid code duplication.


On a side note, you don’t need to explicitly mix EntityType in SourceTypeToEntityType, as the later mixes AbstractSourceTypeToEntityType which itself mixes EntityType.


Unfortunately, that doesn’t work. For this method to work, SourceTypeToEntityType must explicitly mix EntityType, or the platform throws the following error:

Error in Canonical.transform: Invalid target type EntityType for canonical SourceType

This is another detail that makes me worry whether I can rely on this method.


I’ve been looking for this type of capability for a long time on our CDC logic. I would assume that transforms should have one mixes as it’s the single target getting created, just as transforms seems to be singular. However, if it’s letting it slip in, I wonder if it’s because the order is loosely tied to the last mixin being the transform’s target while anything prior is treated as a typical mixin. If only we had a grammar…


I see why you want to mix Transform types, and currently it should work.

But in the future we are moving away from defining transforms as types and move it to metadata in Transform.c3typ
When you define a transform, whatever it mixes( first level mixing and not deep mixing) are the targetTypes to which it will transform(AbstractSourceToEntityType, EntityType) and the source type is defined after the transforms keyword(SourceType).
Since the type AbstractSourceTypeToEntityType is not persistable, although it mixes EntityType which is Persistable, and the check is only for first level mixins it throws the error when you remove EntityType from the declaration.

Transform as a c3type are exceptions hence the move to Transform metadata. not sure how will we support mixes of Transform there.
But thanks for this, we will try to keep in mind about the mixing and the move to metadata will probably be post 7.9

If you don’t want to duplicate code, I would highly recommend making the SourceType more generic enough to be used across different source systems then you can use only one transform logic which takes one source and outputs objects of one target type.