Discover the winners & finalists of the 2022 Dataiku Frontrunner Awards!READ THEIR USE CASES

Project Variables and Data Typing

Solved!
indy2005
Level 3
Project Variables and Data Typing

Hi

I am a but confused by defininf project variables in DataIku.  When I read them back, they are all being typed as string?  I understand that I should put all values in quotes when defining the variables, but would have thought there was some type of dynamic typing? 

Or do I have to manually do python type conversions on all my variables after reading them in as strings, using get_custom_variables()?

0 Kudos
1 Solution
AlexT
Dataiker

Hi,

Variables are defined a JSON.  Reading project variables will return a dictionary in python for example get_custom_variables().

When you read a specific variable only it would be returned as a string, regardless of this int or boolean in the JSON. So you will have to manually define its type as python does not infer types by default. 

The example below today_year was defined as int 2022, if I want to use at int I can simply use int()

Screenshot 2022-05-23 at 20.40.13.png

In DSS formulas, you can use either use the variables ${var_name} orparseJSON(variables["var_name]). 

https://doc.dataiku.com/dss/latest/formula/index.html#dss-variables

in the DSS formula there is some auto-typing as explained here : 

https://doc.dataiku.com/dss/latest/formula/index.html#variables-typing-and-autotyping

For more information on variables please see :

https://knowledge.dataiku.com/latest/courses/o16n/variables/variables101/variables101-summary.html

View solution in original post

0 Kudos
3 Replies
AlexT
Dataiker

Hi,

Variables are defined a JSON.  Reading project variables will return a dictionary in python for example get_custom_variables().

When you read a specific variable only it would be returned as a string, regardless of this int or boolean in the JSON. So you will have to manually define its type as python does not infer types by default. 

The example below today_year was defined as int 2022, if I want to use at int I can simply use int()

Screenshot 2022-05-23 at 20.40.13.png

In DSS formulas, you can use either use the variables ${var_name} orparseJSON(variables["var_name]). 

https://doc.dataiku.com/dss/latest/formula/index.html#dss-variables

in the DSS formula there is some auto-typing as explained here : 

https://doc.dataiku.com/dss/latest/formula/index.html#variables-typing-and-autotyping

For more information on variables please see :

https://knowledge.dataiku.com/latest/courses/o16n/variables/variables101/variables101-summary.html

0 Kudos
Erlebacher
Level 4

In the documentation on creating Dataiku Applications, I see the following:

2022-12-04_17-39-05.png

If types are not honored, why the complex JSON structure? When does one use such a structure and when not? Where do the various options listed come from? Also, I would like to allow the users to see a list of options and select multiple options among them. How is this done? Where can I find an example? Thanks.

0 Kudos
Erlebacher
Level 4

I am about to figure it out. One defines project parameters in the variables area and set up the presentation details in the applications interface.

0 Kudos