2016-08-18 14 views
1

私は、dapplyを使って行を変換する、とても単純なSparkRプログラムを作成しようとしています。私はあまりにも多くの小学校のミスをしていた単純なSparkR dapplyの例が動作しない

Error in split.default(output, seq(nrow(output))) : 
    group length is 0 but data length > 0 
    at org.apache.spark.api.r.RRunner.compute(RRunner.scala:108) 
    at org.apache.spark.sql.execution.r.MapPartitionsRWrapper.apply(MapPartitionsRWrapper.scala:59) 
    at org.apache.spark.sql.execution.r.MapPartitionsRWrapper.apply(MapPartitionsRWrapper.scala:29) 
    at org.apache.spark.sql.execution.MapPartitionsExec$$anonfun$6.apply(objects.scala:178) 
    at org.apache.spark.sql.execution.MapPartitionsExec$$anonfun$6.apply(objects.scala:175) 

答えて

2

lines <- read.text("/path/to/file.txt") 

resultingSchema <- structType(structField("line", "string")) 

linesmapped <- dapply(lines, function(line) { 
    y <- list() 
    y[[1]] <- paste(line[[1]], "1", sep = ":")  
}, resultingSchema) 

head(linesmapped) 

これは私が取得エラーは次のとおりです。しかし、私は悩み、それを実行しています。 (SparkRのドキュメントは、現時点では非常に希薄であるため)私は、これは他の誰かに役立ちます願っています:dapplyと

lines <- read.text("/path/to/file.txt") 
resultingSchema <- structType(structField("value", "string")) 

ldf <- dapply(lines, function(x) {  
    x <- transform(x, value=paste(value, "$", sep="")) 
}, resultingSchema) 

head(collect(ldf)) 
0

基本的な事はdapply内の関数は、データフレームと出力もデータフレームになります期待していることを覚えておくことです。

したがって、パーティションがdapply関数にネイティブRデータフレームとして渡され、それに従って関数が適用されると考えてください。

関連する問題