DocsWorkflowsComponentsDatadata:list:compare

data:list:compare

Sorts two lists of items into buckets by comparing them key by key. Items pair up through the configured key paths, so the two lists may name the same thing differently. A pair whose compared values all agree is the same. A pair whose values disagree is classified against the base, which is git's three-way merge question and the only reason a base is accepted at all. The side that still equals the base did not move, so a pair lands in a_moved, b_moved or both_moved and a caller reads the merge policy straight off the bucket name instead of re-deriving it a step later. A pair with no base for its key is different, since nothing there says which side moved. Every bucket is emitted in key order and nothing is written anywhere.

Options

NameTypeDescription
a[]map[string]anyThe first list of items
b[]map[string]anyThe second list of items
base[]map[string]anyThe shared ancestor both lists were derived from
keys[]CompareFieldThe paths whose values identify the same item in each list
  ↳ astringThe dotted path read from list A
  ↳ bstringThe dotted path read from list B
  ↳ basestringThe dotted path read from the base list
compare[]CompareFieldThe paths whose values decide whether two paired items are the same
  ↳ astringThe dotted path read from list A
  ↳ bstringThe dotted path read from list B
  ↳ basestringThe dotted path read from the base list

Outputs

NameTypeDescription
only_in_a[]CompareItemThe items whose key appears in A and not in B
  ↳ key[]anyThe identifying values read through the configured key paths
  ↳ itemmap[string]anyThe item as it appears in its own list
only_in_b[]CompareItemThe items whose key appears in B and not in A
  ↳ key[]anyThe identifying values read through the configured key paths
  ↳ itemmap[string]anyThe item as it appears in its own list
same[]ComparePairThe paired items whose compared values all agree
  ↳ key[]anyThe identifying values read through the configured key paths
  ↳ amap[string]anyThe item as it appears in list A
  ↳ bmap[string]anyThe item as it appears in list B
  ↳ basemap[string]anyThe item as it appears in the base list
different[]ComparePairThe paired items whose compared values disagree and that have no base to say which side moved
  ↳ key[]anyThe identifying values read through the configured key paths
  ↳ amap[string]anyThe item as it appears in list A
  ↳ bmap[string]anyThe item as it appears in list B
  ↳ basemap[string]anyThe item as it appears in the base list
a_moved[]ComparePairThe paired items where A moved away from the base and B did not
  ↳ key[]anyThe identifying values read through the configured key paths
  ↳ amap[string]anyThe item as it appears in list A
  ↳ bmap[string]anyThe item as it appears in list B
  ↳ basemap[string]anyThe item as it appears in the base list
b_moved[]ComparePairThe paired items where B moved away from the base and A did not
  ↳ key[]anyThe identifying values read through the configured key paths
  ↳ amap[string]anyThe item as it appears in list A
  ↳ bmap[string]anyThe item as it appears in list B
  ↳ basemap[string]anyThe item as it appears in the base list
both_moved[]ComparePairThe paired items where both sides moved away from the base
  ↳ key[]anyThe identifying values read through the configured key paths
  ↳ amap[string]anyThe item as it appears in list A
  ↳ bmap[string]anyThe item as it appears in list B
  ↳ basemap[string]anyThe item as it appears in the base list
countsListCompareCountsThe size of every bucket
  ↳ only_in_aint
  ↳ only_in_bint
  ↳ sameint
  ↳ differentint
  ↳ a_movedint
  ↳ b_movedint
  ↳ both_movedint

Example

name: Compare a product list against the store
actions:
  - name: changes
    component: data:list:compare
    vars:
      a: "{{ var.products }}"
      b: "{{ var.store }}"
      keys:
        - a: sku
          b: product_sku
      compare:
        - a: price
          b: unit_price

outputs:
  only_in_a: "{{ changes.only_in_a }}"
  only_in_b: "{{ changes.only_in_b }}"
  different: "{{ changes.different }}"
  counts: "{{ changes.counts }}"