Get the last element from Apache Spark SQL split() Function

后端 未结 4 942
太阳男子
太阳男子 2021-02-06 13:54

I want to get the last element from the Array that return from Spark SQL split() function.

split(4:3-2:3-5:4-6:4-5:2,\'-\')

I know it can get b

4条回答
  •  悲哀的现实
    2021-02-06 14:12

    You can also use SparkSql Reverse() function on a column after Split(). For example:

    SELECT reverse(split(MY_COLUMN,'-'))[0] FROM MY_TABLE

    Here [0] gives you the first element of the reversed array, which is the last element of the initial array.

提交回复
热议问题