-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implicit metadata creation on JSON leaves #778
Comments
How does Ditto know what fields to set implicitly? I assume that this should not be hard-coded but at least global configuration. Or is this configurable by the user somehow? |
I also thought about this and see 2 options:
|
Does providing a metadata field which is also auto-injected by ditto (configurable or not) take precedence? E.g. if I want to have ditto set the modified field automatically if I don't provide one myself? |
@w4tsn that's to discuss. It could be very useful when you e.g. want to provide a custom |
Then following up on other discussion on this topic it might be better to have the internal Ok, but then again you could also implement it in the client that if there is no |
Exactly, I would prevent duplicating metadata :) |
This could indeed be a way to go. Probably we also need the possibility to define default values for auto-metadata fields. |
Why would we? Defaults can only be static, can't they? |
I'm not sure if there is a use-case that justifies deactivating built-in metadata. Maybe that's a unnecessary complexity right now. I think static metadata defaults would only make sense if one can also specify for which paths those defaults apply. This would make it possible to load a vorto model as kind-of prototype into the metadata which would then automatically apply metadata to incoming data of this model / the provided auto-metadata definition. However for most parts this could also be written initially on thing creation. Anyways this is how I would image something like this: "_metadata": {
"prototype": {
"features": {
"temperature": {
"properties": {
"value": {
"measurementUnit": "°C"
}
}
}
}
}
} Which produces this thing: {
"thingId": "org.eclipse.ditto:thing-1",
"policyId": "...",
"features": {
"temperature": {
"properties": {
"value": true
}
}
},
"_created": "2020-06-01T10:00:00Z",
"_modified": "2020-06-09T14:30:00Z",
"_revision": 42,
"_metadata": {
"prototype": {
"features": {
"temperature": {
"properties": {
"value": {
"measurementUnit": "°C"
}
}
}
}
},
"policyId": {
"_modified": "2020-06-09T14:00:00Z",
"_revision": 1
},
"features": {
"temperature": {
"properties": {
"value": {
"_modified": "2020-06-09T14:30:00Z",
"_revision": 42,
"measurementUnit": "°C"
}
}
}
}
}
} If one would change the model / auto-metadata of this kind then new incoming data would automatically cause a change of the attached metadata. A use-case for this could be a status property which is a map of wireless device in range which is dynamically filled. I know which metadata the objects of this map would have, but they are not present on thing creation. One problem I stumbled upon with current metadata in general: in the above example the color object is not a leaf and hence has no metadata assigned. In terms of Other interesting built-in:
|
Sure - simply in order to save on the additional data volume when someone does not need it at all.
I could not follow your thoughts here and don't see why this is an added value comparing to setting the metadata when e.g. creating the thing JSON based on a Vorto model.
Yes, that's why the current
Yes, that's possible right now - should have nothing to do with implicitly added metadata.
Agreed, that could be useful as well. We also added
What do you mean with that? |
Fair enough! In that case: should built-in metadata be enabled or disabled by default? Is Furthermore an alternative approach could be to set it this way: "_metadata": {
"settings": {
"auto-metadata": {
"_revision": true,
"_modified": true
}
}
}
Imagine a feature with a property tracking wireless devices in range (e.g. LoRa Gateways or Devices): "LoRaGateways": {
"properties": {
"status": {
"gatewaysInRange": {
"some-id-ab79dc8d8f0f": {
"signalStrength": -7,
"noise": 100
}
}
}
}
} and metadata: "_metadata": {
"features": {
"LoRaGateways": {
"properties": {
"status": {
"gatewaysInRange": {
"some-id-ab79dc8d8f0f": {
"noise": {
"measurementUnit": "dB"
}
}
}
}
}
}
}
} In this case I know the metadata from the model in advance, but I don't know / have the actual objects in the To be able to do this I'd need the ability to set this metadata with the correct path from the vorto model at thing creation (or update it later of course) and ditto needs to apply this everytime I put a new object into such a map. This is a problem of complex data types and it may be argued if it's in dittos responsibility to manage this.
I was wondering if I could apply metadata to the contents of an array and your last response answered this. So a work-around or solution is to use a map / object instead of an array in those cases. |
Following up on Ditto being able to manage arbitrary metadata with #680 it could be useful in some use cases to automatically create/inject certain metadata on each modification of a digital twin.
The 3 obvious implicit metadata fields coming to my mind:
_revision
: the thing_revision
in which the JSON leaf (e.g. a feature property or an attribute) was modified for the last time_modified
: the modification date at which the JSON leaf (e.g. a feature property or an attribute) was modified for the last time_created
: the creation date at which the JSON leaf (e.g. a feature property or an attribute) was createdI suggest keeping the underscore prefix
_
in order to "mark" that those are automatic / Ditto managed metadata fields.An example thing JSON document could look like this:
The text was updated successfully, but these errors were encountered: