【问题标题】:Spark Streaming 2.3.1 Type Casting: String to TimestampSpark Streaming 2.3.1 类型转换:字符串到时间戳
【发布时间】: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


【解决方案1】:
猜你喜欢
  • 2018-01-15
  • 2021-08-04
  • 2018-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-29
  • 1970-01-01
  • 2018-07-23
相关资源
最近更新 更多