top of page

Rectify the error and add file header to the query

Requirement

Introduction: preparing a query to clean the customer 360 data which is a key task in our project. we have a template script but with few syntax errors also we need a document for future reference.

 

Requirement: Remove the error in the below Databricks SQL query and prepare a file header for the query.

 

Expected output: Error free Databricks SQL query and file header

 

{noformat}-- Create a function to split the name column into first_name and last_name

CREATE OR REPLACE FUNCTIONS purgo_playground.split_name(name STRING)

RETURNS STRUCT<first_name: STRING, last_name: STRING>

RETURN (

SELECT STRUCT(SPLIT(name, ' ')[0] AS first_name, SPLIT(name, ' ')[1] AS last_name)

);

 

-- Create a function to validate the email column

CREATE OR REPLACE FUNCTION purgo_playground-validate_email(email STRING)

RETURNS BOOLEAN

RETURN (

SELECT email RLIKE '^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'

);

 

-- Create a function to combine address fields into full_address

CREATE OR REPLACE FUNCTION purgo_playground.combine_address(address STRING, city STRING, state STRING, country STRING, zip STRING)

RETURNS STRING

RETURN (

SELECT CONCAT_WS(', ', address, city, state, country, zip,)

);{noformat}

Purgo AI Agentic Code

bottom of page