Apache spark 卡夫卡主题中没有数据时如何控制火花流的处理
我使用的是spark sql 2.4.1、spark-cassandra-connector_2.11-2.4.1.jar和java8 我有这样的卡桑德拉桌子:Apache spark 卡夫卡主题中没有数据时如何控制火花流的处理,apache-spark,apache-spark-sql,spark-streaming,datastax-enterprise,Apache Spark,Apache Spark Sql,Spark Streaming,Datastax Enterprise,我使用的是spark sql 2.4.1、spark-cassandra-connector_2.11-2.4.1.jar和java8 我有这样的卡桑德拉桌子: CREATE company(company_id int,start_date date,company_name text,PRIMARY_KEY(company_id,start_date)) 使用聚类顺序(开始日期描述); 这里的字段start_date是一个派生字段,在业务逻辑中计算 我有spark sql流代码,在其中我调
CREATE company(company_id int,start_date date,company_name text,PRIMARY_KEY(company_id,start_date))
使用聚类顺序(开始日期描述);
这里的字段start_date是一个派生字段,在业务逻辑中计算
我有spark sql流代码,在其中我调用了下面的mapFunction
公共静态映射函数mapFunInsertCompany=(记录)->{
CompanyTransformed rec=新CompanyTransformed();
rec.setCompany_id(record.getCompanyId());
rec.setCompany_name(record.getCompanyName());
if(record.getChangeFlag().equalsIgnoreCase(“I”)和&record.getCreateDate()!=null)
rec.setStart_date(record.getCreateDate());
if(record.getChangeFlag().equalsIgnoreCase(“U”))
rec.setStart_date(新日期(CommonUtils.today().getTime()+86400000));
返回记录;
};
当启动我的消费者并且卡夫卡主题中没有记录时,流媒体流持续调用上面的map函数
因为record.getCreateDate()=null开始日期设置为null
但开始日期是我的C*表中主键的一部分,因此,插入失败和spark无限期等待,无法恢复数据并将其保存到C*表中
所以
1.应该做些什么来修复它?有什么线索吗
第二部分:
.foreachBatch((batchDf, batchId) -> {
System.out.println( "latestRecords batchDf.isEmpty : " +
batchDf.isEmpty() + "\t length : " + batchDf.rdd().getPartitions().length);
}
以
latestRecords batchDf.isEmpty : false length : 6
那么如何检查isEmpty呢?正如我所说:错
第四部分:
当我启动consumer时,主题中没有可用的数据。
即使数据集没有显示数据,但计数显示为3,如下所示输出,这怎么可能
如果我试试这个
输出
latestRecords batchDf.rdd().count : 3 batchDf.count :3
spark流媒体应用程序面临一个常见问题。当源中没有数据时(在您的案例中是卡夫卡主题),Spark会创建一个。如果RDD为空,可以通过添加
if(!rdd.isEmpty)
在调用方法mapFunInsertCompany之前
请也看看这个
if(!rdd.isEmpty)