【问题标题】:Sparklyr "NoSuchTableException" error after subsetting data子集数据后的 Sparklyr“NoSuchTableException”错误
【发布时间】:2017-08-21 22:44:36
【问题描述】:

我是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

【问题讨论】:

    标签: r apache-spark apache-spark-sql sparklyr


    【解决方案1】:

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

    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

    【讨论】:

      猜你喜欢
      • 2018-10-05
      • 2018-07-08
      • 2016-01-10
      • 2018-07-28
      • 1970-01-01
      • 2017-08-31
      • 2017-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多