Apache spark 使用自定义接收器的spark结构化流媒体中的输入行数
我在结构化流(spark 2.2.0)中使用了一个自定义接收器,并注意到spark为输入行数生成了不正确的度量——它始终为零 我的流结构:Apache spark 使用自定义接收器的spark结构化流媒体中的输入行数,apache-spark,apache-spark-sql,spark-streaming,spark-structured-streaming,Apache Spark,Apache Spark Sql,Spark Streaming,Spark Structured Streaming,我在结构化流(spark 2.2.0)中使用了一个自定义接收器,并注意到spark为输入行数生成了不正确的度量——它始终为零 我的流结构: StreamingQuery writeStream = session .readStream() .schema(RecordSchema.fromClass(TestRecord.class)) .option(OPTION_KEY_DELIMITER, OPTION_VALUE_
StreamingQuery writeStream = session
.readStream()
.schema(RecordSchema.fromClass(TestRecord.class))
.option(OPTION_KEY_DELIMITER, OPTION_VALUE_DELIMITER_TAB)
.option(OPTION_KEY_QUOTE, OPTION_VALUE_QUOTATION_OFF)
.csv(s3Path.toString())
.as(Encoders.bean(TestRecord.class))
.flatMap(
((FlatMapFunction<TestRecord, TestOutputRecord>) (u) -> {
List<TestOutputRecord> list = new ArrayList<>();
try {
TestOutputRecord result = transformer.convert(u);
list.add(result);
} catch (Throwable t) {
System.err.println("Failed to convert a record");
t.printStackTrace();
}
return list.iterator();
}),
Encoders.bean(TestOutputRecord.class))
.map(new DataReinforcementMapFunction<>(), Encoders.bean(TestOutputRecord.clazz))
.writeStream()
.trigger(Trigger.ProcessingTime(WRITE_FREQUENCY, TimeUnit.SECONDS))
.format(MY_WRITER_FORMAT)
.outputMode(OutputMode.Append())
.queryName("custom-sink-stream")
.start();
writeStream.processAllAvailable();
writeStream.stop();
我是否必须在自定义接收器中填充任何指标才能跟踪进度?或者,当FileStreamSource从s3 bucket读取数据时,它可能是一个问题吗?该问题与在我的自定义接收器中使用
dataset.rdd
有关,它创建了一个新计划,因此StreamExecution不知道它,因此无法获取度量
将
data.rdd.mapPartitions
替换为data.queryExecution.toRdd.mapPartitions
解决了这个问题。我也面临类似的问题。标准报告会有这个问题吗?在“标准报告”下是什么意思?如果您在结构化流媒体中实现自定义接收器,那么您不应该通过查询执行而不是直接从数据集使用rdd。请查看此内容
Streaming query made progress: {
"id" : "a8a7fbc2-0f06-4197-a99a-114abae24964",
"runId" : "bebc8a0c-d3b2-4fd6-8710-78223a88edc7",
"name" : "custom-sink-stream",
"timestamp" : "2018-01-25T18:39:52.949Z",
"numInputRows" : 0,
"inputRowsPerSecond" : 0.0,
"processedRowsPerSecond" : 0.0,
"durationMs" : {
"getOffset" : 781,
"triggerExecution" : 781
},
"stateOperators" : [ ],
"sources" : [ {
"description" : "FileStreamSource[s3n://test-bucket/test]",
"startOffset" : {
"logOffset" : 0
},
"endOffset" : {
"logOffset" : 0
},
"numInputRows" : 0,
"inputRowsPerSecond" : 0.0,
"processedRowsPerSecond" : 0.0
} ],
"sink" : {
"description" : "com.mycompany.spark.MySink@f82a99"
}
}