Rahul
Rahul

Reputation: 21

How to load files in sparksql through remote hive storage ( s3 orc) using spark/scala + code + configuration

intellij(spark)--->Hive(Remote)---storage on S3(orc format) Not able to read remote Hive table through spark/scala.

was able to read table schema but not able to read table.

Error -Exception in thread "main" java.lang.IllegalArgumentException: AWS Access Key ID and Secret Access Key must be specified as the username or password (respectively) of a s3 URL, or by setting the fs.s3.awsAccessKeyId or fs.s3.awsSecretAccessKey properties (respectively).

import org.apache.spark.SparkConf
import org.apache.spark.SparkContext
import org.apache.spark.sql.{Encoders, SparkSession}
import org.apache.spark.sql.hive.HiveContext
import org.apache.spark.sql.hive.orc._
import org.apache.spark.sql.types.StructType

object mainclas {

  def main(args: Array[String]): Unit = {

     val spark = SparkSession.builder
      .master("local[*]")
      .appName("hivetable")
      .config("hive.metastore.uris", "thrift://10.20.30.40:9083")
       .config("access-key","PQHFFDEGGDDVDVV")
       .config("secret-key","FFGSGHhjhhhdjhJHJHHJGJHGjHH")
       .config("format", "orc")
      .enableHiveSupport()
      .getOrCreate()

   val res = spark.sqlContext.sql("show tables").show()
   val res1 =spark.sql("select *from ace.visit limit 5").show() 
}
}`

Upvotes: 2

Views: 1458

Answers (2)

stevel
stevel

Reputation: 13430

you need to prefix all the fs. options with spark.hadoop if you are setting them in the spark config. And as noted: use s3a over s3n if you can.

Upvotes: 0

Sivaprasanna Sethuraman
Sivaprasanna Sethuraman

Reputation: 4132

Try this:

val spark = SparkSession.builder
  .master("local[*]")
  .appName("hivetable")
  .config("hive.metastore.uris", "thrift://10.20.30.40:9083")
  .config("fs.s3n.awsAccessKeyId","PQHFFDEGGDDVDVV")
  .config("fs.s3n.awsSecretAccessKey","FFGSGHhjhhhdjhJHJHHJGJHGjHH")
  .config("format", "orc")
  .enableHiveSupport()
  .getOrCreate()

Upvotes: 1

Related Questions