我有一个Spark DataFrame
,其中一列是Vector
类型。当我在它上面创建一个 Hive 表时,我不知道它相当于哪种类型
CREATE EXTERNAL TABLE mix (
topicdist ARRAY<DOUBLE>
)
STORED AS PARQUET
LOCATION 's3://path/to/file.parquet'
表创建似乎有效并返回正常,但是当我尝试时
select topicdist from mix limit 1
我得到的错误:
Failed with exception java.io.IOException:java.lang.RuntimeException: Unknown hive type info array<double> when searching for field type
>Vector
是Spark用户定义的类型,它在内部存储为一个
StructType(Seq(
StructField("type", ShortType, true),
StructField("size",IntegerType, true),
StructField("indices", ArrayType(IntegerType, true), true),
StructField("values",ArrayType(DoubleType, true), true)
))
因此,您需要:
CREATE EXTERNAL TABLE mix (
topicdist struct<type:tinyint,size:int,indices:array<int>,values:array<double>>
)
STORED AS PARQUET
LOCATION 's3://path/to/file.parquet'
请记住,生成的列不会被解释为 Spark Vector
。