// var test6 = data1.withColumn(colName,(to_timestamp(col(colName))))
// 将TimestampType 转为StringType
var test6 = data1.withColumn(colName, col(colName).cast(StringType))
test6.show()
var type_test6 = test6.dtypes
type_test6.foreach(println)
参考资料:
1.https://www.cnblogs.com/mylittlecabin/p/11692363.html
2.https://stackoverflow.com/questions/40763796/convert-date-from-string-to-date-format-in-dataframes
3.https://www.nuomiphp.com/eplan/29850.html
4.https://stackoverflow.com/questions/40763796/convert-date-from-string-to-date-format-in-dataframes
5.https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-DateFunctions
6.https://www.jianshu.com/p/a87ac9f827e4
7.https://cloud.tencent.com/developer/ask/225235
8.https://blog.csdn.net/qq_33283716/article/details/81043264
https://www.cnblogs.com/mylittlecabin/p/11692363.htmlhttps://stackoverflow.com/questions/40763796/convert-date-from-string-to-date-format-in-dataframeshttps://www.nuomiphp.com/eplan/29850.html
PostgreSQL 的 to_timestamp 函数可以将字符串或整数转换为时间戳。它接受两个参数,第一个参数是要转换的值,第二个参数是该值的格式。例如,to_timestamp('2022-01-01', 'YYYY-MM-DD') 将返回 2022 年 1 月 1 日的时间戳。
private static void top(SparkSession sparkSession, Dataset<Row> logDS, Dataset<Row> userDataset) {
String startTi...
1.由于之前比较熟悉hive,于是用spark.sql写,其中包含hive的一些函数,如
unix_timestamp(regexp_replace(time, '[\\x2b]', ' '))是把表中的time里的'+'换成‘ ’,然后再换成时间戳的形式,但是原来的hql的写法执行时数据没有实现转换,hive为:
val df1 = spark.sql(s"select distinc...
org.apache.hive.service.cli.HiveSQLException: Error while compiling statement:
FAILED: SemanticException [Error 10015]:
Line 1:15 Arguments length mismatch
1.1时区设置
set spark.sql.session.timeZone=GMT+8; --设置为东八区时间
set spark.sql.session.timeZone=UTC; --设置为UTC时间
1.2时间戳格式化为日期
from_unixtime(floor(ts/1000),'yyyy-MM-dd')
--注释,使用此方法转换时间时,默认使用的是集群的时区(时区设置参考1.1)
--次函数的时间戳为10位的
val lines = ssc.socketTextStream("localhost", 9999)
val windowedWordCounts = lines.window(Seconds(4), Seconds(2))
windowedWordCounts.foreachRDD(
(rdd, time) => {
println(Instant.ofEpochMilli(time.mill...