1

I have code like so with a multiline query

  val hiveInsertIntoTable = spark.read.text(fileQuery).collect()
  hiveInsertIntoTable.foreach(println)

  val actualQuery = hiveInsertIntoTable(0).mkString
  println(actualQuery)


  spark.sql(s"truncate table $tableTruncate")
  spark.sql(actualQuery)

Whenever I try to execute actual query I get an error.

org.apache.spark.sql.catalyst.parser.ParseException:
no viable alternative at input '<EOF>'(line 1, pos 52)
== SQL ==
insert into wera_tacotv_esd.lac_asset_table_pb_hive

----------------------------------------------------^^^

and the end of the query  .... ;    (terminates in a ;)

The query is actually about 450 lines

I tried to wrap the variable in triple quotes but that didn't work either.

Any help is appreciated.

I am using spark 2.1 and scala 2.11

2
  • We'll need to see this query... at least the first 53 characters of it... Commented May 22, 2018 at 21:50
  • 1
    You were right ronhash the error was a combinatrion of the current anser and the fact that I had a ; at the end of the query Commented May 24, 2018 at 13:50

1 Answer 1

1

Three problems:

  • hiveInsertIntoTable is an Array[org.apache.spark.sql.Row] - not very useful structure.
  • You take only the first row of it hiveInsertIntoTable(0)
  • Even if you took all rows, concatenating with empty string (.mkString) wouldn't work well.

Either:

val actualQuery = spark.read.text(path).as[String].collect.mkString("\n")

or

val actualQuery = spark.sparkContext.wholeTextFiles(path).values.first()
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.