emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
blob 5ca233377381e5b819f3c51c341195baff6544d0 6888 bytes (raw)
name: testing/examples/org-tbljoin.org 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
 
#+Title: a collection of examples org-tbljoin tests

* In-place mode

** Nutritional reference table with header

There are multiple "eggplant" entries on purpose.
They will all get added to the master table when joining.

The header extends on 3 lines. All 3 lines will be concatenated to the
master table header, provided the master table header has at least 3
lines. The excess lines will be ignored.

#+tblname: nut_with_header
|------+----------+-------+-------+---------|
| Carb | type     | Fiber | Sugar | Protein |
| ohyd |          |       |       |         |
| rate |          |       |       |         |
|------+----------+-------+-------+---------|
|  8.6 | eggplant |   2.5 |   3.2 |     0.8 |
|  8.7 | eggplant |   2.6 |   3.3 |     0.9 |
|  3.4 | tomatoe  |   0.6 |   2.1 |     0.8 |
|  9.0 | onion    |   1.3 |   4.4 |     1.3 |
| 18.3 | egg      |     0 |  18.3 |    31.9 |
| 16.0 | rice     |   0.2 |     0 |     1.5 |
| 16.0 | bread    |   0.7 |   0.7 |     3.3 |
| 17.6 | orange   |   3.1 |  11.9 |     1.3 |
| 18.5 | banana   |   2.1 |   9.9 |     0.9 |
|  1.4 | tofu     |   0.7 |   0.5 |     6.6 |
|  7.2 | nut      |   2.6 |   1.3 |     4.9 |
| 21.3 | corn     |   4.7 |   1.8 |     2.8 |
|  8.5 | eggplant |     ? |     ? |       ? |
|      |          |       |       |         |

** Nutritional reference table without header

#+tblname: nut_no_header
|  8.6 | eggplant | 2.5 |  3.2 |  0.8 |
|  8.7 | eggplant | 2.6 |  3.3 |  0.9 |
|  3.4 | tomatoe  | 0.6 |  2.1 |  0.8 |
|  9.0 | onion    | 1.3 |  4.4 |  1.3 |
| 18.3 | egg      |   0 | 18.3 | 31.9 |
| 16.0 | rice     | 0.2 |    0 |  1.5 |
| 16.0 | bread    | 0.7 |  0.7 |  3.3 |
| 17.6 | orange   | 3.1 | 11.9 |  1.3 |
| 18.5 | banana   | 2.1 |  9.9 |  0.9 |
|  1.4 | tofu     | 0.7 |  0.5 |  6.6 |
|  7.2 | nut      | 2.6 |  1.3 |  4.9 |
| 21.3 | corn     | 4.7 |  1.8 |  2.8 |
|  8.5 | eggplant |   ? |    ? |    ? |
|      |          |     |      |      |

** With a header and a formula
   :PROPERTIES:
   :ID:       cc039f82-24d2-422c-a5ae-4dea09cce684
   :END:

- Put the cursor on the "type" column
- type
  : M-x orgtbl-join
- answer
  : nut_with_header
  : type

| quty | type     | units |  mul |
|------+----------+-------+------|
|   70 | onion    |     5 |  350 |
|  120 | tomatoe  |     8 |  960 |
|  300 | eggplant |     2 |  600 |
|------+----------+-------+------|
|  100 | tofu     |     1 |  100 |
|  250 | corn     |    15 | 3750 |
|   90 | tomatoe  |     5 |  450 |
|------+----------+-------+------|
|   80 | amarante |     1 |   80 |
#+TBLFM: $4=$1*$3

The master tables have a formula on the last column, which will be
preserved after joining.

** Without a header, with a formula
- Put the cursor on the second column
- type
  : M-x orgtbl-join
- answer
  : nut_with_header
  : type

|  70 | onion    |  5 |  350 |
| 120 | tomatoe  |  8 |  960 |
| 300 | eggplant |  2 |  600 |
| 100 | tofu     |  1 |  100 |
| 250 | corn     | 15 | 3750 |
|  90 | tomatoe  |  5 |  450 |
|  80 | amarante |  1 |   80 |
#+TBLFM: $4=$1*$3

The master tables have a formula on the last column, which will be
preserved after joining.

* PULL mode

** Master table with oversized header

#+tblname: meal_with_header
| product   |   quty |
| common    |     in |
| name      | gramms |
| (english) |        |
|-----------+--------|
| onion     |     70 |
| unknown   |    999 |
| tomatoe   |    120 |
| eggplant  |    300 |
| corn      |    250 |

** Master table without header

#+tblname: meal_no_header
| onion     |  70 |
| not known | 999 |
| tomatoe   | 120 |
| eggplant  | 300 |
| corn      | 250 |

** Join header+header
Marker: a14723d3-13c8-4fd1-a69f-caf2fdb2d2b1
#+BEGIN: join :mas-table meal_with_header :mas-column $1 :ref-table nut_with_header :ref-column 2
#+END:

** join header+bare
Marker: 79a90117-fc0e-4556-b790-c925b6acd450
#+BEGIN: join :mas-table "meal_with_header" :mas-column "product" :ref-table "nut_no_header" :ref-column "2"
#+END:

** join bare+header
Marker: 24c5a7b4-2815-40d4-89ec-32b58f492b32
#+BEGIN: join :mas-table meal_no_header :mas-column $1 :ref-table nut_with_header :ref-column type
#+END:

** join bare+bare
Marker: e872df5c-dd5c-4ad6-b395-2e5a000488b5
#+BEGIN: join :mas-table meal_no_header :mas-column 1 :ref-table nut_no_header :ref-column $2
#+END:

* PUSH mode

** Push a master table with header

1st reference table has a larger header
2nd reference table has no header

Marker: 6426c948-bbd4-4b25-8b3d-2584b70af4d0
#+ORGTBL: SEND joined1 orgtbl-to-joined-table :ref-table nut_with_header :mas-column product :ref-column type
#+ORGTBL: SEND joined2 orgtbl-to-joined-table :ref-table "nut_no_header" :mas-column "$1"    :ref-column $2
| product       | quty |
| (yes)         |  (g) |
|---------------+------|
| onion         |   70 |
| not specified |  999 |
| tomatoe       |  120 |
| eggplant      |  300 |
| corn          |  250 |

#+BEGIN RECEIVE ORGTBL joined1
#+END RECEIVE ORGTBL joined1

#+BEGIN RECEIVE ORGTBL joined2
#+END RECEIVE ORGTBL joined2

** Push a master table with not header

1st reference table has a larger header
2nd reference table has no header

Marker: 1683a68c-f4df-4b04-9f2d-bd4c8a909bf3
#+ORGTBL: SEND joined3 orgtbl-to-joined-table :ref-table nut_with_header :mas-column "1" :ref-column type
#+ORGTBL: SEND joined4 orgtbl-to-joined-table :ref-table "nut_no_header" :mas-column $1  :ref-column $2
| onion         |  70 |
| not specified | 999 |
| tomatoe       | 120 |
| eggplant      | 300 |
| corn          | 250 |

#+BEGIN RECEIVE ORGTBL joined3
#+END RECEIVE ORGTBL joined3

#+BEGIN RECEIVE ORGTBL joined4
#+END RECEIVE ORGTBL joined4

* Cartesian product

What happens when the master and the reference table are the same
table?  A so-called cartesian product (named after the mathematician
René Descartes) is created.  Every possible combination of rows is
created.

** Simple auto-join in pull-mode

The table is joined with itself, creating a cartesian product.  The
resulting table size is the square of the original table size (7*7 =
49).

#+tblname: auto
| t | n |
|---+---|
| a | 1 |
| a | 2 |
| a | 3 |
| a | 4 |
| a | 5 |
| a | 6 |
| a | 7 |

Marker: b6e51dab-cded-427e-8967-d14a34070d08
#+BEGIN: join :mas-table auto :mas-column t :ref-table auto :ref-column "t"
#+END:

** Two sub-cartesian-products in push mode

Because the table has two keys (a & b), two completely unrelated
cartesian products are created, each the square size of the source
(3^2 + 2^2 = 13).

#+tblname: buto
#+ORGTBL: SEND buto2 orgtbl-to-joined-table :ref-table buto :mas-column "t" :ref-column t
| t | n |
|---+---|
| a | 1 |
| a | 2 |
| a | 3 |
| b | 4 |
| b | 5 |

#+BEGIN RECEIVE ORGTBL buto2
| t | n | n |
|---+---+---|
| a | 1 | 1 |
| a | 1 | 2 |
| a | 1 | 3 |
| a | 2 | 1 |
| a | 2 | 2 |
| a | 2 | 3 |
| a | 3 | 1 |
| a | 3 | 2 |
| a | 3 | 3 |
| b | 4 | 4 |
| b | 4 | 5 |
| b | 5 | 4 |
| b | 5 | 5 |
#+END RECEIVE ORGTBL buto2

debug log:

solving 5ca2333 ...
found 5ca2333 in https://list.orgmode.org/orgmode/55D640F0.4070502@free.fr/

applying [1/1] https://list.orgmode.org/orgmode/55D640F0.4070502@free.fr/
diff --git a/testing/examples/org-tbljoin.org b/testing/examples/org-tbljoin.org
new file mode 100644
index 0000000..5ca2333

Checking patch testing/examples/org-tbljoin.org...
Applied patch testing/examples/org-tbljoin.org cleanly.

index at:
100644 5ca233377381e5b819f3c51c341195baff6544d0	testing/examples/org-tbljoin.org

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).