如何访问数组列中的值? [英] How to access values in array column?

查看:19
本文介绍了如何访问数组列中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一列的数据框.该列的每一行都有一个字符串值数组:

I have a Dataframe with one column. Each row of that column has an Array of String values:

我的 Spark 2.2 数据框中的值

Values in my Spark 2.2 Dataframe

["123", "abc", "2017", "ABC"]
["456", "def", "2001", "ABC"]
["789", "ghi", "2017", "DEF"]

org.apache.spark.sql.DataFrame = [col: array]

root
|-- col: array (nullable = true)
|    |-- element: string (containsNull = true)

访问数组中元素的最佳方式是什么?例如,我想在 2017 年的第四个元素中提取不同的值(答案ABC"、DEF").

What is the best way to access elements in the array? For example, I would like extract distinct values in the fourth element for the year 2017 (answer "ABC", "DEF").

推荐答案

从 Spark 2.4.0 开始,有一个新函数 element_at($array_column, $index).

Since Spark 2.4.0, there is a new function element_at($array_column, $index).

查看 Spark 文档

这篇关于如何访问数组列中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆