我很确定以下查询曾经在Presto上为我工作:
select segment, sum(count)
from modeling_trends
where segment='2557172' and date = '2016-06-23' and count_time between '2016-06-23 14:00:00.000' and '2016-06-23 14:59:59.000';
group by 1;
Run Code Online (Sandbox Code Playgroud)
现在,当我运行它(在EMR上的Presto 0.147上)时,我收到错误,试图将varchar分配给日期/时间戳.
我可以使用它:
select segment, sum(count)
from modeling_trends
where segment='2557172' and date = cast('2016-06-23' as date) and count_time between cast('2016-06-23 14:00:00.000' as TIMESTAMP) and cast('2016-06-23 14:59:59.000' as TIMESTAMP)
group by segment;
Run Code Online (Sandbox Code Playgroud)
但感觉很脏......有没有更好的方法呢?
我有一个spark 2.0应用程序,它使用spark streaming(使用spark-streaming-kafka-0-10_2.11)从kafka读取消息.
结构化流看起来很酷,所以我想尝试迁移代码,但我无法弄清楚如何使用它.
在常规流媒体中,我使用kafkaUtils来创建Dstrean,在我传递的参数中是值deserializer.
在结构化流媒体中,doc说我应该使用DataFrame函数进行反序列化,但我无法确切地知道这意味着什么.
我查看了这个示例,例如我在Kafka中的Avro对象是退出复杂的,不能简单地像示例中的String一样进行转换.
到目前为止,我尝试了这种代码(我在这里看到了另一个问题):
import spark.implicits._
val ds1 = spark.readStream.format("kafka").
option("kafka.bootstrap.servers","localhost:9092").
option("subscribe","RED-test-tal4").load()
ds1.printSchema()
ds1.select("value").printSchema()
val ds2 = ds1.select($"value".cast(getDfSchemaFromAvroSchema(Obj.getClassSchema))).show()
val query = ds2.writeStream
.outputMode("append")
.format("console")
.start()
Run Code Online (Sandbox Code Playgroud)
我得到"数据类型不匹配:无法将BinaryType转换为StructType(StructField(...."
我怎样才能反序化值?
在我给我公司的讲座中,我建议将任何复杂的lambda转换为方法参考(更可读,更好的调试和测试),并被问到是否总是可行的.
我搜索并找不到无法用方法引用替换的lambda.
我对吗?(lambda总是可以用方法引用替换)