zhengruifeng commented on PR #40402:
URL: https://github.com/apache/spark/pull/40402#issuecomment-1477209035

   I save a df with UDT in pyspark, and then read it in python client, and it 
works fine. So I guess something is wrong in 
   `createDataFrame`
   
   vanilla PySpark:
   ```
   In [1]: from pyspark.ml.linalg import Vectors
   
   In [2]: df = spark.createDataFrame([(1.0, 1.0, Vectors.dense(0.0, 5.0)), 
(0.0, 2.0, Vectors.dense(1.0, 2.0)), (1.0, 3.0, Vectors.dense(2.0,
      ...:    ...: 1.0)), (0.0, 4.0, Vectors.dense(3.0, 3.0)),], ["label", 
"weight", "features"],)
   
   In [3]: df.write.parquet("/tmp/tmp.pq")
   ```
   
   Python Client:
   ```
   In [6]: df = spark.read.parquet("/tmp/tmp.pq")
   
   In [7]: df.schema
   Out[7]: StructType([StructField('label', DoubleType(), True), 
StructField('weight', DoubleType(), True), StructField('features', VectorUDT(), 
True)])
   
   In [8]: df.collect()
   Out[8]: 
   [Row(label=0.0, weight=4.0, features=DenseVector([3.0, 3.0])),
    Row(label=0.0, weight=2.0, features=DenseVector([1.0, 2.0])),
    Row(label=1.0, weight=3.0, features=DenseVector([2.0, 1.0])),
    Row(label=1.0, weight=1.0, features=DenseVector([0.0, 5.0]))]
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to