【发布时间】:2018-09-04 03:47:28
【问题描述】:
我正在使用 apsche spark 流式传输 2.3.1,我正在接收一个流,其中包含格式为“HH:mm:ss.xxxxxxxxx”的时间戳值 (13:09:05.761237147) 作为字符串。
我需要将此字符串转换为时间戳数据类型。
spark = SparkSession \
.builder \
.appName("abc") \
.getOrCreate()
schema = StructType().add("timestamp", "string").add("object", "string").add("score", "double")
lines = spark \
.readStream \
.option("sep", ",") \
.schema(schema) \
.csv("/path/to/folder/")
有什么建议如何将“时间戳”转换为时间戳数据类型?
【问题讨论】:
-
lines.withColumn('timestamp' col('timestamp').cast('timestamp'))?由于您没有关联任何日期,我相信它会在时间戳中采用今天的日期。
标签: apache-spark casting pyspark spark-streaming