-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add several values for the same property #168
Comments
@cquest do you have an opinion on that (or can you share OSM experience on that ?) |
On my side, I think option 1 is best for now. Option 2 would:
For option 1, it should be well documented what the UI does. I think going for "," as a separator is better than ";" because it's more standard (for example it's permitted to represent parameters as list in OpenAPI). Then you have either to deal with values containing "," or refuse them. If you deal with them, I strongly encourage using csv style (handling quote) as there are a lot of libs to deal with it and avoid silly bugs. In my opinion, the UI should clearly handle lists (one input box per value) instead of trying to magically guess, which have the risk to lead to complicated cases (explicit is better than implicit). Also don't try to handle more than lists, as dict, for example must be encoded in property name. (one could even argue that list could be encoded as my::value::1="value 1", my::value::2="value 2", etc., but it might be overcomplicated !) We could even argue that list could be handled by property name: ` |
BTW, this also relates to #151 |
I am working on this issue |
I have a doubt, which one should we go ahead with
comma-separated would be more suitable here as we would not have to change the entire structure, just need to change the fetching of values related to specific keys. |
Hi everyone, I don't think this is as much of an implementation problem as it is a design problem (easy to implement, hard to plan). I've been reading the discussions surrounding this issue (see #168, #151, #189, and perhaps #128) and I strongly believe that this issue (#168) should be thought about along with #189 so we don't create incompatible designs. The current solution appears to be to use namespaces (for example, With this in mind, I want to tackle two birds with one stone: allowing multiple values for the same key and allowing contextual flags without key sprawl. Here's my proposed solution that addresses the challenges while maintaining backward compatibility and avoiding unique constraint violations. Please keep in mind that this deviates from OSM's approach, but this is a design decision I believe is worth considering which could potentially help towards #128 Suggestion: Multiple Values and Contextual Flags with a Separate args ArrayOur goal is to standardize how we handle keys with contextual extensions without causing key sprawl. Instead of embedding context in the key (e.g. using colon-separated strings like Schema Changes to Support Contextual Flags
This column will store an array of contextual flags. If a key is provided without any contextual extension, ALTER TABLE folksonomy
ADD COLUMN args JSONB DEFAULT '[]'::JSONB;
When a composite key (e.g.
For example:
The current unique constraint on CREATE UNIQUE INDEX ON folksonomy (product, owner, key, value, args); This ensures that a single product (and owner) can have multiple entries for the same base key, as long as the combination of value and context (in Querying and API Endpoint DesignWhen querying, we need to handle both cases: filtering by a specific set of context flags and retrieving entries that have no context. Suggestion 1: Querying for Specific Context using an additional args querySuppose you want to query for the entry that specifically represents a "robotoff issue" with a "product version" context. You can design the API to accept a query parameter (e.g.,
Suggestion 2: Handle splitting in the backendIn the backend, you can split keys by the colon and store the first part as
After this, the query will:
SELECT *
FROM folksonomy
WHERE product = '{product_id}'
AND key = 'data_quality'
AND args @> '["robotoff_issue", "product_version"]'; This query works as long as you enforce a canonical order or simply use the containment operator, which ignores order. If you require precise matching (order matters), you may need additional logic, but typically the containment check is sufficient. Handling Cases with No Args but Multiple Values for Same Key (#168)For entries without any contextual flags (i.e., Example API Endpoints1. Inserting a Property with ContextWhen adding or updating a property, the client sends the composite key which is then split server-side: POST /product/0055144524653/data_quality
Content-Type: application/json
{
"v": "Yes",
"args": ["robotoff_issue", "product_version"] // Optional: omit or set to [] if no context
} 2. Querying for a Specific ContextTo query for a specific contextual combination: GET /product/0055144524653/data_quality?args=robotoff_issue,product_version Backend logic would:
3. Querying Without ContextTo query entries for GET /product/0055144524653/data_quality This would return all entries where Backward Compatibility for Single-Value API Responses Problem: Existing users expect Solution:
SELECT * FROM folksonomy
WHERE product = '0055144524653' AND key = 'producer_data_issue'
ORDER BY last_edit DESC
LIMIT 1;
For example:
Deprecation strategy: We can document the legacy behavior as "returns the latest value" and tell new clients to use I'm new to OFF and I understand that there are a lot of moving parts here so I would love to hear your thoughts and feedback. Charles' Solution 1: Delimiter-Separated Values (OSM Style)Or we can go ahead with Option 1 where we simply use a delimiter like OSM. I genuinely think this is a great option too. |
@suchithh thanks for the clear proposal and the research. I'm not sure how you idea solve the list problem. Also it does not solve the suggestion problem (how do you help user finding the right keys) Also reducing keys to one word seems to go against the initial design. The args list you are proposing is interesting though, it's very close to my key / value proposal Maybe we could have something like:
translate to |
Reported by Alizarine on Slack (2024-03-24).
Indeed, the example provides a simple use case: a product could have multiple
producer_data_issue
.Option 1: do not change the API, manage it with the UI
With the UI it would be possible to enter a property several times.
In the database, the different values would be stored in a unique
property
/value
, separated by a given sign (a;
for example).The UI would have to manage the following cases:
Option 2: change the API, do not change the UI
There would be probably no change at all in the UI.
The text was updated successfully, but these errors were encountered: