是否有可能拥有带有2个(或多个)时间图的德鲁伊数据源?我知道德鲁伊是基于时间的数据库,我对这个概念没有任何问题,但我想添加另一个维度,我可以像时间戳一样工作
例如用户保留:度量肯定是指定到某个特定日期,但我还需要根据用户的注册日期创建同类群组,并将这些日期汇总到几周,几个月或过滤到特定时间段....
如果不支持该功能,是否有任何插件?有任何脏问题?
虽然我宁愿等待时间戳维度的官方实施全面支持德鲁伊,但我发现了一个我一直在寻找的"脏"黑客.
数据源架构
首先,我想知道,每天登录的用户数量,能够按日期/月/年同期汇总
这是我使用的数据模式:
"dataSchema": {
"dataSource": "ds1",
"parser": {
"parseSpec": {
"format": "json",
"timestampSpec": {
"column": "timestamp",
"format": "iso"
},
"dimensionsSpec": {
"dimensions": [
"user_id",
"platform",
"register_time"
],
"dimensionExclusions": [],
"spatialDimensions": []
}
}
},
"metricsSpec": [
{ "type" : "hyperUnique", "name" : "users", "fieldName" : "user_id" }
],
"granularitySpec": {
"type": "uniform",
"segmentGranularity": "HOUR",
"queryGranularity": "DAY",
"intervals": ["2015-01-01/2017-01-01"]
}
},
Run Code Online (Sandbox Code Playgroud)
所以样本数据应该类似(每个记录都是登录事件):
{"user_id": 4151948, "platform": "portal", "register_time": "2016-05-29T00:45:36.000Z", "timestamp": "2016-06-29T22:18:11.000Z"}
{"user_id": 2871923, "platform": "portal", "register_time": "2014-05-24T10:28:57.000Z", "timestamp": "2016-06-29T22:18:25.000Z"}
Run Code Online (Sandbox Code Playgroud)
如您所见,我计算这些指标的"主"时间戳是时间戳字段,其中register_time只是字符串中的维度 - ISO 8601 UTC格式.
汇总
现在,对于有趣的部分:由于时间格式提取功能,我已经能够通过时间戳(日期)和register_time(再次约会)进行聚合
查询看起来像这样:
{
"intervals": "2016-01-20/2016-07-01",
"dimensions": [
{
"type": "extraction",
"dimension": "register_time",
"outputName": "reg_date",
"extractionFn": {
"type": "timeFormat",
"format": "YYYY-MM-dd",
"timeZone": "Europe/Bratislava" ,
"locale": "sk-SK"
}
}
],
"granularity": {"timeZone": "Europe/Bratislava", "period": "P1D", "type": "period"},
"aggregations": [{"fieldName": "users", "name": "users", "type": "hyperUnique"}],
"dataSource": "ds1",
"queryType": "groupBy"
}
Run Code Online (Sandbox Code Playgroud)
过滤
过滤解决方案基于JavaScript提取功能,我可以使用它将日期转换为UNIX时间并在内部使用它(例如)绑定过滤器:
{
"intervals": "2016-01-20/2016-07-01",
"dimensions": [
"platform",
{
"type": "extraction",
"dimension": "register_time",
"outputName": "reg_date",
"extractionFn": {
"type": "javascript",
"function": "function(x) {return Date.parse(x)/1000}"
}
}
],
"granularity": {"timeZone": "Europe/Bratislava", "period": "P1D", "type": "period"},
"aggregations": [{"fieldName": "users", "name": "users", "type": "hyperUnique"}],
"dataSource": "ds1",
"queryType": "groupBy"
"filter": {
"type": "bound",
"dimension": "register_time",
"outputName": "reg_date",
"alphaNumeric": "true"
"extractionFn": {
"type": "javascript",
"function": "function(x) {return Date.parse(x)/1000}"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我试图用javascript过滤器"直接"过滤它,但我无法说服德鲁伊回复正确的记录,虽然我用各种JavaScript REPL双重检查,但是,嘿,我不是JavaScript专家.
小智 3
不幸的是,Druid 只有一个时间戳列可用于进行汇总,而且当前 Druid 将所有其他列视为字符串(当然指标除外),因此您可以添加另一个带有时间戳值的字符串列,但唯一的事情是你可以用它做的就是过滤。我想你也许可以用这种方式破解它。希望未来德鲁伊将允许不同类型的列,也许时间戳将是其中之一。