如何计算spark Scala中2行之间的时间差
val sparkSession = SparkSession .builder() .appName(this.getClass.getSimpleName) //本地测试 .master('local[4]') .config('spark.driver.host', '127.0.0.1') .config('spark.driver.bindAddress', '127.0.0.1') .getOrCreate() val rows = Seq( Row('31-AUG-21 02.16.33.371 PM') ) val schema = StructType( Seq( StructField('my_time', StringType, true) ) ) val rowsRDD = sparkSession.sparkContext.parallelize(rows, 4) val df = sparkSession.createDataFrame(rowsRDD, schema)
df.withColumn('time1',expr('date_format(from_unixtime(unix_timestamp(my_time,'dd-MMM-yy hh.mm.ss.SSS a'),'yyyy-MM-dd HH:mm:ss.SSS'),'yyyy-MM-dd HH:mm:ss.SSS')'))
.show(10)
赞0
踩0