VectorUDT usage

2019-01-20 16:20发布

I have to get the datatype and do a case match and convert it to some required format. But the usage of org.apache.spark.ml.linalg.VectorUDT is showing VectorUDT is private. Also I specifically need to use org.apache.spark.ml.linalg.VectorUDT and not org.apache.spark.mllib.linalg.VectorUDT. Can someone suggest how to go about this?

1条回答
劫难
2楼-- · 2019-01-20 16:56

For org.apache.spark.ml.linalg types you should specify schema using org.apache.spark.ml.linalg.SQLDataTypes which provide singleton instances of the private UDT types:

  • MatrixType for matrices (org.apache.spark.ml.linalg.Matrix).

    scala> org.apache.spark.ml.linalg.SQLDataTypes.MatrixType.getClass
    res0: Class[_ <: org.apache.spark.sql.types.DataType] = class org.apache.spark.ml.linalg.MatrixUDT
    
  • VectorType for vectors (org.apache.spark.ml.linalg.Vector).

    scala> org.apache.spark.ml.linalg.SQLDataTypes.VectorType.getClass
    res1: Class[_ <: org.apache.spark.sql.types.DataType] = class org.apache.spark.ml.linalg.VectorUDT
    
查看更多
登录 后发表回答