Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Register schema_of_csv and adding SQL tests
  • Loading branch information
MaxGekk committed Sep 21, 2018
commit 7acdd70924af783e2d6e26365640708b103ab0aa
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@ object FunctionRegistry {
castAlias("string", StringType),

// csv
expression[CsvToStructs]("from_csv")
expression[CsvToStructs]("from_csv"),
expression[SchemaOfCsv]("schema_of_csv")
)

val builtin: SimpleFunctionRegistry = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,7 @@ select from_csv('1', 'a InvalidType');
select from_csv('1', 'a INT', named_struct('mode', 'PERMISSIVE'));
select from_csv('1', 'a INT', map('mode', 1));
select from_csv();

-- infer schema of json literal
select schema_of_csv('1,abc');
select schema_of_csv('1|abc', map('delimiter', '|'));
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- Automatically generated by SQLQueryTestSuite
-- Number of queries: 10
-- Number of queries: 12


-- !query 0
Expand Down Expand Up @@ -102,3 +102,19 @@ struct<>
-- !query 9 output
org.apache.spark.sql.AnalysisException
Invalid number of arguments for function from_csv. Expected: one of 2 and 3; Found: 0; line 1 pos 7


-- !query 10
select schema_of_csv('1,abc')
-- !query 10 schema
struct<schemaofcsv(1,abc):string>
-- !query 10 output
struct<_c0:int,_c1:string>


-- !query 11
select schema_of_csv('1|abc', map('delimiter', '|'))
-- !query 11 schema
struct<schemaofcsv(1|abc):string>
-- !query 11 output
struct<_c0:int,_c1:string>