Canonical for updating a field of an existent type

#1

I’ve to add a new field for Facility so I’ve created a canonical type with two fields: facility id, and boolean value for new field, e.g.

BuildingID,FullyMetered
0001,true
0003,true
0004,false
0005,true

My canonical looks like this

type CanonicalFullyMetered mixes Canonical<CanonicalFullyMetered> {
    BuildingID: string
    FullyMetered: boolean
}

Then the transform is simply like this:

type TransformCanonicalFullyMeteredToFacility mixes Facility transforms CanonicalFullyMetered {
    id           :  ~ expression 'BuildingID'
    fullyMetered :  ~ expression 'FullyMetered'
}

Now the problem is that when I upload the file corresponding to this canonical, no Facility is updated with this new field!

Is this approach OK, i.e, using a different canonical to update a new field in an existent type? Or do I have to modify the original canonical for facilities and add the column to this file then upload it?

0 Likes

#2

Hi Bachir,

Have you tried setting the following annotation:
@canonicalTransform(updateMode='merge')

1 Like

#3

@bachr did your CanonicalFullyMetered file load successfully? In general your second Canonical should also be able to populate all the mandatory fields on the type.

0 Likes

#4

@bachr I don’t think anything new has to be added, by default we always merge in relational db backed entity types, unless we specify updateMode in transform as replace or create

Facility type should have fullyMetered field, and the ids should exist otherwise

Facility.make('0001').get('fullyMetered').fullyMetered// true;

Can you check the status on SourceFile/DataLoadProcessLog and see if there are any errors

0 Likes

#5

thanks @ishka good to know that there is an option to control transforms. From the documentation, it’s actually defaulted to merge:

updateMode: !string enum ImportDataUpdateModeEnum post default 'merge'

@garrynigel sorry I should have put details about the process log, it is showing success but it did creates only two objects out of 334

 targetTypeId: 1186
 targetTypeName: CanonicalFullyMetered
 source: s3://bucket/fs/c3/c3/inbox/CanonicalFullyMetered/inbox/CanonicalFullyMetered.csv
 chunkNumber: 1
 startRecordNumber: 2
 content: { ... }
 id: ba4e4b86-9017-40fb-ab96-31f2d4e60648
 status: SUCCESS
 stats: { ... }
 totalTransformationTimeInsecs: 0
 dbTimeInSecs: 0
 totalTimeInSecs: 0
 successfulObjCount: 334
 rejectedObjCount: 0
 targetTypeStats: { ... }
 Facility: { ... }
 stagedObjCount: 0
 createdObjCount: 2
 updatedObjCount: 0
 failedObjCount: 0
 time: 587
 dbTime: 0
 failedObjCount: 0
 objCount: 334
 time: 587
 dbTime: 0
 objsPerSecond: 568
 dbObjsPerSecond: 83500

The two created facilities does not even exists before and has IDs which are not present in the canonical file.

0 Likes

#6

It’s working now, but I don;t know why though, may be after adding the updateMode='merge' but it;s already default value!

0 Likes

#7

Not sure why it did not work before but updateMode by default is always merge. If you have a reproducible test case kindly create a ticket with the testcase/branch/package and we will try to resolve it.

1 Like