1

I am trying to load a xls/xlsx file from server

With this code https://github.com/crealytics/spark-excel

SparkConf sparkConf = new SparkConf();
SparkContext sparkContext = null;

sparkContext = new SparkContext("local", "234", sparkConf);
SparkSession sparkSession = 
SparkSession.builder().sparkContext(sparkContext).getOrCreate();

SQLContext sqlContext = sparkSession.sqlContext().newSession();
Dataset<Row> dframe = sqlContext.read().format("com.crealytics.spark.excel").option("timestampFormat", "yyyy-mmm-dd HH:mm:ss").option("dataAddress", "'My Sheet'!A1").option("useHeader", "true").option("treatEmptyValuesAsNulls", "false").option("inferSchema", "true")
            .load("/home/test/myfile/sample.xlsx"); // local path

This code perfectly works on local file

"/home/test/myfile/sample.xlsx"

How can i read files on server with path like this

"http://10.0.0.1:8080/serverFiles/test.xlsx"

I treid replacing the code with Server url above and got this error :

 Exception in thread "main" java.io.IOException: No FileSystem for scheme: http
    at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:2586)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2593)

Can spark read xlsx/xls file directly from server URL ? [not for CSV]

1 Answer 1

0

You cannot directly use HTTP paths in your Spark Context.

Refer the this SO-question

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

7 Comments

How can i do that in java .For xlsx file .I dont want to use CSV
This gives a scanner object which again cannot be loaded using sqlContext
you can create a local file/String with this scanner and use parallelize to create RDD and create DF from it...
this not possible as far I know.. spark will accept all HDFS compliance data source.. but not from HTTP. That's why I suggested to get the file content to your driver and distribute it..
|

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.