我在spark scala中使用下面的代码来获得分区列。
scala> val part_cols= spark.sql(" describe extended work.quality_stat ").select("col_name").as[String].collect()
part_cols: Array[String] = Array(x_bar, p1, p5, p50, p90, p95, p99, x_id, y_id, # Partition Information, # col_name, x_id, y_id, "", # Detailed Table Information, Database, Table, Owner, Created Time, Last Access, Created By, Type, Provider, Table Properties, Location, Serde Library, InputFormat, OutputFormat, Storage Properties, Partition Provider)
scala> part_cols.takeWhile( x => x.length()!= 0 ).reverse.takeWhile( x => x != "# col_name" )
res20: Array[String] = Array(x_id, y_id)
我需要在python中获得类似的输出。我正在努力在python中复制相同的代码,以便数组操作获得[y\u id,x\u id]。
下面是我试过的。
>>> part_cols=spark.sql(" describe extended work.quality_stat ").select("col_name").collect()
是否可以使用python。
1条答案
按热度按时间s8vozzvw1#
part_cols
问题是一个行数组。所以第一步是把它转换成一个字符串数组。现在可以使用
最后,可以从列表中提取一个片段,将这两个值作为start和end
此切片将包含值
如果输出真的应该反转,切片
将包含值