2016-09-30 8 views
3

私はScalaでspark-cassandra-connectorを使用していますが、cassandraからデータを読み込み、toArrayメソッドで表示します。 しかし、クラスのメンバーではありませんが、APIに示されているというエラーメッセージが表示されます。誰かが私のエラーを見つけるのを手伝ってくれましたか?ここでSpark-cassandra-connector:toArrayが機能しません

が私のファイルです:

build.sbt:

name := "Simple_Project" 

version := "1.0" 

scalaVersion := "2.11.8" 

assemblyMergeStrategy in assembly := { 
case PathList("META-INF", xs @ _*) => MergeStrategy.discard 
case x => MergeStrategy.first 
} 

libraryDependencies += "org.apache.spark" %% "spark-core" % "2.0.0-preview" 
libraryDependencies += "org.apache.spark" %% "spark-sql" % "2.0.0-preview" 
resolvers += "Spark Packages Repo" at "https://dl.bintray.com/spark-packages/maven" 
libraryDependencies += "datastax" % "spark-cassandra-connector" % "2.0.0-M2-s_2.11" 

SimpleScala.scala:cqlshため

import org.apache.spark.SparkContext 
import org.apache.spark.SparkContext._ 
import org.apache.spark.SparkConf 
import org.apache.spark.sql._ 
import org.apache.spark.sql.functions._ 
import com.datastax.spark.connector._ 
import com.datastax.spark.connector.rdd._ 
import org.apache.spark.sql.cassandra._ 
import org.apache.spark.sql.SQLContext 
import com.datastax.spark.connector.cql.CassandraConnector._ 

object SimpleApp { 

    def main(args: Array[String]) { 

    val conf = new SparkConf().setAppName("Simple Application") 
    conf.set("spark.cassandra.connection.host", "127.0.0.1") 
    val sc = new SparkContext(conf) 

    val rdd_2 = sc.cassandraTable("test_2", "words") 

    rdd_2.toArray.foreach(println) 
    } 
} 

機能:

CREATE KEYSPACE test_2 WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': 1 }; 

CREATE TABLE test_2.words (word text PRIMARY KEY, count int); 
INSERT INTO test_2.words (word, count) VALUES ('foo', 20); 
INSERT INTO test_2.words (word, count) VALUES ('bar', 20); 

エラーメッセージ:

事前に
[info] Loading global plugins from /home/andi/.sbt/0.13/plugins 
[info] Resolving org.scala-sbt.ivy#ivy;2.3.0-sbt-2cc8d2761242b072cedb0a04cb39435[info] Resolving org.fusesource.jansi#jansi;1.4 ... 
[info] Done updating. 
[info] Loading project definition from /home/andi/test_spark/project 
[info] Updating {file:/home/andi/test_spark/project/}test_spark-build... 
[info] Resolving org.scala-sbt.ivy#ivy;2.3.0-sbt-2cc8d2761242b072cedb0a04cb39435[info] Resolving org.fusesource.jansi#jansi;1.4 ... 
[info] Done updating. 
[info] Set current project to Simple_Project (in build file:/home/andi/test_spark/) 
[info] Compiling 1 Scala source to /home/andi/test_spark/target/scala-2.11/classes... 
[error] /home/andi/test_spark/src/main/scala/SimpleApp.scala:50: value toArray is not a member of com.datastax.spark.connector.rdd.CassandraTableScanRDD[com.datastax.spark.connector.CassandraRow] 
[error] rdd_2.toArray.foreach(println) 
[error]  ^
[error] one error found 
[error] (compile:compileIncremental) Compilation failed 

多くのおかげで、 アンディ

答えて

3

CassandraTableScanRDD.toArray方法は非推奨となり、スパークカサンドラコネクタの2.0.0リリース以降、削除されました。この方法は、1.6.0のリリースまで存在していました。代わりにcollectメソッドを使用できます。

0

残念ながら、文書Spark Cassandra ConnectorはまだtoArrayを使用しています。とにかく、ここがうまくいくでしょう。

rdd_2.collect.foreach(println) 
関連する問題