Merging two lists of maps

I currently have two list data.

data1 = [%{id: "111", name: "name1"},
           %{id: "222", name: "name2"},
           %{id: "333", name: "name3"},
           %{id: "444", name: "name4"}
          ]

data2 = [
  %{
    mapData: %{
      "111": "data1.com",
      "222": "data2.com",
      "333": "data3.com",
    }
  },
  %{
      mapData: %{
        "111": "data11.com",
        "222": "data22.com",
      },
      mapData: %{
        "111": "data111.com"
      }

  }
]

Now I want to obtain data in this format.

 [
           %{id: "111", name: "name1",address:"data1.com"},
           %{id: "111", name: "name1",address:"data11.com"},
           %{id: "111", name: "name1",address:"data111.com"},
           %{id: "222", name: "name2",address:"data2.com"},
           %{id: "222", name: "name22",address:"data22.com"},
           %{id: "333", name: "name3",address:"data3com"},
           %{id: "444", name: "name4",address:""}
          ]

I don’t know how to implement it now.I am a beginner and I hope everyone can help me. Thank you.

Could you please post the sample data exactly the way you have it? From this example it’s not clear why in data2 the keys are quoted atoms ("111": ...) and not usual string keys ("111" => ...) and whether this is intentional.

Regardless, you could look for something like this:

iex(39)> for %{id: id, name: name} <- data1,
             %{mapData: m2} <- data2,
             is_map_key(m2, String.to_atom(id)),
             do: %{id: id, name: name, address: m2[String.to_atom(id)]} 
[
  %{address: "data1.com", id: "111", name: "name1"},
  %{address: "data111.com", id: "111", name: "name1"},
  %{address: "data2.com", id: "222", name: "name2"},
  %{address: "data3.com", id: "333", name: "name3"}
]
2 Likes

It will help if you give little more context about what exactly do you want to achieve. That way people can give you better solutions.

So you want to match everything from data1 with the name field from data2, but how exactly? They don’t seem to have anything in common, so nothing to refer to. Or do you want to just match them by the order in the lists?

Copying these over from the Elixir chat room.

Originally sent in Elixir Chat
zhanjingbaobao

I currently have two list data.

data1 = [
  %{id: "111", name: "name1"},
  %{id: "222", name: "name2"},
  %{id: "333", name: "name3"},
  %{id: "444", name: "name4"}
]

data2 = [
  %{
    mapData: %{
      "111": "data1",
      "222": "data2_test",
      "333": "data3_test"
    }
  },
  %{
    mapData: %{
      "111": "data11_test",
      "222": "data22_test"
    },
    mapData: %{
      "111": "data111_test"
    }
  }
]

# Now I want to obtain data in this format.
mergeData = [
  %{id: "111", name: "name1", address: "data1_test"},
  %{id: "111", name: "name1", address: "data11_test"},
  %{id: "111", name: "name1", address: "data111_test"},
  %{id: "222", name: "name2", address: "data2_test"},
  %{id: "222", name: "name22", address: "data22_test"},
  %{id: "333", name: "name3", address: "data3_test"},
  %{id: "444", name: "name4", address: ""}
]

I don't know how to implement it now.I am a beginner and I hope everyone can help me. Thank you.

Eiji

Your data2 map is invalid as it's keys are not unique and therefore only last would be used.

There are 2 other issues … In data2 the first 111 have data1 address, but should have data1_test. In mergeData you have name22 instead of name2.

After applying all fixed this is a final example code:

defmodule Example do
  def sample(data, addresses) when is_list(data) and is_list(addresses) do
    # a list of addressess
    flat_addresses =
      addresses
      # reduce it with an empty list
      |> Enum.reduce([], fn %{mapData: addresses}, acc ->
        # take a map value under mapData key
        addresses
        # change atom id to string
        |> Enum.map(fn {id, address} -> {Atom.to_string(id), address} end)
        # concat the result with acc
        |> then(&(acc ++ &1))
      end)
      # the original addresses are sorted partially i.e. only in specified mapData
      # to fix that we simply need to sort the flat list result by id
      |> Enum.sort_by(&elem(&1, 0))

    # in order to recursively pattern match key by key we need to change a list of maps
    # to a map with id as key and name as value
    data |> Enum.map(&{&1.id, &1.name}) |> merge(flat_addresses)
  end

  # function head is required when using a default argument(s)
  # in functions with multiple clasule
  defp merge(data, addresses, last_matched \\ false)

  # when done simply finish a recursive call returning an empty list as result tail
  defp merge([], [], _last_matched), do: []

  # if id matches add a new map to result and continue with same data and the rest of addresses
  defp merge([{id, name} | _data_tail] = data, [{id, address} | addresses], _last_matched) do
    [%{address: address, id: id, name: name} | merge(data, addresses, true)]
  end

  # if id does not match and previous clause matched for this id
  # we simply continue with rest of data and same addresses
  defp merge([_data_head | data], addresses, true), do: merge(data, addresses, false)

  # otherwise if id still does not match and previous clause do not matched for this id even once
  # add a new map with an empty address and continue with rest of data and same addresses
  # the combination of last_matched boolean argument and this clause
  # is required in case we do not have any addresses for specific data like it is for "444" id 
  defp merge([{id, name} | data], addresses, false) do
    [%{address: "", id: id, name: name} | merge(data, addresses, false)]
  end
end

data = [
  %{id: "111", name: "name1"},
  %{id: "222", name: "name2"},
  %{id: "333", name: "name3"},
  %{id: "444", name: "name4"}
]

addresses = [
  %{
    mapData: %{
      # fix: "data1" -> "data1_test"
      "111": "data1_test",
      "222": "data2_test",
      "333": "data3_test"
    }
  },
  # fix: split map wih duplicate keys into two separate maps
  %{
    mapData: %{
      "111": "data11_test",
      "222": "data22_test"
    }
  },
  %{
    mapData: %{
      "111": "data111_test"
    }
  }
]

expected = [
  %{id: "111", name: "name1", address: "data1_test"},
  %{id: "111", name: "name1", address: "data11_test"},
  %{id: "111", name: "name1", address: "data111_test"},
  %{id: "222", name: "name2", address: "data2_test"},
  # fix: "name22" -> "name2"
  %{id: "222", name: "name2", address: "data22_test"},
  %{id: "333", name: "name3", address: "data3_test"},
  %{id: "444", name: "name4", address: ""}
]

iex> Example.sample(data, addresses) == expected
true
zhanjingbaobao

Thank you very much Eiji,but when I tested the code, I didn't get the data structure I expected.

I have two pieces of data: data1 and data2,

data1 = [
  %{
    channelId: "1",
    describtion: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"}
  },
  %{
    channelId: "2",
    describtion: "dev-test_002",
    tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"}
  },
  %{
    channelId: "3",
    describtion: "dev-test_003",
    tags: %{pipelineId: "1003", pipelineTemplate: "live-drm"}
  },
  %{
    channelId: "4",
    describtion: "dev-test_004",
    tags: %{pipelineId: "1004", pipelineTemplate: "live-drm"}
  }
]

data2 = [
  %{
    mediaTailoId: %{"1": "channel1_data", "2": "channel2_dadta", "3": "channel3_dadta"},
    mediaTailorRegion: "us-east-1",
    name: "testName1"
  },
  %{
    mediaTailoId: %{"1": "channel1_data", "2": "channel2_dadta"},
    mediaTailorRegion: "us-east-2",
    name: "testName2"
  },
  %{mediaTailoId: %{"1": "channel1_data"}, mediaTailorRegion: "us-east-3", name: "testName3"}
]

Here are my expected data.Expected results do not need to be sorted, as long as the content can be aligned.

expect_data = [
  %{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"},
    name: "testName1"
  },
  %{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"},
    name: "testName2"
  },
  %{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"},
    name: "testName3"
  },
  %{
    channelId: "2",
    description: "dev-test_002",
    tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"},
    name: "testName1"
  },
  %{
    channelId: "2",
    description: "dev-test_002",
    tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"},
    name: "testName2"
  },
  %{
    channelId: "3",
    describtion: "dev-test_003",
    tags: %{pipelineId: "1003", pipelineTemplate: "live-drm"},
    name: "testName2"
  },
  %{
    channelId: "4",
    describtion: "dev-test_004",
    tags: %{pipelineId: "1004", pipelineTemplate: "live-drm"},
    name: ""
  }
]

Thank you for reading this message.

Eiji

Again, you had issues in your data. Firstly there is descri**b**tion instead of descri**p**tion. Secondly 2nd last expected map should have name testName1 instead of testName2.

Here goes the complete example with fixed data:

defmodule Example do
  def sample(data, names) when is_list(data) and is_list(names) do
    # a list of names
    # reduce it with an empty list
    flat_names =
      Enum.reduce(names, [], fn %{mediaTailoId: ids_map, name: name}, acc ->
        # take a map value under mapData key
        ids_map
        # change atom id to string
        |> Enum.map(fn {id, _value} -> {Atom.to_string(id), name} end)
        # concat the result with acc
        |> then(&(acc ++ &1))
      end)
      # the original names are sorted partially i.e. only in specified mediaTailoId
      # to fix that we simply need to sort the flat list result by id
      |> Enum.sort_by(&elem(&1, 0))

    # in order to recursively pattern match key by key we need to change a list of maps
    # to a map with id as key and name as value
    data |> Enum.map(&{&1.channelId, &1}) |> merge(flat_names)
  end

  # function head is required when using a default argument(s)
  # in functions with multiple clasule
  defp merge(data, names, last_matched \\ false)

  # when done simply finish a recursive call returning an empty list as result tail
  defp merge([], [], _last_matched), do: []

  # if id matches add a new map to result and continue with same data and the rest of names
  defp merge([{id, map} | _data_tail] = data, [{id, name} | names], _last_matched) do
    [Map.merge(map, %{name: name}) | merge(data, names, true)]
  end

  # if id does not match and previous clause matched for this id
  # we simply continue with rest of data and same names
  defp merge([_data_head | data], names, true), do: merge(data, names, false)

  # otherwise if id still does not match and previous clause do not matched for this id even once
  # add a new map with an empty name and continue with rest of data and same names
  # the combination of last_matched boolean argument and this clause
  # is required in case we do not have any names for specific data like it is for "444" id 
  defp merge([{_id, map} | data], names, false) do
    [Map.merge(map, %{name: ""}) | merge(data, names, false)]
  end
end

data1 = [
  %{
    channelId: "1",
    # fix: describtion -> description
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"}
  },
  %{
    channelId: "2",
    # fix: describtion -> description
    description: "dev-test_002",
    tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"}
  },
  %{
    channelId: "3",
    # fix: describtion -> description
    description: "dev-test_003",
    tags: %{pipelineId: "1003", pipelineTemplate: "live-drm"}
  },
  %{
    channelId: "4",
    # fix: describtion -> description
    description: "dev-test_004",
    tags: %{pipelineId: "1004", pipelineTemplate: "live-drm"}
  }
]

data2 = [
  %{
    mediaTailoId: %{"1": "channel1_data", "2": "channel2_dadta", "3": "channel3_dadta"},
    mediaTailorRegion: "us-east-1",
    name: "testName1"
  },
  %{
    mediaTailoId: %{"1": "channel1_data", "2": "channel2_dadta"},
    mediaTailorRegion: "us-east-2",
    name: "testName2"
  },
  %{mediaTailoId: %{"1": "channel1_data"}, mediaTailorRegion: "us-east-3", name: "testName3"}
]

expect_data = [
  %{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"},
    name: "testName1"
  },
  %{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"},
    name: "testName2"
  },
  %{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"},
    name: "testName3"
  },
  %{
    channelId: "2",
    description: "dev-test_002",
    tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"},
    name: "testName1"
  },
  %{
    channelId: "2",
    description: "dev-test_002",
    tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"},
    name: "testName2"
  },
  %{
    channelId: "3",
    description: "dev-test_003",
    tags: %{pipelineId: "1003", pipelineTemplate: "live-drm"},
    # fix: "testName2" -> "testName1" 
    name: "testName1"
  },
  %{
    channelId: "4",
    description: "dev-test_004",
    tags: %{pipelineId: "1004", pipelineTemplate: "live-drm"},
    name: ""
  }
]

iex> Example.sample(data1, data2) == expect_data
true

@AstonJ Could you please move our messages to a separate topic, please?

Note: Fixed code formatting.

1 Like

Reminds me of this How to merge two list with maps based on particular key

And the person on SO asking the same thing. Just has mapData instead of price.

When I verified the code, I found that true could not be printed out, and the print result:

%{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"}
  },
  %{
    channelId: "2",
    description: "dev-test_002",
    tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"}
  },
  %{
    channelId: "3",
    description: "dev-test_003",
    tags: %{pipelineId: "1003", pipelineTemplate: "live-drm"}
  },
  %{
    channelId: "4",
    description: "dev-test_004",
    tags: %{pipelineId: "1004", pipelineTemplate: "live-drm"}
  }
]
false

I use the channelID of data1 to match any key of mediaTailoId in data2. If the match is successful, data1 will add a new piece of data. The data of id=1 in data1 appears three times in data2, so there are three id=1 in the final result I generated, and the name of each is the name of data2. id=4 does not have any matching records in data2, so name=“”.My code,but it doeson’t work.

    data1 = [
      %{channelId: "1", describtion: "dev-test_001", tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"}},
      %{channelId: "2", describtion: "dev-test_002", tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"}},
      %{channelId: "3", describtion: "dev-test_003", tags: %{pipelineId: "1003", pipelineTemplate: "live-drm"}},
      %{channelId: "4", describtion: "dev-test_004", tags: %{pipelineId: "1004", pipelineTemplate: "live-drm"}}
    ]

    data2 = [
      %{mediaTailoId: %{"1": "channel1_data", "2": "channel2_dadta", "3": "channel3_dadta"}, mediaTailorRegion: "us-east-1", name: "testName1"},
      %{mediaTailoId: %{"1": "channel1_data", "2": "channel2_dadta"}, mediaTailorRegion: "us-east-2", name: "testName2"},
      %{mediaTailoId: %{"1": "channel1_data"}, mediaTailorRegion: "us-east-3", name: "testName3"}
    ]
 result1 = Enum.flat_map(data1, fn channel ->
      Enum.map(data2, fn media ->
        IO.inspect(media.mediaTailoId)
        IO.inspect(channel.channelId)
        IO.inspect(Map.get(media.mediaTailoId, :"#{channel.channelId}"))
        if Map.get(media.mediaTailoId, channel.channelId) != nil do
          %{channel | name: media.name}
        else
          %{channel | name: ""}
        end
      end)
    end)
     IO.inspect(result1)

No idea how you got those results. Which code example have you used? Since you give 2 different inputs and expected I wrote two examples. Maybe you have used the wrong one?

If there is a piece of data in data2 that does not match the channelId of data1, there will be an exception. I tried to judge but failed.
For example:

data2 = [
  %{
    mediaTailoId: %{"1": "channel1_data", "2": "channel2_dadta", "3": "channel3_dadta"},
    mediaTailorRegion: "us-east-1",
    name: "testName1"
  },
  %{
    mediaTailoId: %{"1": "channel1_data", "2": "channel2_dadta"},
    mediaTailorRegion: "us-east-2",
    name: "testName2"
  },
  %{mediaTailoId: %{"1": "channel1_data"}, mediaTailorRegion: "us-east-3", name: "testName3"},
  %{mediaTailoId: %{"666": "channel1_data"}, mediaTailorRegion: "us-east-3", name: "testName666"}
]

data1 has not changed,I think the problem should be here, but I failed to modify it successfully, I am very sorry to ask you for help again.

[Map.merge(map, %{name: ""}) | merge(data, names, false)]

Yes, as this was not mentioned originally.

No worries.

No, it’s not. As above you have added a special cases not mentioned before. Here is the current error:

** (FunctionClauseError) no function clause matching in Example.merge/3    
    
    The following arguments were given to Example.merge/3:
    
        # 1
        []
    
        # 2
        [{"666", "testName666"}]
    
        # 3
        false

We can see that we have done with data, but still have extra names list elements. This means that we only need to modify a strict condition that finishes our recursive process i.e.

# in case no extra names we can strictly pattern match here
defp merge([], [], _last_matched), do: []
# in case we do not care about more items in `names` list
defp merge([], _names, _last_matched), do: []

Also I have simplified my example a bit:

defmodule Example do
  def sample(data, names) when is_list(data) and is_list(names) do
    # a list of names
    # reduce it with an empty list
    names
    |> Enum.reduce([], fn %{mediaTailoId: ids_map, name: name}, acc ->
      # take a map value under mapData key
      ids_map
      # change atom id to string
      |> Enum.map(fn {id, _value} -> {Atom.to_string(id), name} end)
      # concat the result with acc
      |> then(&(acc ++ &1))
    end)
    # the original names are sorted partially i.e. only in specified mediaTailoId
    # to fix that we simply need to sort the flat list result by id
    |> Enum.sort_by(&elem(&1, 0))
    |> then(&merge(data, &1))
  end

  # function head is required when using a default argument(s)
  # in functions with multiple clasule
  defp merge(data, names, last_matched \\ false)

  # when done simply finish a recursive call returning an empty list as result tail
  defp merge([], _names, _last_matched), do: []

  # if id matches add a new map to result and continue with same data and the rest of names
  defp merge([%{channelId: id} = map | _data_tail] = data, [{id, name} | names], _last_matched) do
    [Map.merge(map, %{name: name}) | merge(data, names, true)]
  end

  # if id does not match and previous clause matched for this id
  # we simply continue with rest of data and same names
  defp merge([_data_head | data], names, true), do: merge(data, names, false)

  # otherwise if id still does not match and previous clause do not matched for this id even once
  # add a new map with an empty name and continue with rest of data and same names
  # the combination of last_matched boolean argument and this clause
  # is required in case we do not have any names for specific data like it is for "444" id 
  defp merge([map | data], names, false) do
    [Map.merge(map, %{name: ""}) | merge(data, names, false)]
  end
end

data1 = [
  %{
    channelId: "1",
    # fix: describtion -> description
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"}
  },
  %{
    channelId: "2",
    # fix: describtion -> description
    description: "dev-test_002",
    tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"}
  },
  %{
    channelId: "3",
    # fix: describtion -> description
    description: "dev-test_003",
    tags: %{pipelineId: "1003", pipelineTemplate: "live-drm"}
  },
  %{
    channelId: "4",
    # fix: describtion -> description
    description: "dev-test_004",
    tags: %{pipelineId: "1004", pipelineTemplate: "live-drm"}
  }
]

data2 = [
  %{
    mediaTailoId: %{"1": "channel1_data", "2": "channel2_dadta", "3": "channel3_dadta"},
    mediaTailorRegion: "us-east-1",
    name: "testName1"
  },
  %{
    mediaTailoId: %{"1": "channel1_data", "2": "channel2_dadta"},
    mediaTailorRegion: "us-east-2",
    name: "testName2"
  },
  %{mediaTailoId: %{"1": "channel1_data"}, mediaTailorRegion: "us-east-3", name: "testName3"},
  %{mediaTailoId: %{"666": "channel1_data"}, mediaTailorRegion: "us-east-3", name: "testName666"}
]

expect_data = [
  %{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"},
    name: "testName1"
  },
  %{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"},
    name: "testName2"
  },
  %{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"},
    name: "testName3"
  },
  %{
    channelId: "2",
    description: "dev-test_002",
    tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"},
    name: "testName1"
  },
  %{
    channelId: "2",
    description: "dev-test_002",
    tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"},
    name: "testName2"
  },
  %{
    channelId: "3",
    description: "dev-test_003",
    tags: %{pipelineId: "1003", pipelineTemplate: "live-drm"},
    # fix: "testName2" -> "testName1" 
    name: "testName1"
  },
  %{
    channelId: "4",
    description: "dev-test_004",
    tags: %{pipelineId: "1004", pipelineTemplate: "live-drm"},
    name: ""
  }
]

iex> Example.sample(data1, data2) == expect_data
true
3 Likes

I’m joining this thread late and to be honest, have not read all the correction details. I offer another approach with get_in that may or may not be of interest. I like these sorts of data manipulation puzzles though :grin:

iex(11)> data1
[
  %{id: "111", name: "name1"},
  %{id: "222", name: "name2"},
  %{id: "333", name: "name3"},
  %{id: "444", name: "name4"}
]
iex(12)> data2
[
  %{mapData: %{"111": "data1", "222": "data2_test", "333": "data3_test"}},
  %{mapData: %{"111": "data11_test", "222": "data22_test"}},
  %{mapData: %{"111": "data111_test"}}
]
iex(13)> Enum.flat_map(data1, fn %{id: id} = d1 ->
...(13)>   id2 = String.to_atom(id)
...(13)>   addrs = data2 |> get_in([Access.all(), :mapData, id2]) |> Enum.reject(&is_nil/1)
...(13)>   addrs = if addrs == [], do: [""], else: addrs
...(13)>  Enum.map(addrs, &Map.put(d1, :address, &1))
...(13)> end)
[
  %{address: "data1", id: "111", name: "name1"},
  %{address: "data11_test", id: "111", name: "name1"},
  %{address: "data111_test", id: "111", name: "name1"},
  %{address: "data2_test", id: "222", name: "name2"},
  %{address: "data22_test", id: "222", name: "name2"},
  %{address: "data3_test", id: "333", name: "name3"},
  %{address: "", id: "444", name: "name4"}
]
3 Likes

sorry,this is the new data

data1 = [
      %{channelId: "1", describtion: "dev-test_001", tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"}},
      %{channelId: "2", describtion: "dev-test_002", tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"}},
      %{channelId: "3", describtion: "dev-test_003", tags: %{pipelineId: "1003", pipelineTemplate: "live-drm"}},
      %{channelId: "4", describtion: "dev-test_004", tags: %{pipelineId: "1004", pipelineTemplate: "live-drm"}}
    ]

    data2 = [
      %{mediaTailoId: %{"1": "channel1_data", "2": "channel2_dadta", "3": "channel3_dadta"}, mediaTailorRegion: "us-east-1", name: "testName1"},
      %{mediaTailoId: %{"1": "channel1_data", "2": "channel2_dadta"}, mediaTailorRegion: "us-east-2", name: "testName2"},
      %{mediaTailoId: %{"1": "channel1_data"}, mediaTailorRegion: "us-east-3", name: "testName3"}
    ]

On this basis I also want to get the name attribute in data2 as another attribute of data1. I tried without success. Do you have any good suggestions?
my expect_data

expect_data = [
  %{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"},
    name: "testName1"
  },
  %{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"},
    name: "testName2"
  },
  %{
    channelId: "1",
    description: "dev-test_001",
    tags: %{pipelineId: "1001", pipelineTemplate: "live-drm"},
    name: "testName3"
  },
  %{
    channelId: "2",
    description: "dev-test_002",
    tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"},
    name: "testName1"
  },
  %{
    channelId: "2",
    description: "dev-test_002",
    tags: %{pipelineId: "1002", pipelineTemplate: "live-drm"},
    name: "testName2"
  },
  %{
    channelId: "3",
    description: "dev-test_003",
    tags: %{pipelineId: "1003", pipelineTemplate: "live-drm"},
    # fix: "testName2" -> "testName1" 
    name: "testName1"
  },
  %{
    channelId: "4",
    description: "dev-test_004",
    tags: %{pipelineId: "1004", pipelineTemplate: "live-drm"},
    name: ""
  }
]