Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache spark 如何收集每组订单行(使用收集列表)?_Apache Spark_Apache Spark Sql - Fatal编程技术网

Apache spark 如何收集每组订单行(使用收集列表)?

Apache spark 如何收集每组订单行(使用收集列表)?,apache-spark,apache-spark-sql,Apache Spark,Apache Spark Sql,我将DF作为扁平订单行,列为: orderId (String), orderLine (struct) 1, {"sequence":1,"productId":11111111,"productName":"Blah","quantity":1,"unitPrice":{"net":65},"totalPrice":{"gross":67.84,"net":65,"tax":2.84}} 1, {"sequence":2,"productId":22222222,"productNa

我将DF作为扁平订单行,列为:

orderId (String), orderLine (struct)

1,  {"sequence":1,"productId":11111111,"productName":"Blah","quantity":1,"unitPrice":{"net":65},"totalPrice":{"gross":67.84,"net":65,"tax":2.84}}

1,  {"sequence":2,"productId":22222222,"productName":"Blah2","quantity":1,"unitPrice":{"net":100},"totalPrice":{"gross":104.38,"net":100,"tax":4.38}}
从中生成数据帧的最有效方法是:

orderId (string), orderLines (Array of orderLine Struct)

基本上,将给定订单的单个行结构分组/收集到一个行项目数组中-在本例中,订单行将有两个订单行项目作为数组的一部分。

我将使用
groupBy
collect\u list
函数,如下所示:

orders.groupBy("orderId").agg(collect_list("orderLine"))

请参阅(有关
groupBy
)和对象(有关
collect\u list
函数)。

我将使用
groupBy
collect\u list
函数,如下所示:

orders.groupBy("orderId").agg(collect_list("orderLine"))

请参阅(用于
groupBy
)和对象(用于
collect\u list
函数)。

图例这再次奏效!谢谢Jacek,你帮了我很大的忙。我还有带空格的csv标题,并试图获取一个select experssion(使用expr not selectExpr)来计算错误(简单的experssion,但不确定是否是反勾号导致了问题?expr(“
=“x”然后“y”或“z”END创建时的情况”)。别名(“a”)-有什么想法吗?请你再问一个问题好吗?我很感激。这是一个打字错误…再次感谢heaps!如果你能帮忙的话,那也太好了。我只是想和Spark一起站起来,所以非常感谢你的帮助!传奇又一次成功了!谢谢Jacek,你帮了我大忙。我也有带空格的csv标题,并尝试使用g设置一个select experssion(使用expr not selectExpr)来计算错误(简单的experssion确实但不确定是否是反勾号导致了问题?expr(“
创建时的情况下由”
=“x”然后“y”否则“z”结束”)。别名(“a”)-有什么想法吗?请你再问一个问题好吗?我会很感激的。让它工作起来是一个打字错误…再一次感谢堆!如果你能帮忙的话,那也太好了。我只是想和Spark一起站起来,所以非常感谢你的帮助!