How to execute multi line sql in spark sql

后端 未结 5 636
余生分开走
余生分开走 2020-12-29 12:20

How can I execute lengthy, multiline Hive Queries in Spark SQL? Like query below:

val sqlContext = new HiveContext (sc)
val result = sqlContext.sql (\"
 sele         


        
5条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-29 12:42

    It is worth noting that the length is not the issue, just the writing. For this you can use """ as Gaweda suggested or simply use a string variable, e.g. by building it with string builder. For example:

    val selectElements = Seq("a","b","c")
    val builder = StringBuilder.newBuilder
    builder.append("select ")
    builder.append(selectElements.mkString(","))
    builder.append(" where d<10")
    val results = sqlContext.sql(builder.toString())
    

提交回复
热议问题