How to lower all column name in the analysis module ?

Highlighted
UserBird Dataiker
Dataiker
How to lower all column name in the analysis module ?
Hi guys,

Is there a possibility to lower all the column name in the analysis module ? I have 30 columns in my file , i synced it into a postgresql table and after that, i would lower all the column name without renaming these manually or with a python recipe. I wondered if there is a special feature or a python snippet into the analysis module to make it.

Thanks.
0 Kudos
3 Replies
jrouquie Dataiker
Dataiker
Re: How to lower all column name in the analysis module ?

I am not aware of a possibility to do so directly in the GUI, but if too tedious to do it by hand, you might want to edit



DATA_DIR/config/projects/PROJECTFOO/datasets/datasetbar.json



through a script. Here, datasetbar is the input dataset to the sync recipe. Then




  • open this sync recipe, click “resync schema” so that the schemas of both DSS datasets are lowercase.

  • rerun this recipe, so that at the end DSS writes the new schema to postgres.





 



If your dataset fits in memory, I would replace the sync recipe by a Python recipe that change the column names and then copy its input to its output. This way there is no unnecessary duplication of data.

0 Kudos
Thomas Dataiker
Dataiker
Re: How to lower all column name in the analysis module ?

Hi, 



Here is a solution that might work in Visual Preparation scripts (under Analysis):




  • Create a Custom python script that outputs a JSON object (Python dict) storing the lowered column names:




import json

def process(row):
columns = row.keys()
o = {}
for column in columns:
new_name = str(column).lower()
o[new_name] = row[column]
return json.dumps(o)



  • via the Columns view, delete all the columns except the newly created JSON object

  • Flatten the JSON object

  • Get rid again of the unwanted columns, then, again under the Columns view, mass rename the columns by removing the prefix generated by flattening the JSON object





That's it. You end up with a view of your dataset where all the columns are lowered. 



NOTE: this is not the best solution since you still need to build your dataset at the end, so this may create a not-so-necessary copy of your base dataset.

0 Kudos
jereze Dataiker
Dataiker
Re: How to lower all column name in the analysis module ?

If you want to lower the column name because of PostegreSQL, the solution might be to double quote the column name in your SQL code:




select "MyColomn1", mycolumn2 from "MyTable";


More info here.

Jeremy, Product Manager at Dataiku
0 Kudos
Labels (2)