2

I am trying to read a json file using spark in Java. The few changes I tried were :

SparkConf conf = new SparkConf().setAppName("Search").setMaster("local[*]");

DataFrame df = sqlContext.read().json("../Users/pshah/Desktop/sample.json/*");

Code:

import java.util.Arrays;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.FlatMapFunction;
import org.apache.spark.api.java.function.Function;
import org.apache.spark.api.java.function.PairFunction;
import org.apache.spark.sql.DataFrame;
import org.apache.spark.sql.SQLContext;
public class ParseData {

public static void main(String args[]){
    SparkConf conf = new SparkConf().setAppName("Search").setMaster("local");
    JavaSparkContext sc= new JavaSparkContext(conf);
    SQLContext sqlContext = new org.apache.spark.sql.SQLContext(sc);
    // Create the DataFrame
    DataFrame df = sqlContext.read().json("/Users/pshah/Desktop/sample.json");
    // Show the content of the DataFrame
    df.show();
}}

Error:

Exception in thread "main" java.io.IOException: No input paths specified in job
at org.apache.hadoop.mapred.FileInputFormat.listStatus(FileInputFormat.java:198)
5
  • I've been unable to replicate your issue. Could You please provide pastebin with the JSON file? Commented Jul 23, 2016 at 21:45
  • pastebin.com/PT0g3jiM Commented Jul 23, 2016 at 21:58
  • Are you sure the path exists? it seems you point to the wrong path Commented Jul 24, 2016 at 0:37
  • Yes. The path exists. I just tried building the maven project again and it's running fine now. Thank you for the response! Commented Jul 24, 2016 at 0:50
  • The problem is the code runs fine for very simple JSON file. But when I am using nested json data . I get the following error : java.lang.RuntimeException: Failed to parse a value for data type StructType() (current token: VALUE_STRING Commented Jul 24, 2016 at 0:53

1 Answer 1

0

i wrote the same code, and meet the same problem. i put the people.json file under project directory src/main/resources. the reason is program could not finding the file. after i copy the people.json file to the program's working directory, the program works well

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.