dotted-notation 0.56.0__tar.gz → 0.57.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/CHANGELOG.md +69 -0
  2. {dotted_notation-0.56.0/dotted_notation.egg-info → dotted_notation-0.57.0}/PKG-INFO +196 -26
  3. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/README.md +195 -25
  4. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/__init__.py +18 -10
  5. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/access.py +78 -3
  6. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/api.py +117 -53
  7. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/base.pxd +1 -0
  8. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/base.py +30 -5
  9. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/engine.pxd +1 -1
  10. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/engine.py +12 -9
  11. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/filters.py +27 -7
  12. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/results.py +1 -5
  13. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/translators/core.py +55 -6
  14. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/translators/spark_pyspark.py +813 -5
  15. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/translators/sql_pg.py +92 -10
  16. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/utils.py +71 -1
  17. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/utypes.py +3 -0
  18. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/wrappers.py +21 -27
  19. {dotted_notation-0.56.0 → dotted_notation-0.57.0/dotted_notation.egg-info}/PKG-INFO +196 -26
  20. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/pyproject.toml +1 -1
  21. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/LICENSE +0 -0
  22. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/MANIFEST.in +0 -0
  23. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/__main__.py +0 -0
  24. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/access.pxd +0 -0
  25. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/cli/__init__.py +0 -0
  26. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/cli/_compat.py +0 -0
  27. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/cli/formats.py +0 -0
  28. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/cli/main.py +0 -0
  29. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/containers.py +0 -0
  30. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/filters.pxd +0 -0
  31. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/grammar.py +0 -0
  32. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/groups.pxd +0 -0
  33. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/groups.py +0 -0
  34. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/matchers.pxd +0 -0
  35. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/matchers.py +0 -0
  36. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/native.py +0 -0
  37. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/predicates.py +0 -0
  38. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/recursive.pxd +0 -0
  39. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/recursive.py +0 -0
  40. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/transforms.py +0 -0
  41. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/translators/__init__.py +0 -0
  42. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/translators/spark.py +0 -0
  43. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/translators/sql.py +0 -0
  44. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted/wrappers.pxd +0 -0
  45. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted_notation.egg-info/SOURCES.txt +0 -0
  46. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted_notation.egg-info/dependency_links.txt +0 -0
  47. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted_notation.egg-info/entry_points.txt +0 -0
  48. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted_notation.egg-info/requires.txt +0 -0
  49. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/dotted_notation.egg-info/top_level.txt +0 -0
  50. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/setup.cfg +0 -0
  51. {dotted_notation-0.56.0 → dotted_notation-0.57.0}/setup.py +0 -0
@@ -3,6 +3,75 @@
3
3
  All notable changes to `dotted` are recorded here. Versions prior to
4
4
  the ones listed are omitted — browse git history for earlier entries.
5
5
 
6
+ ## [0.57.0]
7
+
8
+ ### Added
9
+ - Streaming reads: `iget`, `ipluck` and `iexpand` read through a one-shot
10
+ iterator (a generator, a `map`, a cursor). A pattern iterates what it
11
+ reads and yields one match at a time, drawing from the iterator only as
12
+ far as it is asked: `iget({'rows': gen}, 'rows[*&x=1].y')`. A dict-like
13
+ is read through its own `items()`, a sequence or iterator through its
14
+ `__iter__`. A slice of an iterator is an `islice` of it and a slice
15
+ filter of one a generator, read with a following `[*]`. An index, or a
16
+ slice from the end, does not match an iterator and does not draw from
17
+ it. An iterator is read once: a path that reaches it twice finds it
18
+ empty the second time.
19
+ - `iget_multi`, `ipluck_multi` and `iexpand_multi`, the streaming forms of
20
+ `get_multi`, `pluck_multi` and `expand_multi`. `iget_multi` is flat:
21
+ every match of every path in one stream.
22
+ - `iter` as a type restriction name, a one-shot iterator: `*:!iter`.
23
+
24
+ ### Changed (breaking)
25
+ - `unique=False` replaces `duplicates=False` on `pluck`, `expand`, their
26
+ `i` and `_multi` forms: every match is yielded, and
27
+ `unique=True` gives each path once. `pluck` and `expand` no longer
28
+ dedup by default. `duplicates=` is removed.
29
+ - `iget`, `ipluck` and `iexpand` read through an iterator, which yielded
30
+ nothing before. `get`, `has`, `pluck`, `expand` and the writes are
31
+ unchanged, and never draw from one.
32
+ - `walk` and `walk_multi` are removed: call `ipluck` and `ipluck_multi`.
33
+
34
+ ### Fixed
35
+ - An iterator is no longer taken for a set: a set pattern in a value
36
+ guard no longer matches, and so consumes, a generator.
37
+ - An OR filter keeps an object that sits at several positions of a
38
+ list at each of them. It tracked matches by identity, so
39
+ `get([d, d], '[*&x=1,x=2]')` gave `d` once, the slice filter
40
+ `[x=1,x=2]` likewise, and `remove` left the repeats behind.
41
+
42
+ ## [0.56.2]
43
+
44
+ ### Added
45
+ - `sqlize` and `sparkize` write through groups, as dotted's `update`
46
+ does: `(a, b)` writes each branch where it matches, on the node the
47
+ branches before it wrote, and builds the last concrete one where none
48
+ does; `(a&b)` writes every branch, where each matches or can be built;
49
+ `(a, b)?` writes the first that matches; a cut ends the branches after
50
+ one that matched. So `emails[(*&email="x"#, +)]` writes the email
51
+ that's there, else appends one, and `(name.~first#, name.first)` sets
52
+ `first` only where it's missing. A soft cut in a write, and a group at
53
+ the top of a path, still raise (#75).
54
+
55
+ ## [0.56.1]
56
+
57
+ ### Added
58
+ - `sparkize`'s `r.as_update(value)`, the write of `value` at a column
59
+ path's matches as dotted's `update` does it, as `sqlize`'s
60
+ `as_update` writes it: `build` makes it a dict for `df.withColumns`,
61
+ `df.withColumns(r.build(r.as_update('admin'), schema=df.schema))`.
62
+ Each node is written by its Spark type: a struct's field takes the
63
+ written value's type, a map's values and a list's elements share one.
64
+ Where Spark can't hold what dotted writes, as a null struct dotted
65
+ makes a dict of fewer keys, or where dotted's update raises, the job
66
+ fails with a `dotted update: …` message. Groups, `!`, `**` and slices
67
+ in a write raise, and a slot on a str fails the job, as in `sqlize`
68
+ (#75).
69
+
70
+ ### Fixed
71
+ - `sqlize`'s `as_update` writes nothing under `~` at a string, and
72
+ nothing for `.*` at an array or a string, as dotted's update does;
73
+ it failed.
74
+
6
75
  ## [0.56.0]
7
76
 
8
77
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dotted_notation
3
- Version: 0.56.0
3
+ Version: 0.57.0
4
4
  Summary: Dotted notation for safe nested data traversal with optional chaining, pattern matching, and transforms
5
5
  Author-email: Frey Waid <logophage1@gmail.com>
6
6
  License-Expression: MIT
@@ -101,6 +101,7 @@ For faster `mutable=False` updates and removes, install the
101
101
  - [Breaking Changes](#breaking-changes)
102
102
  - [API](#api)
103
103
  - [Get](#get)
104
+ - [Streaming reads](#streaming-reads)
104
105
  - [Update](#update)
105
106
  - [Remove](#remove)
106
107
  - [Match](#match)
@@ -112,7 +113,7 @@ For faster `mutable=False` updates and removes, install the
112
113
  - [Mutable](#mutable)
113
114
  - [Setdefault](#setdefault)
114
115
  - [Pluck](#pluck)
115
- - [Walk](#walk)
116
+ - [Ipluck](#ipluck)
116
117
  - [Unpack](#unpack)
117
118
  - [Pack](#pack)
118
119
  - [Keys, Values, Items](#keys-values-items)
@@ -275,10 +276,24 @@ Several Python libraries handle nested data access. Here's how dotted compares:
275
276
  - **String/bytes glob patterns**—match by prefix, suffix, or substring: `*="user_"...`, `*=b"header"...b"footer"`
276
277
  - **Value groups**—disjunction over filter values: `*=(1, 2, 3)`, `[*&status=("active", "pending")]`
277
278
  - **Strict mode**—enforce type separation: `[0]` only matches lists, `.key` only matches dicts
279
+ - **Streaming reads**—`iget`, `ipluck` and `iexpand` read through generators and other one-shot iterators, one match at a time: `rows[*&active=True].id` over a cursor
278
280
 
279
281
  <a id="breaking-changes"></a>
280
282
  ## Breaking Changes
281
283
 
284
+ ### v0.57.0
285
+ - **`pluck` and `expand` no longer dedup by default.** `unique=False`
286
+ replaces `duplicates=False` on `pluck`, `expand` and their `i` and `_multi`
287
+ forms: a path a pattern reaches twice is yielded twice.
288
+ Pass `unique=True` for each path once; `duplicates=` is gone and raises
289
+ `TypeError`. See [Pluck](#pluck).
290
+ - **`iget`, `ipluck` and `iexpand` are streaming reads.** A pattern
291
+ iterates what it reads, so they read through a one-shot iterator, which
292
+ yielded nothing before. See [Streaming reads](#streaming-reads).
293
+ - **`walk` and `walk_multi` are removed.** They were other names for
294
+ `ipluck` and `pluck_multi`; call `ipluck` and `ipluck_multi`. See
295
+ [Ipluck](#ipluck).
296
+
282
297
  ### v0.56.0
283
298
  - **`sparkize`'s `build` takes the DataFrame's schema.** A path reads
284
299
  each node by its type, so `r.build(fragment, schema=df.schema)`;
@@ -292,7 +307,7 @@ Several Python libraries handle nested data access. Here's how dotted compares:
292
307
  - **`walk` dedups.** It is now `ipluck`, and `walk_multi` is `pluck_multi`,
293
308
  so a path a pattern reaches twice is yielded once, as `pluck` does:
294
309
  `walk({'a': 1, 'b': 2}, '(a,*)')` yields `('a', 1)`, `('b', 2)`. Pass
295
- `duplicates=True` for the old behavior. See [Walk](#walk).
310
+ `duplicates=True` for the old behavior. See [Ipluck](#ipluck).
296
311
 
297
312
  ### v0.53.0
298
313
  - **`!` negates the whole path.** `!(metadata.*)` yields everything
@@ -496,6 +511,89 @@ so the caller never has to ask which kind of path it holds.
496
511
  >>> list(dotted.iget({'a': 1}, 'b', default=0))
497
512
  [0]
498
513
 
514
+ <a id="streaming-reads"></a>
515
+ ### Streaming reads
516
+
517
+ `iget`, `ipluck` and `iexpand`, and their `_multi` forms, are **streaming
518
+ reads**. Where `get` looks items up (`__getitem__`), a streaming read's
519
+ pattern iterates what it reads and yields one match at a time. So it reads
520
+ through a one-shot iterator too (a generator, a `map`, a cursor), drawing
521
+ from it only as far as it is asked:
522
+
523
+ >>> rows = iter([{'x': 1, 'y': 'a'}, {'x': 2, 'y': 'b'}, {'x': 1, 'y': 'c'}])
524
+ >>> list(dotted.iget({'rows': rows}, 'rows[*&x=1].y'))
525
+ ['a', 'c']
526
+
527
+ `get`, `has`, `pluck`, `expand` and the writes never read an iterator: to
528
+ them it is a value like any other, and it is left untouched.
529
+
530
+ >>> rows = iter([{'y': 1}, {'y': 2}])
531
+ >>> dotted.get({'rows': rows}, 'rows[*].y')
532
+ ()
533
+ >>> list(rows)
534
+ [{'y': 1}, {'y': 2}]
535
+
536
+ A slice of an iterator is an `islice` of it, one value, as a slice of a list
537
+ is a list; `[*]` then reads it, no further than the slice's bound. A slice
538
+ filter of one is likewise a generator of the items that pass.
539
+
540
+ >>> list(dotted.iget({'rows': iter([1, 2, 3, 4])}, 'rows[:2][*]'))
541
+ [1, 2]
542
+ >>> list(dotted.iget({'rows': iter([{'x': 1}, {'x': 2}])}, 'rows[x=2][*].x'))
543
+ [2]
544
+
545
+ What an iterator cannot answer does not match: an index (`rows[0]`), or a
546
+ slice from its end (`rows[-2:]`, `rows[::-1]`). It is not drawn from.
547
+
548
+ >>> list(dotted.iget({'rows': iter([1, 2])}, 'rows[0]', default='none'))
549
+ ['none']
550
+
551
+ `ipluck` and `iexpand` number an iterator's items by position, the paths a
552
+ list of the same items would have, so `pack` rebuilds from the pairs:
553
+
554
+ >>> rows = iter([{'y': 1}, {'y': 2}])
555
+ >>> list(dotted.ipluck({'rows': rows}, 'rows[*].y'))
556
+ [('rows[0].y', 1), ('rows[1].y', 2)]
557
+
558
+ An iterator is read once. A path that reaches the same one twice finds it
559
+ empty the second time, so group below it, not across it:
560
+
561
+ >>> rows = lambda: iter([{'a': 1, 'b': 2}, {'a': 3, 'b': 4}])
562
+ >>> list(dotted.iget({'rows': rows()}, 'rows[*](.a, .b)'))
563
+ [1, 2, 3, 4]
564
+ >>> list(dotted.iget({'rows': rows()}, '(rows[*].a, rows[*].b)'))
565
+ [1, 3]
566
+
567
+ A recursive pattern enters an iterator as it enters a list, and reads it to
568
+ its end before it yields. The matches are the same; the read is not lazy
569
+ there.
570
+
571
+ >>> d = {'a': {'rows': iter([{'y': 1}, {'y': 2}])}}
572
+ >>> list(dotted.iget(d, '*(*#, [*]).y'))
573
+ [1, 2]
574
+
575
+ A set is not read: it has no order, so its items have no positions to be
576
+ their paths.
577
+
578
+ >>> list(dotted.iget({'s': {1, 2}}, 's[*]'))
579
+ []
580
+
581
+ A dict-like is read through its own `items()`, in one pass, when it has
582
+ one, else through each key it iterates; a sequence or iterator through its
583
+ `__iter__`; anything else by index, as `get` reads it. For a lazy mapping
584
+ of your own, a lazy `items()` is the interface to implement.
585
+
586
+ `iget_multi` reads several paths as one flat stream of values, and
587
+ `ipluck_multi` and `iexpand_multi` are `pluck_multi` and `expand_multi` as
588
+ streaming reads. The paths of one call read the same object, so an iterator
589
+ one path has read is empty for the next, as it is for the next call:
590
+
591
+ >>> d = {'name': 'orders', 'rows': iter([{'y': 1}, {'y': 2}])}
592
+ >>> list(dotted.iget_multi(d, ['name', 'rows[*].y']))
593
+ ['orders', 1, 2]
594
+ >>> list(dotted.ipluck_multi(d, ['name', 'rows[*].y']))
595
+ [('name', 'orders')]
596
+
499
597
  <a id="update"></a>
500
598
  ### Update
501
599
 
@@ -824,13 +922,14 @@ Expand a pattern into all matching paths in an object.
824
922
  >>> dotted.expand(d, '*.*[1:]')
825
923
  ('hello.there[1:]',)
826
924
 
827
- A path the pattern reaches more than once is given once; pass
828
- `duplicates=True` to keep each. `iexpand` is `expand` as a generator.
925
+ A path the pattern reaches more than once is given each time; pass
926
+ `unique=True` for each path once. `iexpand` is `expand` as a generator, and
927
+ a [streaming read](#streaming-reads).
829
928
 
830
929
  >>> dotted.expand(d, '(bye,*)')
831
- ('bye', 'hello')
832
- >>> dotted.expand(d, '(bye,*)', duplicates=True)
833
930
  ('bye', 'hello', 'bye')
931
+ >>> dotted.expand(d, '(bye,*)', unique=True)
932
+ ('bye', 'hello')
834
933
  >>> list(dotted.iexpand(d, '*'))
835
934
  ['hello', 'bye']
836
935
 
@@ -918,20 +1017,20 @@ Extract (path, value) pairs from an object matching a pattern.
918
1017
  >>> dotted.pluck(d, 'nested.*')
919
1018
  (('nested.x', 10),)
920
1019
 
921
- A path the pattern reaches more than once is given once; pass
922
- `duplicates=True` to keep each.
1020
+ A path the pattern reaches more than once is given each time; pass
1021
+ `unique=True` for each path once.
923
1022
 
924
1023
  >>> dotted.pluck(d, '(a,*)')
925
- (('a', 1), ('b', 2), ('nested', {'x': 10}))
926
- >>> dotted.pluck(d, '(a,*)', duplicates=True)
927
1024
  (('a', 1), ('a', 1), ('b', 2), ('nested', {'x': 10}))
1025
+ >>> dotted.pluck(d, '(a,*)', unique=True)
1026
+ (('a', 1), ('b', 2), ('nested', {'x': 10}))
928
1027
 
929
- <a id="walk"></a>
930
- ### Walk
1028
+ <a id="ipluck"></a>
1029
+ ### Ipluck
931
1030
 
932
1031
  `ipluck` is `pluck` as a generator — it yields `(path, value)` pairs without
933
1032
  materializing the full result, for a concrete path as for a pattern. Useful
934
- for streaming or large structures. `walk` is another name for it.
1033
+ for streaming or large structures: it is a [streaming read](#streaming-reads).
935
1034
 
936
1035
  >>> import dotted
937
1036
  >>> d = {'a': {'b': 1, 'c': 2}, 'x': 3}
@@ -939,7 +1038,7 @@ for streaming or large structures. `walk` is another name for it.
939
1038
  [('a.b', 1), ('a.c', 2)]
940
1039
  >>> list(dotted.ipluck(d, 'a.b'))
941
1040
  [('a.b', 1)]
942
- >>> for path, val in dotted.walk(d, '*'):
1041
+ >>> for path, val in dotted.ipluck(d, '*'):
943
1042
  ... print(f'{path} = {val}')
944
1043
  a = {'b': 1, 'c': 2}
945
1044
  x = 3
@@ -958,6 +1057,13 @@ reconstruct the original object.
958
1057
  >>> dotted.pack(dotted.unpack(d)) == d
959
1058
  True
960
1059
 
1060
+ A one-shot iterator is a leaf: `unpack` does not read it, and it is in the
1061
+ normal form as itself. See [Streaming reads](#streaming-reads).
1062
+
1063
+ >>> rows = iter([{'y': 1}])
1064
+ >>> dotted.unpack({'name': 'orders', 'rows': rows}) == {'name': 'orders', 'rows': rows}
1065
+ True
1066
+
961
1067
  Pass `attrs=` to also descend into object attributes. The `Attrs` enum controls
962
1068
  which attributes are included:
963
1069
 
@@ -1139,8 +1245,9 @@ produce `[]`.
1139
1245
 
1140
1246
  Most operations have `*_multi` variants for batch processing:
1141
1247
 
1142
- **Note:** The read-side `_multi` APIs — `get_multi`, `match_multi`, `expand_multi`,
1143
- `pluck_multi`, `walk_multi`, `translate_multi`, `assemble_multi`, and
1248
+ **Note:** The read-side `_multi` APIs — `get_multi`, `iget_multi`, `match_multi`,
1249
+ `expand_multi`, `iexpand_multi`, `pluck_multi`, `ipluck_multi`,
1250
+ `translate_multi`, `assemble_multi`, and
1144
1251
  `setdefault_multi` — return a **generator**, not a list or tuple. Consume with
1145
1252
  `list()` / `tuple()` / `for`. The write-side `_multi` APIs (`update_multi`,
1146
1253
  `remove_multi`, `build_multi`, `apply_multi`, etc.) return the mutated object.
@@ -1167,7 +1274,8 @@ before a full traversal completes.
1167
1274
 
1168
1275
  Available multi operations: `get_multi`, `update_multi`, `update_if_multi`, `remove_multi`,
1169
1276
  `remove_if_multi`, `setdefault_multi`, `match_multi`, `expand_multi`, `apply_multi`,
1170
- `build_multi`, `pluck_multi`, `walk_multi`, `assemble_multi`.
1277
+ `build_multi`, `pluck_multi`, `assemble_multi`, and the streaming `iget_multi`,
1278
+ `iexpand_multi`, `ipluck_multi`.
1171
1279
 
1172
1280
  <a id="strict-mode"></a>
1173
1281
  ### Strict Mode
@@ -1667,7 +1775,7 @@ See [Replace](#replace) and [Translate](#translate) for full API details.
1667
1775
  <a id="template-bindings"></a>
1668
1776
  ### Template bindings
1669
1777
 
1670
- All traversal APIs — `get`, `update`, `remove`, `has`, `walk`, `expand`, `pluck`,
1778
+ All traversal APIs — `get`, `update`, `remove`, `has`, `ipluck`, `expand`, `pluck`,
1671
1779
  `apply`, `build`, `mutable`, `setdefault`, and their multi variants — accept a
1672
1780
  `bindings=` keyword argument to resolve template paths inline:
1673
1781
 
@@ -2032,7 +2140,11 @@ Here `*:dict` keeps the values that are dicts, and `.*` continues into them.
2032
2140
  The list and string are dropped.
2033
2141
 
2034
2142
  Supported types: `str`, `bytes`, `int`, `float`, `dict`, `list`, `tuple`,
2035
- `set`, `frozenset`, `bool`.
2143
+ `set`, `frozenset`, `bool`, and `iter`, a one-shot iterator (a generator, a
2144
+ `map`, a cursor):
2145
+
2146
+ >>> dotted.get({'rows': iter([1, 2]), 'tags': ['a']}, '*:!iter')
2147
+ (['a'],)
2036
2148
 
2037
2149
  <a id="positive-restrictions"></a>
2038
2150
  ### Positive restrictions
@@ -2504,7 +2616,7 @@ aggregate over the item:
2504
2616
  >>> dotted.get(d, 'items[*&(p[*];)|len=0]')
2505
2617
  ({'p': []},)
2506
2618
 
2507
- A pack is its own path segment: `walk` and `expand` give it back as
2619
+ A pack is its own path segment: `ipluck` and `expand` give it back as
2508
2620
  written, `(a.*;)|sum`. There is nothing under a tuple of matches to write
2509
2621
  to, so `update` and `remove` through a pack raise `ValueError`, and a pack
2510
2622
  cannot be negated. `;` is a reserved character; quote a key that contains
@@ -3902,6 +4014,13 @@ Python's `in` tells. For a column path it is the assignments, for an
3902
4014
  >>> args[-1]
3903
4015
  '"admin"'
3904
4016
 
4017
+ A group writes as `update` does: `(a, b)` each branch where it
4018
+ matches, on the node the branches before it wrote, the last concrete
4019
+ one built where none does; `(a&b)` every branch, where each matches or
4020
+ can be built; `(a, b)?` the first that matches; and a cut ends the
4021
+ branches after one that matched, so `emails[(*&email="x"#, +)]` writes
4022
+ the email that's there, else appends one.
4023
+
3905
4024
  A value is a literal, sent as a parameter, or a `Raw` / `Col` SQL
3906
4025
  expression. A transform at the end of the path, `data.user.age|int`,
3907
4026
  applies to a literal value, as dotted's does; on a SQL expression it
@@ -3913,7 +4032,8 @@ Not yet supported (`TranslationError`):
3913
4032
  - Regex keys, `data./prefix_\d+/.field`; references inside pattern
3914
4033
  paths; a `**` with depths or accessors; first filters, `[*&a=1?]`
3915
4034
  - Transforms other than `int`, `float` and `str`, or with arguments
3916
- - In a write: groups, `!`, `**` and slices; a table search
4035
+ - In a write: a soft cut, `!`, `**` and slices; a group at the top of
4036
+ a path; a table search
3917
4037
 
3918
4038
  <a id="sqlize-table-search"></a>
3919
4039
  ### `sqlize` table search
@@ -4183,8 +4303,8 @@ A `SQLFragment` carries:
4183
4303
  - Returns a `SQLFragment`: for a column path, the assignments for an
4184
4304
  `UPDATE ... SET`, each column's new value as dotted's `update` writes
4185
4305
  `value` at the path's matches (see *Writes* above). Build it with
4186
- `r.build`. A table search, and groups, `!`, `**` and slices in the
4187
- path, raise `TranslationError`.
4306
+ `r.build`. A table search, and a soft cut, `!`, `**` and slices in
4307
+ the path, raise `TranslationError`.
4188
4308
 
4189
4309
  The `Resolver.build(sql, paramstyle='...', **bindings)` classmethod is
4190
4310
  retained as a low-level escape hatch that takes an explicit paramstyle
@@ -4362,6 +4482,47 @@ A `Column` can't hold a placeholder, so `r.where` is a
4362
4482
  b = dotted.sparkize('status = "active"')
4363
4483
  df.where(a.build(a.where & b.where, schema=df.schema, min_age=30))
4364
4484
 
4485
+ ### Writes (`as_update`)
4486
+
4487
+ `r.as_update(value)` is the write of `value` at the path's matches, as
4488
+ dotted's `update` does it, and as `sqlize`'s `as_update` writes it.
4489
+ `build` makes it a dict of each column the write touches to its new
4490
+ value, for `df.withColumns`:
4491
+
4492
+ r = dotted.sparkize('data.user.role')
4493
+ df = df.withColumns(r.build(r.as_update('admin'), schema=df.schema))
4494
+
4495
+ The write is:
4496
+ - `value` at each match;
4497
+ - along literal keys and slots, the nodes the path lacks built, a null
4498
+ one replaced, as dotted builds them, and a slot past the end
4499
+ appending;
4500
+ - a pattern, filter or guard writing only what is there and passes;
4501
+ - `~` holding a segment back;
4502
+ - `[+]` appending, and `[+?]` where the list doesn't hold the value, as
4503
+ Python's `in` tells.
4504
+
4505
+ A value is a literal, or a `Column`, read by its type; a transform at
4506
+ the end of the path applies to a literal. A struct's field takes the
4507
+ written value's type; a map's values, and a list's elements, share
4508
+ one. Where Spark can't hold what dotted writes, the job fails, with a
4509
+ `dotted update: …` message, where a row has it:
4510
+ - a null struct, which dotted makes a dict of only the keys the path
4511
+ names;
4512
+ - a field added to some of a list's structs and not to others;
4513
+ - a str written among a map's ints.
4514
+
4515
+ A group writes as dotted's `update` does, as in `sqlize`: `(a, b)` each branch where it
4516
+ matches, on the node the branches before it wrote, the last concrete
4517
+ one built where none does; `(a&b)` every branch, where each matches or
4518
+ can be built; `(a, b)?` the first that matches; and a cut ends the
4519
+ branches after one that matched, so `emails[(*&email="x"#, +)]` writes
4520
+ the email that's there, else appends one.
4521
+
4522
+ So does a write where dotted's update raises: a key on a list, an
4523
+ index before its start. A slot on a str, which dotted writes, fails
4524
+ too for now, as in `sqlize` (#75).
4525
+
4365
4526
  <a id="sparkize-table-search"></a>
4366
4527
  ### `sparkize` table search
4367
4528
 
@@ -4406,7 +4567,8 @@ Not yet supported (`TranslationError`):
4406
4567
  - Comparing a `DECIMAL` with a float `Column`; `str()` or a regex of a
4407
4568
  timestamp, whose Python value depends on the session's time zone;
4408
4569
  reading into a binary value
4409
- - Writes
4570
+ - In a write: a soft cut, `!`, `**` and slices; a group at the top of
4571
+ a path; a table search; a column the schema lacks
4410
4572
 
4411
4573
  ### API reference
4412
4574
 
@@ -4425,13 +4587,21 @@ Not yet supported (`TranslationError`):
4425
4587
  `r.build(fragment, schema=None, **bindings)`
4426
4588
 
4427
4589
  - `fragment` — a `ColumnFragment` (`r.where`, `r.select`, or a
4428
- composition of fragments).
4590
+ composition of fragments), or `r.as_update(value)`, which builds to a
4591
+ dict of column name to `Column`.
4429
4592
  - `schema` — **required**. The schema of the DataFrame the Column
4430
4593
  reads, `df.schema`: a path reads each node by its type.
4431
4594
  - `**bindings` — values for substitutions, keyed by original
4432
4595
  substitution name. An unknown or missing binding raises
4433
4596
  `TranslationError`.
4434
4597
 
4598
+ `r.as_update(value)`
4599
+
4600
+ - `value` — a literal, or a Spark `Column`, read by its type.
4601
+ - Returns a fragment `build` makes into a dict of each column the write
4602
+ touches, by name, to its new value, for `df.withColumns` (see
4603
+ *Writes* above).
4604
+
4435
4605
  Translation never imports pyspark; only `build` does.
4436
4606
 
4437
4607
  <a id="constants-and-exceptions"></a>