Merge grids by column name

If grids have one (only one) common column you can use join (for 2 grids) or joinAll (for list of grids)

Join example:

There are grid1 and grid2 with common column col2. To get one merged by col2 grid use join function.

joinTwoGridsByCommonCol.axon
  () => do
  grid1: [{"col1": 5, "col2":15},
  {"col1": 1, "col2":11},
  {"col1": 4, "col2":14},
  {"col1": 2, "col2":12},
  {"col1": 3, "col2":13}].toGrid
  
  grid2: [{"col3": 25, "col2":15},
  {"col3": 21, "col2":11},
  {"col3": 24, "col2":14},
  {"col3": 22, "col2":12},
  {"col3": 23, "col2":13}].toGrid
  
  resultGrid: grid1.join(grid2,"col2")
end

Result is one grid joined by col2:

joinAll example:

There are grid1, grid2 and grid3 with common column col2. To get one merged by col2 grid use joinAll function.

joinListOfGridsByCommonCol.axon
  () => do
  grid1: [{"col1": 5, "col2":15},
  {"col1": 1, "col2":11},
  {"col1": 4, "col2":14},
  {"col1": 2, "col2":12},
  {"col1": 3, "col2":13}].toGrid
  
  grid2: [{"col3": 25, "col2":15},
  {"col3": 21, "col2":11},
  {"col3": 24, "col2":14},
  {"col3": 22, "col2":12},
  {"col3": 23, "col2":13}].toGrid
  
  grid3: [{"col4": 35, "col2":15},
  {"col4": 31, "col2":11},
  {"col4": 34, "col2":14},
  {"col4": 32, "col2":12},
  {"col4": 33, "col2":13}].toGrid
  
  resultGrid: joinAll([grid1,grid2,grid3],"col2")
end

Result is one grid joined by col2:

Merge grids without common column

To merge grids without common column you can convert them to lists and use addAll(). Then convert result back to grid.

joinListOfGridsByCommonCol.axon
  () => do
  grid1: [{"col1": 5, "col2":15},
  {"col1": 1, "col2":11},
  {"col1": 4, "col2":14},
  {"col1": 2, "col2":12},
  {"col1": 3, "col2":13}].toGrid
  
  grid2: [{"col3": 5, "col4":15},
  {"col3": 1, "col4":11},
  {"col3": 4, "col4":14},
  {"col3": 2, "col4":12},
  {"col3": 3, "col4":13}].toGrid
  
  resultGrid: grid1.toRecList.addAll(grid2.toRecList)
end

Result is one grid:



  • No labels