擅长:python、mysql、java
<p><code>StructType</code>/<code>Row</code>表示固定大小的<a href="https://en.wikipedia.org/wiki/Product_type" rel="nofollow noreferrer">product type</a>对象,不能用于表示可变大小的对象。在</p>
<p>若要表示同构集合,请使用<code>list</code>作为外部类型,<code>ArrayType</code>作为SQL类型:</p>
<pre><code>udf(lambda x: [2*e for e in x], ArrayType(IntegerType()))
</code></pre>
<p>或(Spark 2.2或更高版本):</p>
^{pr2}$
<p>在Spark 2.4或更高版本中,您可以使用<code>transform</code></p>
<pre><code>from pyspark.sql.functions import expr
expr("tranform(input_column, x -> 2 * x)")
</code></pre>