1

我是新手sparklyr,也没有接受过任何正式的培训——这在这个问题之后会变得很明显。我也更多地站在统计学家的一边,这没有帮助。子设置 Spark 后出现错误DataFrame

考虑以下示例:

library(sparklyr)
library(dplyr)

sc <- spark_connect(master = "local[*]")
iris_tbl <- copy_to(sc, iris, name="iris", overwrite=TRUE)

#check column names
colnames(iris_tbl)

#subset so only a few variables remain  
subdf <- iris_tbl %>%
  select(Sepal_Length,Species)

subdf <- spark_dataframe(subdf)

#error happens when I try this operation
spark_session(sc) %>% 
  invoke("table", "subdf")

我得到的错误是:

Error: org.apache.spark.sql.catalyst.analysis.NoSuchTableException
        at org.apache.spark.sql.hive.client.ClientInterface$$anonfun$getTable$1.apply(ClientInterface.scala:122)
        at org.apache.spark.sql.hive.client.ClientInterface$$anonfun$getTable$1.apply(ClientInterface.scala:122)

还有其他几行错误。

我不明白为什么我会收到这个错误。"subdf" 是一个 Spark DataFrame

4

1 回答 1

1

要了解为什么这不起作用,您必须了解当您copy_to. 在内部sparklyr将使用 Spark Metastore 注册临时表,并将其或多或少地视为另一个数据库。这就是为什么:

spark_session(sc) %>% invoke("table", "iris")

可以找到“iris”表:

<jobj[32]>
  class org.apache.spark.sql.Dataset
  [Sepal_Length: double, Sepal_Width: double ... 3 more fields]

subdf另一方面只是普通的本地对象。它未在 Metastore 中注册,因此无法使用 Spark 目录访问它。要使其工作,您可以注册 Spark DataFrame

subdf <- iris_tbl %>% 
  select(Sepal_Length, Species)

spark_dataframe(subdf) %>%
  invoke("createOrReplaceTempView", "subdf")

或者copy_to如果数据小到足以由驱动程序处理:

subdf <- iris_tbl %>% 
  select(Sepal_Length, Species) %>% 
  copy_to(sc, ., name="subdf", overwrite=TRUE)

如果您使用 Spark 1.x createOrReplaceTempView,则应将其替换为registerTempTable.

于 2017-03-28T19:04:46.177 回答