score:0
So, it all points to that after the file is inside JAR, it can only be accessed as a inputstream to read the chunk of data from within the compressed file.
I arrived at a solution, even though its not pretty it does what I need, that is to read a csv file, take the 2 first columns and make it into a dataframe and after load it inside a key-value structure (in this case i created a case class to hold these pairs).
I am considering migrating these lookups to a HOCON file, that may make the process less convoluted to load these lookups
import sparkSession.implicits._
val fileStream = scala.io.Source.getClass.getResourceAsStream("/lookup01.csv")
val input = sparkSession.sparkContext.makeRDD(scala.io.Source.fromInputStream(fileStream).getLines().toList).toDF()
val myRdd = input.map {
line =>
val col = utils.Utils.splitCSVString(line.getString(0))
KeyValue(col(0), col(1))
}
val myDF = myRdd.rdd.map(x => (x.key, x.value)).collectAsMap()
fileStream.close()
score:2
You have to get the correct path from classPath
Considering that your file is under src/main/resources:
val path = getClass.getResource("/lookup01.csv")
val v_lookup = sparkSession.read.option( "header", true ).csv(path)
Source: stackoverflow.com
Related Query
- Load CSV file as dataframe from resources within an Uber Jar
- Spark load csv file in jar from resources folder
- Cannot load main class from JAR file
- How to load the csv file into the Spark DataFrame with Array[Int]
- spark dataframe is loading all nulls from csv file
- Spark-Submit Error: Cannot load main class from JAR file
- I need to skip three rows from the dataframe while loading from a CSV file in scala
- scala typesafe config - How to load conf file from classpath not from top level resources
- Not able to load file from HDFS in spark Dataframe
- Failed to load main class from JAR file while running with spark-submit
- Is it possible to make csv file using records from KAFKA STREAMS within a time frame?
- How to load a json file which is having double quotes within a string into a dataframe in spark scala
- How in Spark application create CSV file from DataFrame (Scala)?
- How to use periodic commit from scala to load csv file to neo4j?
- Error : Unable to load Main Class from JAR file on running spark-submit command
- removing spaces in DataFrame using SCALA. (I have loaded CSV file into RDD then trying to remove spaces from it
- Load a CSV file from line 17 of the file in scala spark
- Load CSVs - unable to pass file paths from dataframe
- Spark - load CSV file as DataFrame?
- How to build an Uber JAR (Fat JAR) using SBT within IntelliJ IDEA?
- Provide schema while reading csv file as a dataframe in Scala Spark
- Creating a jar file from a Scala file
- Reading DataFrame from partitioned parquet file
- How to create a DataFrame from a text file in Spark
- How to make a jar file from scala
- How to construct Dataframe from a Excel (xls,xlsx) file in Scala Spark?
- How to run an external file from within the scala interactive interpreter (REPL)?
- Using SparkR JVM to call methods from a Scala jar file
- Add column names to data read from csv file without column names
- Spark-SQL : How to read a TSV or CSV file into dataframe and apply a custom schema?
More Query from same tag
- Pattern matching with ADTs and type members
- Write GeoLocation Twitter4J to Postgres
- Getting value from broadcasted map is taking lot of time in spark
- How to import many ADT classes
- How in Spark application create CSV file from DataFrame (Scala)?
- Can scala splat be used for anything that isn't a varargs?
- Scala Curly braces with and without return statement
- Pattern behind shapeless Aux classes
- Working with images in Scala
- Linear algebra library for Scala?
- not found: value udf error
- http4s - get request body as String or InputStream
- [Randomly appear][Spark ML ALS][AWS EMR] FileNotFoundException in checkpoint folder but file exists
- Standardize an RDD
- Why doesn't scala swing app exit when main frame is closed?
- Scala: implicits, subclassing and member types
- Scala / MongoDB - removing duplicate
- Strange results of `list.indexWhere` when parameter `from` is negative
- Are the children of a ScalaFX Pane of JavaFX type?
- Cannot resolve symbol error in intellij with Scala with Odersky's programming in scala book
- Scala: if inside match case
- kafka-streams-scala version vis-à-vis kafka-streams version
- value session is not a member of Unit
- Scala - Filter lines in a document if a string/word is present
- Akka Cluster - Recover data from a crashed actor
- Dynamic dataframe with n columns and m rows
- Implicit conversion where there resulting type is a type projection on a generic type
- In Spark windowing, how do you fill null for when the number of rows selected are less than window size?
- Order in Scala set
- Akka Streams Websocket Wiring