【问题标题】:What type to give for java.time.Instant while fetching StructType from case class?从案例类中获取 StructType 时为 java.time.Instant 提供什么类型?
【发布时间】:2018-10-28 01:19:23
【问题描述】:

我有一个案例类

case class A(tm: java.time.Instant)

在尝试使用

获取此案例类的 StructType 时
ScalaReflection.schemaFor[A].dataType.asInstanceOf[StructType]

我收到以下错误

[error] Exception in thread "main" java.lang.ExceptionInInitializerError
[error]     at sample.spark.streaming.StructuredStreaming.main(StructuredStreaming.scala)
[error] Caused by: java.lang.UnsupportedOperationException: Schema for type java.time.Instant is not supported

谁能告诉我如何解决这个问题?我进行了很多搜索,但找不到任何解决此问题的方法。不,我无法更改案例类中的 java.time.Instant 类型。

【问题讨论】:

    标签: scala apache-spark spark-structured-streaming


    【解决方案1】:

    tl;dr 您根本不能将java.time.* 类用作架构的一部分(在结构化查询/数据集中)。

    但是,您可以将数据集作为 DataFramemapjava.time.Instant 字段加载到支持的类型(即,Encoder 可用)。

    有关可用编码器列表,请参阅org.apache.spark.sql.SQLImplicits


    不,我无法更改案例类中的 java.time.Instant 类型。

    那么,您必须创建自己的案例类以在 Spark 中使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多