Java教程

parse_url函数

本文主要是介绍parse_url函数,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

参数

  • path:路径/login
  • host:www.baidu.com
  • query:username=zs
  • protocol:http协议
package SparkSQL.fun

import org.apache.spark.SparkConf
import org.apache.spark.sql.{Dataset, SparkSession}

object ParseUrlFun {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setAppName("func").setMaster("local[*]")
    val session = SparkSession.builder().config(conf).getOrCreate()

    import session.implicits._
    val dataset: Dataset[(Int, String)] = session.createDataset(Array(
      (1, "http://www.baidu.com/login?username=zs"),
      (2, "http://www.baidu.com/index?search=zs")
    ))
    val frame1 = dataset.toDF("id", "url")
    dataset.printSchema()

    frame1.createTempView("temp")
    val frame = session.sql("select * from temp")
    frame.show()

    /*
    QUERY: username=zs
    HOST: www.baidu.com
    PATH: /login
    PROTOCOL: http
     */
    val frame2 = session.sql("select parse_url(url, 'QUERY') from temp")
    frame2.show()

    val frame3 = session.sql("select parse_url(url, 'HOST') from temp")
    frame3.show()

    val frame4 = session.sql("select parse_url(url, 'PATH') from temp")
    frame4.show()

    val frame5 = session.sql("select parse_url(url, 'PROTOCOL') from temp")
    frame5.show()

    session.stop()
  }
}
这篇关于parse_url函数的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!