gpt4 book ai didi

druid - Druid 中是否有可能有另一个时间戳作为维度?

转载 作者:行者123 更新时间:2023-12-01 20:25:40 28 4
gpt4 key购买 nike

是否可以让 Druid 数据源包含 2 个(或多个)时间戳?我知道 Druid 是基于时间的数据库,我对这个概念没有问题,但我想添加另一个维度,我可以使用它来处理时间戳

例如用户保留:指标肯定是指定到某个特定日期的,但我还需要根据用户注册日期创建群组,并将这些日期汇总到一周、几个月或仅过滤到特定时间段......

如果不支持该功能,是否有任何插件?有什么肮脏的解决方案吗?

最佳答案

虽然我宁愿等待 Druid 中时间戳维度完全支持的正式实现,但我发现了我一直在寻找的“肮脏”黑客。

数据源架构

首先,我想知道每天有多少用户登录,并且能够按日期/月/年群组进行聚合

这是我使用的数据架构:

"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"]
}
},

因此示例数据应类似于(每条记录都是登录事件):

{"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"}

如您所见,我计算这些指标的“主要”时间戳是 timestamp 字段,其中 register_time 只是 stringy 中的维度 - ISO 8601 UTC format .

聚合

现在,有趣的部分是:由于Time Format Extraction Function,我已经能够通过时间戳(日期)和注册时间(再次日期)进行聚合。

查询看起来像这样:

{
"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"
}

过滤

过滤的解决方案基于JavaScript Extraction Function我可以用它将日期转换为 UNIX 时间并在内部使用它(例如) bound filter :

{
"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}"
}
}
}

我尝试使用 javascript 过滤器“直接”过滤它,但我无法说服 druid 返回正确的记录,尽管我已经使用各种 JavaScript REPL 仔细检查了它,但是嘿,我不是 JavaScript专家。

关于druid - Druid 中是否有可能有另一个时间戳作为维度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38008495/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com