====== Data Operation - Define ======
===== Define =====
''define'' is an [[op|operation]] that defines a [[docs:resource:resource|data resource]].
A [[select|select operation]] may not return any [[docs:resource:resource|data resources]] but the ''define'' operation returns always the data resource that it defines.
This operation is used:
* to define inline data resource in a [[docs:flow:pipeline|pipeline file]]
* before a [[create|create]] or [[fill|fill]] operation that will create data resource
===== Arguments =====
The ''define'' operations accept the following arguments.
^ Arguments ^ Mandatory ^ Definition ^
| ''data-uri'' | only if ''data'' is not defined | The [[docs:resource:data_uri|data uri]] is the location of the resource |
| ''data'' | only if ''data-uri'' is not defined | The ''data'' as a list of [[docs:resource:record|records]] (the data are in the inline) |
| ''data-definition'' | no | The [[docs:resource:data-definition|data definition]] |
| ''data-resources'' | | to define more than one data resource (a list of inline data resources) |
===== Usage =====
This operation is only available as [[docs:flow:step|step]] in a [[docs:flow:pipeline|pipeline pipeline]] (ie not in a [[docs:tabli:data:start|tabli data command]])
This is a first step (known as the [[docs:flow:supplier|supplier step]]) because it supplies [[docs:resource:resource|data resources]] to the others operations in the pipeline.
==== Single Data Resource ====
Example: A ''color'' data resource with two columns and 3 records.
pipeline:
- name: "Define"
comment: "This operation define the tabular data resource named 'colors' with two columns"
operation: "define"
args:
data-resource:
data-definition:
logicalName: "colors"
columns: ["id","color"]
data:
- ["1", "blue"]
- ["2", "red"]
- ["3", "yellow"]
- name: "Print"
comment: "Print the colors resource"
operation: "print"
If you [[docs:tabli:flow:execute|execute this pipeline]]
tabli flow execute pipeline/define_single.yml@howto
you will get the data of the ''colors'' data resource [[docs:tabli:data:print|printed]] in a tabular format.
id color
-- ------
1 blue
2 red
3 yellow
==== Multiple Inline Data Resources ====
Two inline data resources ''colors'' and ''characters''
pipeline:
- name: 'Define'
operation: 'define'
args:
data-resources:
- data-definition:
logicalName: "colors"
columns: ["id","color"]
data:
- ["1", "blue"]
- ["2", "red"]
- ["3", "yellow"]
- data-definition:
logicalName: "characters"
columns:
- name: "id"
type: integer
- name: "name"
- name: "last_name"
data:
- [1, "Arnold","Schwarzy"]
- [2, "Don","Norman"]
- [3, "Dale","Carnegie"]
- [4, "Daniel","Kahneman"]