Databricks- Camel to Snake Case by using Scala

Ryan Arjun
3 min readFeb 24, 2024

In this tutorial, you will learn “How to change column names from CamelCase to Snake Case in a dataframe by using Scala” in Databricks.

💡Imagine we have an input Dataframe (as in the image). Our goal is to achieve the desired output Dataframe (also in the image).

Basically, you have to change the names of column as follows-
Age -> Age ,

FirstName -> First_Name,

CityName -> City_Name,

CountryName -> Country_Name

Databricks originally was a Notebook interface to run Spark, without having to worry about the distributed compute infrastructure. You just said how big of a cluster you wanted, and Databricks did the rest. This was absolutely huge before distributed compute became the standard.

Scala really shines in big data processing for many reasons, the type safety, immutability and functional paradigms alone allow you to write incredibly concise and much less error prone code.

To create a Dataframe in Scala, you can use Apache Spark’s Dataframe API.

In this example:

💎Import necessary Spark classes for Dataframe operations.

--

--

Ryan Arjun

BI Specialist || Azure || AWS || GCP — SQL|Python|PySpark — Talend, Alteryx, SSIS — PowerBI, Tableau, SSRS