我有一个Dataset.where("theColumn == number")
,因此没有空的theColumn
字段。数据集是从Cassandra数据库收到的,所有数据都存在。
Dataset.groupBy("theColumn").count().show();
返回一个空表,尽管从数据库收到的数据集中存在所有行。
可能是什么问题?如何解决?
我在配置中设置了spark.default.parallelism
值,但没有发生任何变化。我没有设置任何其他特殊配置。
我在JavaDStream.foreachRDD中调用该方法并运行JavaStreamingContext
和SparkSession
。
SparkSession:
SparkSession spark = SparkSession
.builder()
.master("local[4]")
.appName(AppName)
.config("spark.cassandra.connection.host", ip)
.config("spark.cassandra.connection.port", port)
.config("spark.driver.allowMultipleContexts", "true")
.getOrCreate();
StreamingContext:
SparkConf sparkConfig = new SparkConf().setMaster("local[4]")
.setAppName(AppName2)
.set("spark.cassandra.connection.host", ip)
.set("spark.cassandra.connection.port", port)
.set("spark.driver.allowMultipleContexts", "true");
JavaStreamingContext jssc = new JavaStreamingContext(sparkConfig , batchInterval);
groupBy()位置:
logLines.foreachRDD(rdd -> {
javaFunctions(rdd).writerBuilder("my_keyspace", "table_name", mapToRow(Table.class)).saveToCassandra();
Dataset<Row> ds = spark.read()
.format("org.apache.spark.sql.cassandra")
.options(new HashMap<String, String>() {
{
put("keyspace", "my_keyspace");
put("table", "table_name");
}
}).load().where("theColumn == number").cache();
ds.show(); // Prints a correct table.
Dataset<Row> ds2 = ds.groupBy("theColumn").count().cache();
ds2.show(); // Prints an empty table.
});
ds.count()
和ds.dropDuplicates.count()
都返回0
Apache Spark 2.2.0版
似乎同时使用JavaStreamingContext
和SparkSession
时会导致问题。