Hi Rajesh,
Can you recheck the version and your code again?
I tried similar below code and its work fine (compiles and executes)...
// Apply a schema to an RDD of Java Beans and register it as a table.
JavaSchemaRDD schemaPeople = sqlCtx.applySchema(people, Person.class);
schemaPeople.registerAsTable("people");
// SQL can be run over RDDs that have been registered as tables.
JavaSchemaRDD teenagers = sqlCtx.sql("SELECT * FROM people WHERE age >=
13");
// The results of SQL queries are SchemaRDDs and support all the normal RDD
operations.
// The columns of a row in the result can be accessed by ordinal.
List<String> teenagerNames = teenagers.map(new Function<Row, String>() {
public String call(Row row) {
return "Name "+row.getString(1)+" - Age: " + row.getInt(0);
}
}).collect();
for (String name: teenagerNames) {
System.out.println(name);
}
Can you try to replace Test.class with ANAInventory.class and check
JavaRDD<ANAInventory> retrdd = jrdd.map(f);
JavaSchemaRDD schemaPeople = sqlCtx.applySchema(retrdd, Test.class);
However it should compile fine and may show issues while execution. Can you try
with spark sql example and share the result?
Thanks,
Ravi
Date: Sat, 2 Aug 2014 18:36:26 +0530
Subject: Re: spark sql
From: [email protected]
To: [email protected]
Hi Team,
Could you please help me to resolve above compilation issue.
Regards,
Rajesh
On Sat, Aug 2, 2014 at 2:02 AM, Madabhattula Rajesh Kumar <[email protected]>
wrote:
Hi Team,
I'm not able to print the values from Spark Sql JavaSchemaRDD. Please find
below my code
JavaSQLContext sqlCtx = new JavaSQLContext(sc);
NewHadoopRDD<ImmutableBytesWritable, Result> rdd = new
NewHadoopRDD<ImmutableBytesWritable, Result>(
JavaSparkContext.toSparkContext(sc),
TableInputFormat.class, ImmutableBytesWritable.class,
Result.class, conf);
JavaRDD<Tuple2<ImmutableBytesWritable, Result>> jrdd = rdd
.toJavaRDD();
ForEachFunction f = new ForEachFunction();
JavaRDD<ANAInventory> retrdd = jrdd.map(f);
JavaSchemaRDD schemaPeople = sqlCtx.applySchema(retrdd, Test.class);
schemaPeople.registerAsTable("retrdd");
JavaSchemaRDD teenagers = sqlCtx.sql("SELECT * FROM retrdd");
When i add below code. It is giving compilation issue. Could you please help me
to resolve this issue.
List<String> teenagerNames = teenagers.map(new Function<Row, String>() {
public String call(Row row) {
return null; } }).collect();
for (String name: teenagerNames) {
System.out.println(name);
}
Compilation issue :
The method map(Function<Row,R> in the type JavaSchemaRDD is not applicable for
the arguments (new Functiona<Row, String>(){})
Thank you for your help
Regards,
Rajesh