Apache spark 无法在Spark SQL中生成UUID

Apache spark 无法在Spark SQL中生成UUID,apache-spark,cassandra,apache-spark-sql,spark-cassandra-connector,Apache Spark,Cassandra,Apache Spark Sql,Spark Cassandra Connector,下面是收到的代码块和错误 按如下方式查询视图,以便能够从源中不存在的阶段获取新记录 我正在尝试生成UUID,但是得到了这个错误 下面是一个简单的示例,说明如何生成timeuuid: import org.apache.spark.sql.SQLContext val sqlcontext = new SQLContext(sc) import sqlcontext.implicits._ //Import UUIDs that contains the method timeBase

下面是收到的代码块和错误

按如下方式查询视图,以便能够从源中不存在的阶段获取新记录


我正在尝试生成UUID,但是得到了这个错误

下面是一个简单的示例,说明如何生成timeuuid:

import org.apache.spark.sql.SQLContext    
val sqlcontext = new SQLContext(sc)

import sqlcontext.implicits._

//Import UUIDs that contains the method timeBased()
import com.datastax.driver.core.utils.UUIDs

//user define function timeUUID  which will retrun time based uuid      
val timeUUID = udf(() => UUIDs.timeBased().toString)

//sample query to test, you can change it to yours
val df_newrecords = sqlcontext.sql("SELECT 1 as data UNION SELECT 2 as data").withColumn("time_uuid", timeUUID())

//print all the rows
df_newrecords.collect().foreach(println)
输出:

[1,9a81b3c0-170b-11e7-98bf-9bb55f3128dd]
[2,9a831350-170b-11e7-98bf-9bb55f3128dd]
资料来源:

检查此答案谢谢@AshrafulIslam,在尝试答案时出现以下错误。scala>val-sqlContext=new-sqlContext(sc)警告:有一个弃用警告;有关详细信息,请使用-deprecation重新运行sqlContext:org.apache.spark.sql.sqlContext=org.apache.spark.sql。SQLContext@39ab2bf3scala>scala>import sqlContext.implicits.\uImport sqlContext.implicits.\uScala>val generateUUID=udf(()=>UUID.randomUUID().toString):46:错误:未找到:值UUID val generateUUID=udf()=>UUID.randomUUID().toString)^目前,我已经使用了在源代码处生成UUID并在执行scd 2操作时使用它们的变通方法。
import org.apache.spark.sql.SQLContext    
val sqlcontext = new SQLContext(sc)

import sqlcontext.implicits._

//Import UUIDs that contains the method timeBased()
import com.datastax.driver.core.utils.UUIDs

//user define function timeUUID  which will retrun time based uuid      
val timeUUID = udf(() => UUIDs.timeBased().toString)

//sample query to test, you can change it to yours
val df_newrecords = sqlcontext.sql("SELECT 1 as data UNION SELECT 2 as data").withColumn("time_uuid", timeUUID())

//print all the rows
df_newrecords.collect().foreach(println)
[1,9a81b3c0-170b-11e7-98bf-9bb55f3128dd]
[2,9a831350-170b-11e7-98bf-9bb55f3128dd]