在kafka中有流数据,连续浮点数:
2016-11-23 :00
2016年-11-23 11:03:00
2016年-11-23 11:05:00
.
我想计算一下在过去25天中,这些浮点数的平均值和方差在上午11:00到12:00之间。
火花流是否适合处理此问题?
非常感谢!
发布于 2016-11-23 10:18:19
@明,你可以用它作为摘要
val sparkConf = new SparkConf().setAppName("StreamCount")
val ssc = new StreamingContext(sparkConf, Seconds(2))
//update the time according to your need
// Create direct kafka stream with brokers and topics
val topicsSet = topics.split(",").toSet
val kafkaParams = Map[String, String]("metadata.broker.list" -> brokers)
val messages = KafkaUtils.createDirectStream[String, String, StringDecoder, StringDecoder](
ssc, kafkaParams, topicsSet)
// Get the lines, and timestamp data along with the float values
SELECT float_number
FROM [YourTable]
WHERE [YourDate] BETWEEN DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0) + '11:00' AND DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), 0) + '12:00'
//store it to a data frame
df.select(avg($"float_number")).show()https://stackoverflow.com/questions/40754758
复制相似问题