0
library(sparklyr)
library(dplyr)
library(Lahman)

spark_install(version = "2.0.0")
sc <- spark_connect(master = "local")

batting_tbl <- copy_to(sc, Lahman::Batting, "batting"); batting_tbl

batting_tbl %>% arrange(-index())
# Error: org.apache.spark.sql.AnalysisException: Undefined function: 'INDEX'. 
# This function is neither a registered temporary 
# function nor a permanent function registered in the database 'default'.; line 3 pos 10

Anyone know how to use dplyr to sort by index with a Spark (sparklyr) DataFrame?

4

1 回答 1

0

这是我能想到的最好的解决方案。虽然是正确的,但该sdf_with_unique_id函数在 62,000 行以上返回一些非常高的连续值。无论如何,这是使用 SparklyR 创建分布式索引列的一种方法。

library(sparklyr)
library(dplyr)
library(Lahman)

options(tibble.width = Inf) 
options(dplyr.print_max = Inf) 

spark_install(version = "2.0.0")
sc <- spark_connect(master = "local")

batting_tbl <- copy_to(sc, Lahman::Batting, "batting"); batting_tbl
tbl_uncache(sc, "batting")

y <- Lahman::Batting

batting_tbl <- batting_tbl %>% sdf_with_unique_id(., id = "id") # Note 62300 threshold for higher values
batting_tbl %>% arrange(-id)
于 2016-12-13T00:36:28.067 回答