VectorUDT usage

亡梦爱人 提交于 2019-11-27 08:29:57

问题


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:


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
    


来源:https://stackoverflow.com/questions/45809316/vectorudt-usage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!