You now have until September 15th to submit your use case or success story to the 2022 Dataiku Frontrunner Awards!ENTER YOUR SUBMISSION

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
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
1 Reply
AlexT
Dataiker
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