Home > other >  About the spark and Cassandra combine problem!!!! Website run case impassability!!!!!!!!!!!
About the spark and Cassandra combine problem!!!! Website run case impassability!!!!!!!!!!!

Time:09-26

About the spark and Cassandra combine problem!!!! Website run case impassability!!!!!!!!!!!
Post code directly, I basically is a case according to the website to!!!!!! As follows: not enough, only have a few left... Hope everybody to help me

Maven:


Com. Datastax. Spark
The spark - Cassandra - connector_2. 10 & lt;/artifactId>
1.6.0 - M2 & lt;/version>


Com. Datastax. Spark
Spark - Cassandra - connector - java_2. 10 & lt;/artifactId>
1.6.0 - M1 & lt;/version>


Org. Apache. Spark
The spark - core_2. 10 & lt;/artifactId>
1.6.1 & lt;/version>


Org. Apache. Spark
The spark - streaming_2. 10 & lt;/artifactId>
1.6.1 & lt;/version>


Org. Apache. Spark
The spark - sql_2. 10 & lt;/artifactId>
1.6.1 & lt;/version>


Com. Datastax. Cassandra
Cassandra - driver - core
3.0.1 & lt;/version>


Com. Datastax. Cassandra
Cassandra - driver - mapping
3.0.1 & lt;/version>


And then directly is the test code:
/* *
* access connection
*/
Public static JavaSparkContext getConnection () {
//get connection
SparkConf conf=new SparkConf (true). SetAppName (" spark and Cassandra ")
//. The set (" spark. Testing. The memory ", "2147480000")//allocated memory, the memory of less than 512 m
Set (" spark. Cassandra. Connection. The host ", "192.168.1.13");
JavaSparkContext sc=new JavaSparkContext (" spark://192.168.1.13:7077 ", "SparkOptionCassandra1", the conf);
System. The out. Println (sc) master () + ":" + sc. AppName ());
Return sc;
}
/* *
* read the spark Cassandra table data 22222
*/
Public static void getDataFromCassandra () {
JavaSparkContext sc=getConnection ();
Try {
JavaRDD CassandraRowsRDD=javaFunctions (sc). CassandraTable (" XMMSG ", "people")
. The map (new Function () {
Public String call (CassandraRow CassandraRow) throws the Exception {
Return cassandraRow. ToString ();
}
});
System. The out. Println (" Data as CassandraRows: \ n "+ StringUtils. Join (" \ n", cassandraRowsRDD. Collect ()));
} the catch (Exception e) {
e.printStackTrace();
} the finally {
Sc. Stop ();
Sc. The close ();
}
}

Then an error message:



Then save is: hey
/* *
* persisting data to Cassandra database
*/
Public static void savePerson () {
Try {
JavaSparkContext sc=getConnection ();
List People=Arrays. AsList (
Person. NewInstance (1, "John", new Date ()),
Person. NewInstance (2, "Anna", new Date ()),
Person. NewInstance (3, "Andrew", new Date ())
);
JavaRDD RDD=sc. Parallelize (people);
JavaFunctions (RDD). WriterBuilder (" XMMSG ", "people", mapToRow (Person. Class)). SaveToCassandra ();
} the catch (Exception e) {
e.printStackTrace();
}
}

Error message:


please god help me, thank you!!!!!!!!!!!!!!!!!!!


Have a question about sparksql:
Public static void writeResouces () {
JavaSparkContext sc=getConnection (" first ", "local");
SQLContext SQLContext=new SQLContext (sc);
DataFrame df=sqlContext read (). The format (" json "). The load (" c://test//people. The json ");
//don't know why the output file is folder? The Windows and Linux the difference?
Df. Select (" name ", "age"). The write (). The format (" parquet "). The save (" c://test/namesAndAges2 parquet ");
//so to query
DataFrame df2=sqlContext. SQL (" SELECT * FROM parquet. ` c://test/namesAndAges2 parquet ");
System. The out. Println (df2. The count ());
}
Why am I in win local produce is namesAndAges2. Parquet folder, inside what things all have no,

on Linux can generate the file, but can't read!!!!!

CodePudding user response:

Why no one, ah...
  • Related