How to load local file in sc.textFile, instead of HDFS

Try explicitly specify sc.textFile(“file:///path to the file/”). The error occurs when Hadoop environment is set. SparkContext.textFile internally calls org.apache.hadoop.mapred.FileInputFormat.getSplits, which in turn uses org.apache.hadoop.fs.getDefaultUri if schema is absent. This method reads “fs.defaultFS” parameter of Hadoop conf. If you set HADOOP_CONF_DIR environment variable, the parameter is usually set as “hdfs://…”; otherwise “file://”.

Preferred way to create a Scala list

ListBuffer is a mutable list which has constant-time append, and constant-time conversion into a List. List is immutable and has constant-time prepend and linear-time append. How you construct your list depends on the algorithm you’ll use the list for and the order in which you get the elements to create it. For instance, if you … Read more

private[this] vs private

There is a case where private[this] is required to make code compile. This has to do with an interaction of variance notation and mutable variables. Consider the following (useless) class: class Holder[+T] (initialValue: Option[T]) { // without [this] it will not compile private[this] var value = initialValue def getValue = value def makeEmpty { value … Read more

Understanding scala enumerations

the Enumeration trait has a type member Value representing the individual elements of the enumeration (it’s actually an inner class, but the difference doesn’t matter here). Thus object WeekDay inherits that type member. The line type WeekDay = Value is just a type alias. It is useful, because after you import it elsewhere with import … Read more

Spark – Error “A master URL must be set in your configuration” when submitting an app

The TLDR: .config(“spark.master”, “local”) a list of the options for spark.master in spark 2.2.1 I ended up on this page after trying to run a simple Spark SQL java program in local mode. To do this, I found that I could set spark.master using: SparkSession spark = SparkSession .builder() .appName(“Java Spark SQL basic example”) .config(“spark.master”, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)