Long string in canonical vs. c3 type


Let’s assume I want to load a canonical file into a c3 type and I have a very long string as a field.
Do I need to specify “long string” on both the canonical field and the target field?



Yes. If you don’t specify long string in the target type field you will get an error when data will be transformed.

long string datatype will allow you to load and store up to 4000 chars in your field.



What about the canonical type?



The canonical type must have that field defined as long string as well.


type CanonicalTest mixes Canonical<CanonicalTest> {  
  sourceField: long string

type TransformTest mixes Test transforms CanonicalTest {
	testField: ~ expression "sourceField"

entity type Test schema name "TESTTYPE" {
  testField: long string

This way you can load a field of length 4000 from CanonicalTest into the target type Test.testField



What happens if my field is longer than 4000? I know I can set @db(length = xxx) but that is only for the target type, not for the canonical.

Also does it matter to put long string vs string if we set the db annotation length anyway?



If your field is longer than 4000 you can declare it as string and specify the length using the annotation, e.g. @db(length=5000) on the target type. You can also use a clob data type, see documentation:

This is not needed on the canonical type since it’s not a persistable type.

To your second point, declaring the field as long string is equivalent to specify the field as string but with annotation @db(length=4000)

1 Like


so to confirm and summarize:

  • if string length < 512, both canonical and target type fields should be of type string.
  • if string length > 512 and < 4000 both canonical and target type fields can be of type string or long string. If string is chosen a db annotation should be used on the target type field and string can be used on the canonical type field. If long string is chosen, the canonical type field has to be also long string.
  • if string length > 4000 both canonical and target type fields have to be of type string or clob and the target type field needs a db annotation if it is of type string.