Csv Functions

This page lists all csv functions available in Spark SQL.


from_csv

from_csv(csvStr, schema[, options]) - Returns a struct value with the given csvStr and schema.

Examples:

> SELECT from_csv('1, 0.8', 'a INT, b DOUBLE');
 {"a":1,"b":0.8}
> SELECT from_csv('26/08/2015', 'time Timestamp', map('timestampFormat', 'dd/MM/yyyy'));
 {"time":2015-08-26 00:00:00}

Since: 3.0.0


schema_of_csv

schema_of_csv(csv[, options]) - Returns schema in the DDL format of CSV string.

Examples:

> SELECT schema_of_csv('1,abc');
 STRUCT<_c0: INT, _c1: STRING>

Since: 3.0.0


to_csv

to_csv(expr[, options]) - Returns a CSV string with a given struct value

Examples:

> SELECT to_csv(named_struct('a', 1, 'b', 2));
 1,2
> SELECT to_csv(named_struct('time', to_timestamp('2015-08-26', 'yyyy-MM-dd')), map('timestampFormat', 'dd/MM/yyyy'));
 26/08/2015

Since: 3.0.0