# Loop End (Column Append)

**URL:** <https://forum.knime.com/t/loop-end-column-append/7235>\
**Category:** KNIME Analytics Platform\
**Created:** [January 13, 2015, 12:02pm UTC](https://forum.knime.com/t/loop-end-column-append/7235 "2015-01-13T12:02:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![richards99](https://forum-cdn.knime.com/user_avatar/forum.knime.com/richards99/32/48547_2.png) [@richards99](https://forum.knime.com/u/richards99)\
**Post date:** [January 13, 2015, 12:02pm UTC](https://forum.knime.com/t/loop-end-column-append/7235/1 "2015-01-13T12:02:40Z")

</div>

There is a bug which comes up with alarming regularity in my workflows where the output from the "Loop End (Column Append)" node has "(Iter #50) (Iter #100)" sufixes or similar added to the column names.

I can see no logical reason for why this sometimes happens, as there are not duplicated column names, and its that all the columns have the same iteration number appended.

Simon.

---

<div class="post-metadata">

**Author:** ![Marlin](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marlin](https://forum.knime.com/u/Marlin)\
**Post date:** [January 13, 2015, 12:06pm UTC](https://forum.knime.com/t/loop-end-column-append/7235/2 "2015-01-13T12:06:34Z")

</div>

I can confirm this bug, although i have only encountered it once yet.

---

<div class="post-metadata">

**Author:** ![audrius](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@audrius](https://forum.knime.com/u/audrius)\
**Post date:** [January 16, 2015, 8:59am UTC](https://forum.knime.com/t/loop-end-column-append/7235/3 "2015-01-16T08:59:27Z")

</div>

I also can cofirm this bug with "Loop End (Column Append)" node:

| COL1&nbsp;(Iter #50) (Iter #100) (Iter #150) (Iter #200) (Iter #250) |

---

<div class="post-metadata">

**Author:** ![Marlin](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marlin](https://forum.knime.com/u/Marlin)\
**Post date:** [January 16, 2015, 11:02am UTC](https://forum.knime.com/t/loop-end-column-append/7235/4 "2015-01-16T11:02:35Z")

</div>

This should fix it. (in LoopEndJoinNodeModel of course) Could also be a tiny bit faster that way. Not that on would try joining \>=50 columns for performance reasons...

```
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
  // ...
  if (hasSameRowsInEachIteration) {
  // ...
    if (isCacheNew) {
      exec.setProgress(...);
      ExecutionContext ctx = ...
      cacheTable(ctx); // CHANGED
      ctx.setProgress(1.0);
    }
  }
  //...
}

private BufferedDataTable copy(final BufferedDataTable table, final ExecutionContext exec) throws CanceledExecutionException {
  DataColumnSpec[] colSpecs = new DataColumnSpec[table.getDataTableSpec().getNumColumns()];
  int i = 0;
  for (DataColumnSpec cs : table.getDataTableSpec()) { ... }
  return unsafeCopy(table, new DataTableSpec(colSpecs), exec); // Just refactored
}

// Replaces copy() where it was used to cache
private void cacheTable(final ExecutionContext exec) throws CanceledExecutionException {
  // possibly add null check?
  specs = m_currentAppendTable.getDataTableSpec(); // Don't need to check
  m_currentAppendTable = unsafeCopy(m_currentAppendTable, specs, exec);
}

// Refactored former second half of copy()
private BufferedDataTable unsafeCopy(final BufferedDataTable table, final DataTableSpec specs, final ExecutionContext exec) throws CanceledExecutionException {
  BufferedDataContainer container = exec.createDataContainer(specs);
  int i = 0;
  final double rowCount = table.getRowCount();
  for (DataRow r : table) { ... }
  container.close();
  return container.getTable();
}
```

&nbsp;

---

<div class="post-metadata">

**Author:** ![system](https://forum-cdn.knime.com/uploads/default/original/1X/ab3ccf34482a0329361734a18199390177204f15.png) [@system](https://forum.knime.com/u/system)\
**Post date:** [June 23, 2023, 8:24pm UTC](https://forum.knime.com/t/loop-end-column-append/7235/5 "2023-06-23T20:24:26Z")

</div>


