# Column Expressions Guidance: Dynamically set Column Type

**URL:** <https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003>\
**Category:** KNIME Analytics Platform\
**Tags:** flow-variables, node\
**Created:** [September 12, 2022, 11:50am UTC](https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003 "2022-09-12T11:50:40Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mwiegand](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mwiegand/32/66896_2.png) [@mwiegand](https://forum.knime.com/u/mwiegand)\
**Post date:** [September 12, 2022, 11:50am UTC](https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003/1 "2022-09-12T11:50:40Z")

</div>

Hi all,

while working with the [Column Expression Node](https://hub.knime.com/knime/extensions/org.knime.features.expressions/latest/org.knime.expressions.base.node.formulas.FormulasNodeFactory) I struggle a lot, maybe because of the lack of documentation, to dynamically define the column type (i.e. string, int etc.). I overwrite via a flow variable expressions \> element 0 \> outputType \> cell-class but to no avail.

 ![Bildschirmfoto 2022-09-12 um 13.47.11](https://forum-cdn.knime.com/uploads/default/original/3X/6/f/6f19654420486513534516dc413299f7f4e1d41f.jpeg)

I tried with the:

1. exact type declaration like “Number (integer)” or “String”
2. an array index (starting at 0) like 12 for “Number (integer)” or 20 for “String”
3. a cleaned version or the type name like “number\_integer” or “string”

 ![Bildschirmfoto 2022-09-12 um 13.47.50](https://forum-cdn.knime.com/uploads/default/original/3X/8/e/8e272c3395422cb6da507e2550dd1410610d17ad.jpeg)

All to no avail. I then tried to locate the actual code of the node in GitHub or Bitbucket, to possibly derive the required values, but to no avail either. I hope anyone has an idea.

Many thanks in advance  
Mike

---

<div class="post-metadata">

**Author:** ![ArjenEX](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@ArjenEX](https://forum.knime.com/u/ArjenEX)\
**Post date:** [September 12, 2022, 12:24pm UTC](https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003/2 "2022-09-12T12:24:13Z")

</div>

Hi @mwiegand

You need to use the actual data class. For string it’s `org.knime.core.data.def.StringCell` , for integer it’s `org.knime.core.data.def.IntCell`.

![image](https://forum-cdn.knime.com/uploads/default/original/3X/9/c/9c6ec0585ee0fceb7f33b325f361dab98ee394fb.png)

You can derive this information from the Flow Variable section by assigning a temporary field to it. How to do this:

> [@Flow Variable Names](https://forum.knime.com/t/flow-variable-names/46042/2):
>
> Hi @rfeigel Guess who’s back laughing Hack modus on: Go to any node → open the flow variable section → fill in random numbers in the text box that is located after the variable and run the node → open the node preview → switch to the Flow Variables tab → bingo. [image] Hopefully this will save you some time in the future!

Wherever you create this, if you pass this value to the Column Expression, cell\_class flow variable like you have found already, it will work.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![mwiegand](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mwiegand/32/66896_2.png) [@mwiegand](https://forum.knime.com/u/mwiegand)\
**Post date:** [September 12, 2022, 12:43pm UTC](https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003/3 "2022-09-12T12:43:01Z")

</div>

Awesome 🙂 Thanks a lot @ArjenEX. Do you happen to know a place where I can find all data types? Iteratively going through each individual type ist tiring to say the least.

PS: Trying to find that information in the [GitHub Repo](https://github.com/knime/knime-core) doing a `grep -rin core.data.def .` … WIP

---

<div class="post-metadata">

**Author:** ![ArjenEX](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@ArjenEX](https://forum.knime.com/u/ArjenEX)\
**Post date:** [September 12, 2022, 1:02pm UTC](https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003/4 "2022-09-12T13:02:09Z")

</div>

All of the ones I’m not sure right now, need to dive into the SDK for that. This is part of it indeed. [knime-core/org.knime.core/src/eclipse/org/knime/core/data/def at master · knime/knime-core · GitHub](https://github.com/knime/knime-core/tree/master/org.knime.core/src/eclipse/org/knime/core/data/def) but your approach probably gets a bit more.

---

<div class="post-metadata">

**Author:** ![mwiegand](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mwiegand/32/66896_2.png) [@mwiegand](https://forum.knime.com/u/mwiegand)\
**Post date:** [September 12, 2022, 2:06pm UTC](https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003/5 "2022-09-12T14:06:07Z")

</div>

There we go. But, based on the [Test Data Generator – KNIME Hub](https://hub.knime.com/knime/extensions/org.knime.features.testing.application/latest/org.knime.testing.node.datagenerator.TestDataNodeFactory) node there are substantially more data types present than presumably declared 😕 Sure I made a mistake … do you spot it?

> **[Get all Data Definition Types – mwiegand](https://hub.knime.com/mwiegand/spaces/Public/latest/Knime%20Forum%20Support/Get%20all%20Data%20Definition%20Types~2wz2WdJIh46EhNKX)**
>
> Solutions for data science: find workflows, nodes and components, and collaborate in spaces.

 ![Bildschirmfoto 2022-09-12 um 15.59.23](https://forum-cdn.knime.com/uploads/default/original/3X/f/9/f930ca1b0a1702f4fb04dffc095d54d30fdfce3a.jpeg)

Data Types from Test Data Generator

```auto
Boolean value
Date and Time
Duration
List (Collection of: Boolean value)
List (Collection of: Date and Time)
List (Collection of: Number (double))
List (Collection of: Number (integer))
List (Collection of: Number (long))
List (Collection of: String)
List (Collection of: String)
List (Collection of: URI)
Local Date
Local Date Time
Local Time
Number (double)
Number (double)
Number (integer)
Number (long)
Period
Set (Collection of: Boolean value)
Set (Collection of: Date and Time)
Set (Collection of: Number (double))
Set (Collection of: Number (integer))
Set (Collection of: Number (long))
Set (Collection of: String)
Set (Collection of: String)
Set (Collection of: URI)
String
String
String
URI
Zoned Date Time

```

Data Types extracted via grep from Knime GitHub Repository

```auto
core.data.def.BooleanCell
core.data.def.ComplexNumberCell
core.data.def.DefaultCellIterator
core.data.def.DefaultRow
core.data.def.DefaultRowIterator
core.data.def.DefaultTable
core.data.def.DoubleCell
core.data.def.FuzzyIntervalCell
core.data.def.FuzzyNumberCell
core.data.def.IntCell
core.data.def.IntervalCell
core.data.def.JoinedRow
core.data.def.LongCell
core.data.def.StringCell
core.data.def.TimestampCell

```

Cheers  
Mike

---

<div class="post-metadata">

**Author:** ![mwiegand](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mwiegand/32/66896_2.png) [@mwiegand](https://forum.knime.com/u/mwiegand)\
**Post date:** [September 12, 2022, 3:07pm UTC](https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003/6 "2022-09-12T15:07:11Z")

</div>

PS: I updated the workflow to manually extract all data types from the Column Expression node per your guidance. Interestingly, though, all retrieved values are of type `org.knime.core.data.def.StringCell`.

Previously it worked. am I stupid or is this a bug?

> **[Get all Data Definition Types – mwiegand](https://hub.knime.com/mwiegand/spaces/Public/latest/Knime%20Forum%20Support/Get%20all%20Data%20Definition%20Types~2wz2WdJIh46EhNKX)**
>
> Solutions for data science: find workflows, nodes and components, and collaborate in spaces.

---

<div class="post-metadata">

**Author:** ![ArjenEX](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@ArjenEX](https://forum.knime.com/u/ArjenEX)\
**Post date:** [September 12, 2022, 5:14pm UTC](https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003/7 "2022-09-12T17:14:39Z")

</div>

I cannot open it due to the bash so someone else has to jump in. I’m not sure what you’re using but it’s giving an error here.  
 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/c/e/ce59257e15dd776409f11acdf090d2b57246a5b6.png)

---

<div class="post-metadata">

**Author:** ![mwiegand](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mwiegand/32/66896_2.png) [@mwiegand](https://forum.knime.com/u/mwiegand)\
**Post date:** [September 12, 2022, 5:20pm UTC](https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003/8 "2022-09-12T17:20:16Z")

</div>

You probably got to enable a repo. I assume it’s:

```auto
KNIME Community Extensions (Experimental): https://update.knime.com/community-contributions/4.6
Palladian: https://download.nodepit.com/palladian/4.6

```

Added Palladian as well since it’s an awesome extension!

 ![Bildschirmfoto 2022-09-12 um 19.18.58](https://forum-cdn.knime.com/uploads/default/original/3X/8/2/8255fde6f2c4c27a4f5db72d51f61e8718d76504.jpeg)

---

<div class="post-metadata">

**Author:** ![ArjenEX](https://forum-cdn.knime.com/letter_avatar_proxy/v4/letter/a/97f17d/32.png) [@ArjenEX](https://forum.knime.com/u/ArjenEX)\
**Post date:** [September 12, 2022, 5:34pm UTC](https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003/9 "2022-09-12T17:34:19Z")

</div>

Something completely different.

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/f/4/f435fee8572692f6b23141f9d0a09abc25f1c7cb.png)

But anyway, mistake is on your end. You forgot to select the proper output type for all the column expressions, they are indeed all set to string 😉

 ![image](https://forum-cdn.knime.com/uploads/default/original/3X/5/c/5c66e9e7cfe27c85d465e4c6fb27624c36a869fb.png)

---

<div class="post-metadata">

**Author:** ![mwiegand](https://forum-cdn.knime.com/user_avatar/forum.knime.com/mwiegand/32/66896_2.png) [@mwiegand](https://forum.knime.com/u/mwiegand)\
**Post date:** [September 13, 2022, 6:21am UTC](https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003/10 "2022-09-13T06:21:38Z")

</div>

👍 Thanks for pointing that out. My mistake falls into the same category as missing semicolons or quotes xD

Btw, I managed to identify presumably all data type definitions by poking around the repo and recognizing that a more fuzzy search for “.data.” seems to do the job. I will fine tune my workflow and update that later on.

---

<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:** [September 20, 2022, 6:22am UTC](https://forum.knime.com/t/column-expressions-guidance-dynamically-set-column-type/47003/11 "2022-09-20T06:22:28Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
