将列表/数据框(R)转换为databricks中的data.table

问题描述 投票:0回答:1

我通过运行以下命令在 Databricks R 中创建了一个对象:-

data1_df <- spark_read_table(sc, "data1") 

对象类型显然是“列表”

对象的部分结构是这样的:-

List of 6
 $ ChildObjectName      :List of 1
  ..$ con:List of 10
  .. ..$ master     : chr "sparklyr://localhost:65529/65529"
  .. ..$ method     : chr "gateway"
  .. ..$ app_name   : chr "sparklyr"
  .. ..$ config     :List of 8
  .. .. ..$ sparklyr.cancellable                     : logi FALSE
  .. .. ..$ spark.env.SPARK_LOCAL_IP.local           : chr "127.0.0.1"
  .. .. ..$ sparklyr.connect.csv.embedded            : chr "^1.*"
  .. .. ..$ spark.sql.legacy.utcTimestampFunc.enabled: logi TRUE
  .. .. ..$ sparklyr.connect.cores.local             : int 96
  .. .. ..$ spark.sql.shuffle.partitions.local       : int 96
  .. .. ..$ sparklyr.shell.name                      : chr "sparklyr"
  .. .. ..$ spark.r.libpaths                         : chr "/local_disk0/.ephemeral_nfs/envs/rEnv-2742b6da-b682-4cbd-bd6a-5b7b3c426ff4,/databricks/spark/R/lib,/local_disk0"| __truncated__
  .. ..$ state      :<environment: 0x55f774bed4e0> 
  .. ..$ spark_home : NULL
  .. ..$ backend    : 'sockconn' int 7
  .. .. ..- attr(*, "conn_id")=<externalptr> 
  .. ..$ monitoring : 'sockconn' int 8

它包含 1500940 行。

我正在尝试使用此命令通过引用创建一个 data.table 对象(R):-

setDT(data1_df) 

并且一直收到此错误:-

Error in setDT(data1_df) : 
  All elements in argument 'x' to 'setDT' must be of same length, but the profile of input lengths (length:frequency) is: [5:1, 3:2, 1:3]
The first entry with fewer than 5 entries is 1
Error in setDT(data1_df): All elements in argument 'x' to 'setDT' must be of same length, but the profile of input lengths (length:frequency) is: [5:1, 3:2, 1:3]
Error in setDT(data1_df): All elements in argument 'x' to 'setDT' must be of same length, but the profile of input lengths (length:frequency) is: [5:1, 3:2, 1:3]
The first entry with fewer than 5 entries is 1

我不明白为什么。对此的任何建议都会有很大的帮助。我哪里错了?

但是当我运行这个命令时,它起作用了,尽管需要 9 分钟。

致以诚挚的问候

迪帕克

r databricks
1个回答
0
投票

setDT
获取列表并尝试生成索引
data.table
数据帧,它需要相同的列表元素长度。

一个最小的例子是

library(data.table)

lst <- list(1:5, 1:6)

setDT(lst)

Error: All elements in argument 'x' to 'setDT' must be of same length, but 
the profile of input lengths (length:frequency) is: [5:1, 6:1]
The first entry with fewer than 6 entries is 1.

另一方面

data.table(lst)
           lst
        <list>
1:   1,2,3,4,5
2: 1,2,3,4,5,6

之所以有效,是因为它只是将每行的列表元素放入索引的

data.table
结构中。

© www.soinside.com 2019 - 2024. All rights reserved.