atviriduomenys / spinta

Spinta is a framework to describe, extract and publish data (a DEP Framework).
MIT License
10 stars 4 forks source link

Apdoroti Ref id priskirimą, kai dar nesugeneruoti keymap įrašai #653

Closed JustinasKen closed 1 week ago

JustinasKen commented 2 weeks ago

Turint duomenų struktūrą, kurioje yra Ref tipo duomenys, sujungti ne per pirminį raktą ir neturint keymap įrašų duomenų bazėje apie juos, yra generuojami klaidingi raktai. Tai įvyksta kiekvieną kartą, kai kviečiamas keymap.encode() metodas. Metodas, aptikęs, jog nėra įrašo, generuoja atsitiktinę uuid reikšmę.

Problemos pavyzdys:

Schema

d | r | b | m | property          | type    | ref                | source       | prepare                   | access
dataset                           |         |                    |              |                           |
  | db                            | sql     |                    |              |                           |
  |   |   | Country               |         | id                 | countries    |                           |
  |   |   |   | id                | integer |                    | id           |                           | open
  |   |   |   | code              | string  |                    | code         |                           | open
  |   |   |   | name              | string  |                    | name         |                           | open
  |   |   | City                  |         | name               | cities       |                           |
  |   |   |   | name              | string  |                    | name         |                           | open
  |   |   |   | country           | ref     | Country            | country_id   |                           | open
  |   |   |   | country_code      | ref     | Country[code]      | country_code |                           | open
  |   |   |   | country_name      | ref     | Country[name]      | country_name |                           | open
  |   |   |   | country_composite | ref     | Country[code,name] |              | country_code,country_name | open

dataset/Country lenta

id code name
0 lt Lithuania
1 lv Latvia

dataset/City lenta

name country_id country_code country_name
Vilnius 0 lt Lithuania
Ryga 1 lv Latvia

Darant prielaidą, jog keymap duomenų bazė yra tusčia yra galimi keli panaudos atvėjai:

Ref raktai yra sukuriami teisingai:

Plačiau ### `keymap` duomenų bazė `dataset/Country` | key | hash | value | | --- | ----- | ------ | | | | | `dataset/Country.name` | key | hash | value | | --- | ----- | ------ | | | | | `dataset/Country.code` | key | hash | value | | --- | ----- | ------ | | | | | `dataset/Country.code_name` | key | hash | value | | --- | ----- | ------ | | | | | kviečiame `GET dataset/Country` Kiekvieną kartą sistema, grąžindama reikšmes, bando sukurti `PrimaryKey` `_id`. Jei ji aptinka, kad keymap yra įrašas su pateiktu pirminiu raktu (šiuo atveju `id`), grąžina `uuid`. Jei neranda, generuoja naują atsitiktinį ir jį įrašo į `keymap`. Sekančiame etape sistema patikrina visas reikalingas (ne pirminio rakto) kombinacijas, šiuo atveju `code`, `name` ir `code, name`, ir į jų reikšmių kombinacijų lenteles įrašo (su `id` sukurtus) pirminius raktus. ### `keymap` duomenų bazė `dataset/Country` | key | hash | value | | --- | ----- | ------ | | ac2f3acb | ... | [0] | | d98e6184 | ... | [1] | `dataset/Country.name` | key | hash | value | | --- | ----- | ------ | | ac2f3acb | ... | [Lithuania] | | d98e6184 | ... | [Latvia] | `dataset/Country.code` | key | hash | value | | --- | ----- | ------ | | ac2f3acb | ... | [lt] | | d98e6184 | ... | [lv] | `dataset/Country.code_name` | key | hash | value | | --- | ----- | ------ | | ac2f3acb | ... | [lt, Lithuania] | | d98e6184 | ... | [lv, Latvia] | `GET dataset/City` grąžina ```json { "_data": [ { "name": "Vilnius", "country": { "_id": "ac2f3acb" }, "country_code": { "_id": "ac2f3acb" }, "country_name": { "_id": "ac2f3acb" }, "country_composite": { "_id": "ac2f3acb" } }, { "name": "Ryga", "country": { "_id": "d98e6184" }, "country_code": { "_id": "d98e6184" }, "country_name": { "_id": "d98e6184" }, "country_composite": { "_id": "d98e6184" } } ] } ```

Ref raktai yra sukuriami neteisingai:

Plačiau ### `keymap` duomenų bazė `dataset/Country` | key | hash | value | | --- | ----- | ------ | | | | | `dataset/Country.name` | key | hash | value | | --- | ----- | ------ | | | | | `dataset/Country.code` | key | hash | value | | --- | ----- | ------ | | | | | `dataset/Country.code_name` | key | hash | value | | --- | ----- | ------ | | | | | kviečiame `GET dataset/City` Kiekvieną kartą sistema, grąžindama reikšmes, bando išgauti `Ref` lauko `_id` pagal pateiktus duomenis. Tačiau, kadangi `keymap` yra tuščias, ji sukuria atsitiktines reikšmes. ### `keymap` duomenų bazė `dataset/Country` | key | hash | value | | --- | ----- | ------ | | ac2f3acb | ... | [0] | | d98e6184 | ... | [1] | `dataset/Country.name` | key | hash | value | | --- | ----- | ------ | | 6cf3e9f2 | ... | [Lithuania] | | 1a81678f | ... | [Latvia] | `dataset/Country.code` | key | hash | value | | --- | ----- | ------ | | 2859dfe3 | ... | [lt] | | 14e1d76b | ... | [lv] | `dataset/Country.code_name` | key | hash | value | | --- | ----- | ------ | | f77b245a | ... | [lt, Lithuania] | | 0ebf8141 | ... | [lv, Latvia] | `GET dataset/City` grąžina ```json { "_data": [ { "name": "Vilnius", "country": { "_id": "ac2f3acb" }, "country_code": { "_id": "6cf3e9f2" }, "country_name": { "_id": "2859dfe3" }, "country_composite": { "_id": "f77b245a" } }, { "name": "Ryga", "country": { "_id": "d98e6184" }, "country_code": { "_id": "1a81678f" }, "country_name": { "_id": "14e1d76b" }, "country_composite": { "_id": "0ebf8141" } } ] } ```

Sprendimas:

  1. Aptikome, kad keymap lentoje nėra įrašo, bet kadangi įrašas sudarytas iš visų pirminių raktų, galime jį sugeneruoti su atsitiktine reikšme.
  2. Aptikome, kad keymap lentoje nėra įrašo, tačiau įrašas yra sudarytas iš kitų raktų. Reikia pasirinkti vieną iš šių variantų:
    • Mesti klaidą, kad reikia susinchronizuoti keymap lentą.
    • Paleisti getall funkciją su įrašo reikšmėmis kaip filtru, kad automatiškai užpildytų keymap lentą.
      • Jei randame daugiau nei vieną įrašą, ar nerandame nei vieno, reikia išmesti klaidą, kad nepavyko priskirti uuid reikšmę.

Susiję: