我正在更改DF的列位置,因为我会将其放入Cassandra中。 问题是我有22列以上,并且出现此错误:
<console>:1: error: too many elements for tuple: 38, allowed: 22
我正在使用此过程:
scala> val columns: Array[String] = firstDF.columns
columns: Array[String] = Array(HOCPNY, HOCOL, HONUMR, HOLINH, HODTTO, HOTOUR, HOCLIC, HOOE, HOTPAC, HODTAC, HOHRAC, HODESF, HOCDAN, HOCDRS, HOCDSL, HOOBS, HOTDSC, HONRAC, HOLINR, HOUSCA, HODTEA, HOHREA, HOUSEA, HODTCL, HOHRCL, HOUSCL, HODTRC, HOHRRC, HOUSRC, HODTRA, HOHRRA, HOUSRA, HODTCM, HOHRCM, HOUSCM, HODTUA, HOHRUA, HOUSER)
scala> val reorderedColumnNames: Array[String] = (hoclic,hotpac, hocdan, hocdrs,hocdsl,hocol,hocpny,hodesf,hodtac,hodtcl,hodtcm,hodtea,hodtra,hodtrc,hodtto,hodtua,hohrac,hohrcl,hohrcm,hohrea,hohrra,hohrrc,hohrua,holinh,holinr,honrac,honumr,hoobs,hooe,hotdsc,hotour,housca,houscl,houscm,housea,houser,housra,housrc)
<console>:1: error: too many elements for tuple: 38, allowed: 22
val reorderedColumnNames: Array[String] = (hoclic,hotpac,hocdan,hocdrs,hocdsl,hocol,hocpny,hodesf,hodtac,hodtcl,hodtcm,hodtea,hodtra,hodtrc,hodtto,hodtua,hohrac,hohrcl,hohrcm,hohrea,hohrra,hohrrc,hohrua,holinh,holinr,honrac,honumr,hoobs,hooe,hotdsc,hotour,housca,houscl,houscm,housea,houser,housra,housrc)
我该怎么解决?。
P.S。 Cassandra中的表具有以下结构:
CREATE TABLE tfm.foehis(hocpny text, hocol text,honumr int,holinh text,hodtto date,hotour text,hoclic int,hooe text,hotpac text,hodtac int,hohrac int,hodesf text,hocdan text,hocdrs text,hocdsl text, hoobs text,hotdsc int,honrac int,holinr int,housca text,hodtea int,hohrea int,housea text,hodtcl int,hohrcl int,houscl text,hodtrc int,hohrrc int,housrc text,hodtra int,hohrra int,housra text,hodtcm int,hohrcm int,houscm text,hodtua int,hohrua int,houser text, PRIMARY KEY((hoclic),hotpac,hocdan));
答案 0 :(得分:1)
val reorderedColumnNames: Array[String] = (hoclic,hotpac,hocdan,hocdrs,hocdsl,hocol,hocpny,hodesf,hodtac,hodtcl,hodtcm,hodtea,hodtra,hodtrc,hodtto,hodtua,hohrac,hohrcl,hohrcm,hohrea,hohrra,hohrrc,hohrua,holinh,holinr,honrac,honumr,hoobs,hooe,hotdsc,hotour,housca,houscl,houscm,housea,houser,housra,housrc)
问题出在此作业右侧的定义中。让我们快速浏览一下,用一个较小的示例会发生什么情况
scala> val x = ("hello", "world")
x: (String, String) = (hello,world)
x
变成了两个元素的元组!这是因为在scala (...)
中,语法使元组不是序列。相反,您应该使用类似的
scala> val x = Seq("hello", "world")
x: Seq[String] = List(hello, world)
要序列或
scala> val x = Array("hello", "world")
x: Array[String] = Array(hello, world)
创建一个数组。根据您的需要。