0
我正在使用带有Spark SQL Context的CSV文件读取文件。如何将Spark数据帧输出转换为json?
代码:
m.put("path", CSV_DIRECTORY+file.getOriginalFilename());
m.put("inferSchema", "true"); // Automatically infer data types else string by default
m.put("header", "true"); // Use first line of all files as header
m.put("delimiter", ";");
DataFrame df = sqlContext.load("com.databricks.spark.csv",m);
df.printSchema();
抓取列名和数据类型与df.printSchema()
O/P:
|--id : integer (nullable = true)
|-- ApplicationNo: string (nullable = true)
|-- Applidate: timestamp(nullable = true)
什么说法printSchema的返回类型。如何转换JSON格式的输出,如何将数据帧转换为JSON?
希望的O/P:
{"column":"id","datatype":"integer"}
Thanks @Hamel df.schema()。json();做了这份工作。 – Devz