Skip to content
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

New Core YAML Schema types: Table and Matrix #47

Open
lmcarreiro opened this issue Mar 6, 2019 · 1 comment
Open

New Core YAML Schema types: Table and Matrix #47

lmcarreiro opened this issue Mar 6, 2019 · 1 comment

Comments

@lmcarreiro
Copy link

lmcarreiro commented Mar 6, 2019

I would like to suggest new types for the Core YAML Schema: Table and Matrix.

Table

  • Would be helpful in scenarios where we have a lot of objects with the same unordered keys
  • This format could be used for Relational DBMS applications to export and load data using readable text files, instead of the unreadable .csv or .sql files
  • Developers would be really glad to store data files of integration tests using this format and have readable files with clean revision histories

Matrix

  • Would be helpful in scenarios where we have a lot of objects with the same ordered keys
  • Developers could use to store configuration like mapping between roles and resources of an application using spreadsheet softwares that support a file format based on it
  • Spreadsheet softwares could create a new open standard (based on YAML) that could have these advantages:
    • Could be cleaner, using one matrix for data and another with styles references from a styles pallete
    • Could have a clean and readable revision history in version control systems like git
    • Big Spreadsheet files get zipped every time you make a change. When versioning in git (that already have a compression system) you duplicate the size of this file in the revision history every time you change it. It wouldn't happen if we used a text file
    • Have you ever unzipped a .xlsx or .ods file to see how unreadable their XML files are?

Examples

Some examples of how da data would be written in a file (Presentation Model) vs how it would be read by the application (Representation Model).

Applications could use metadata in other fields of the YAML to store information about max column sizes in characters.

Table example:

---
# Use this (Presentation Model):
name: users
content: !!table |
  |      id | name     | type  | gender |
  +---------+----------+-------+--------+
  |       1 / Leonardo | Human | male   |
  |         | M. Carre |       |        |
  |         | iro      /       |        |
  |      10 | Isadora  | Human | female |
  | 2654895 | Princesa | Dog   | female |
  | 2654896 | Pitoco   | Dog   | male   |
---
# To get this (Representation Model):
name: users
content:
  - id: 1
    name: Leonardo M. Carreiro
    type: Human
    gender: male
  - id: 10
    name: Isadora Dias
    type: Human
    gender: female
  - id: 2654895
    name: Princesa
    type: Dog
    gender: female
  - id: 2654896
    name: Pitoco
    type: Dog
    gender: male

Matrix example:

# Use this (Presentation Model):
name: map-resources-to-roles
content: !!matrix |
  |           || admin | moderator | reader |
  +-----------++-------+-----------+--------+
  | list      ||   X   |     X     |    X   |
  | get       ||   X   |     X     |    X   |
  | create    ||   X   |     X     |        |
  | edit      ||   X   |     X     |        |
  | delete    ||   X   |           |        |
---
# To get this (Representation Model):
name: map-resources-to-roles
content:
  - list:
    - admin: X
    - moderator: X
    - reader: X
  - get:
    - admin: X
    - moderator: X
    - reader: X
  - create:
    - admin: X
    - moderator: X
    - reader: ~
  - edit:
    - admin: X
    - moderator: X
    - reader: ~
  - delete:
    - admin: X
    - moderator: ~
    - reader: ~

Matrix example (without keys):

# Use this (Presentation Model):
name: some-matrix-of-weights
content: !!bare-matrix |
  +---+----+---+
  | 4 |  7 | 2 |
  | 9 | 10 | 1 |
  | 7 |  4 | 5 |
---
# To get this (Representation Model):
name: some-matrix-of-weights
content:
  - -  4
    -  7
    -  2
  - -  9
    - 10
    -  1
  - -  7
    -  4
    -  5
@TEH30P
Copy link

TEH30P commented Jul 1, 2019

IMHO, YAML already has a tag !!seq, with which can be represented tuple. So here only need field names mapping.

---
# Why not to use this (Presentation Model):
name: users
content: !!fmap |
  * [     id, name    , type , gender  ]
  - [     1 , Leonardo, Human, male    ]
  - [       , M. Carre,       ,        ]
  - [       ,         , iro   ,        ]
  - [     10, Isadora , Human , female ]
  - [2654895, Princesa, Dog   , female ]
  - [2654896, Pitoco  , Dog   , male   ]
...

Named set of tuples for matrix :

# Just this (Presentation Model):
name: map-resources-to-roles
content: !!fnmap |
  *       [ admin, moderator, reader ]
  list  : [ x    , x        , x      ]
  get   : [ x    , x        , x      ]
  create: [ x    , x        ,        ]
  edit  : [ x    , x        ,        ]
  delete: [ x    ,          ,        ]
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants