Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Forever310
druid
提交
73623467
D
druid
项目概览
Forever310
/
druid
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
druid
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
73623467
编写于
8月 26, 2014
作者:
G
Gian Merlino
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #703 from metamx/fix-period-granularity
fix granularity for precise periods with non-zero origin
上级
0d32466c
a1c8b23b
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
128 addition
and
61 deletion
+128
-61
processing/src/main/java/io/druid/granularity/DurationGranularity.java
...c/main/java/io/druid/granularity/DurationGranularity.java
+6
-2
processing/src/main/java/io/druid/granularity/PeriodGranularity.java
...src/main/java/io/druid/granularity/PeriodGranularity.java
+7
-4
processing/src/test/java/io/druid/granularity/QueryGranularityTest.java
.../test/java/io/druid/granularity/QueryGranularityTest.java
+115
-55
未找到文件。
processing/src/main/java/io/druid/granularity/DurationGranularity.java
浏览文件 @
73623467
...
...
@@ -70,10 +70,14 @@ public class DurationGranularity extends BaseQueryGranularity
}
@Override
public
long
truncate
(
long
t
)
public
long
truncate
(
final
long
t
)
{
final
long
duration
=
getDurationMillis
();
return
t
-
t
%
duration
+
origin
;
long
offset
=
t
%
duration
-
origin
%
duration
;
if
(
offset
<
0
)
{
offset
+=
duration
;
}
return
t
-
offset
;
}
@Override
...
...
processing/src/main/java/io/druid/granularity/PeriodGranularity.java
浏览文件 @
73623467
...
...
@@ -301,14 +301,17 @@ public class PeriodGranularity extends BaseQueryGranularity
return
current
;
}
private
long
truncateMillisPeriod
(
long
t
)
private
long
truncateMillisPeriod
(
final
long
t
)
{
// toStandardDuration assumes days are always 24h, and hours are always 60 minutes,
// which may not always be the case, e.g if there are daylight saving changes.
if
(
chronology
.
days
().
isPrecise
()
&&
chronology
.
hours
().
isPrecise
())
{
if
(
chronology
.
days
().
isPrecise
()
&&
chronology
.
hours
().
isPrecise
())
{
final
long
millis
=
period
.
toStandardDuration
().
getMillis
();
t
-=
t
%
millis
+
origin
%
millis
;
return
t
;
long
offset
=
t
%
millis
-
origin
%
millis
;
if
(
offset
<
0
)
{
offset
+=
millis
;
}
return
t
-
offset
;
}
else
{
...
...
processing/src/test/java/io/druid/granularity/QueryGranularityTest.java
浏览文件 @
73623467
...
...
@@ -347,68 +347,128 @@ public class QueryGranularityTest
@Test
public
void
testCompoundPeriodTruncate
()
throws
Exception
{
final
DateTime
origin
=
new
DateTime
(
"2012-01-02T05:00:00.000-08:00"
);
QueryGranularity
periodOrigin
=
new
PeriodGranularity
(
new
Period
(
"P1M2D"
),
origin
,
DateTimeZone
.
forID
(
"America/Los_Angeles"
));
assertSame
(
Lists
.
newArrayList
(
new
DateTime
(
"2011-11-30T05:00:00.000-08:00"
),
new
DateTime
(
"2012-01-02T05:00:00.000-08:00"
),
new
DateTime
(
"2012-02-04T05:00:00.000-08:00"
),
new
DateTime
(
"2012-02-04T05:00:00.000-08:00"
)
),
Lists
.
newArrayList
(
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-01T05:00:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-02T07:00:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-03-01T07:20:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-02-04T05:00:00.000-08:00"
).
getMillis
())
)
);
QueryGranularity
periodNoOrigin
=
new
PeriodGranularity
(
new
Period
(
"P1M2D"
),
null
,
DateTimeZone
.
forID
(
"America/Los_Angeles"
));
assertSame
(
Lists
.
newArrayList
(
new
DateTime
(
"1970-01-01T00:00:00.000-08:00"
),
new
DateTime
(
"2011-12-12T00:00:00.000-08:00"
),
new
DateTime
(
"2012-01-14T00:00:00.000-08:00"
),
new
DateTime
(
"2012-02-16T00:00:00.000-08:00"
)
),
Lists
.
newArrayList
(
periodNoOrigin
.
truncate
(
new
DateTime
(
"1970-01-01T05:02:04.123-08:00"
).
getMillis
()),
periodNoOrigin
.
truncate
(
new
DateTime
(
"2012-01-01T05:02:04.123-08:00"
).
getMillis
()),
periodNoOrigin
.
truncate
(
new
DateTime
(
"2012-01-15T07:01:04.123-08:00"
).
getMillis
()),
periodNoOrigin
.
truncate
(
new
DateTime
(
"2012-02-16T00:00:00.000-08:00"
).
getMillis
())
{
final
DateTime
origin
=
new
DateTime
(
"2012-01-02T05:00:00.000-08:00"
);
QueryGranularity
periodOrigin
=
new
PeriodGranularity
(
new
Period
(
"P1M2D"
),
origin
,
DateTimeZone
.
forID
(
"America/Los_Angeles"
)
);
assertSame
(
Lists
.
newArrayList
(
new
DateTime
(
"2011-11-30T05:00:00.000-08:00"
),
new
DateTime
(
"2012-01-02T05:00:00.000-08:00"
),
new
DateTime
(
"2012-02-04T05:00:00.000-08:00"
),
new
DateTime
(
"2012-02-04T05:00:00.000-08:00"
)
),
Lists
.
newArrayList
(
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-01T05:00:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-02T07:00:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-03-01T07:20:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-02-04T05:00:00.000-08:00"
).
getMillis
())
)
);
QueryGranularity
periodNoOrigin
=
new
PeriodGranularity
(
new
Period
(
"P1M2D"
),
null
,
DateTimeZone
.
forID
(
"America/Los_Angeles"
)
);
assertSame
(
Lists
.
newArrayList
(
new
DateTime
(
"1970-01-01T00:00:00.000-08:00"
),
new
DateTime
(
"2011-12-12T00:00:00.000-08:00"
),
new
DateTime
(
"2012-01-14T00:00:00.000-08:00"
),
new
DateTime
(
"2012-02-16T00:00:00.000-08:00"
)
),
Lists
.
newArrayList
(
periodNoOrigin
.
truncate
(
new
DateTime
(
"1970-01-01T05:02:04.123-08:00"
).
getMillis
()),
periodNoOrigin
.
truncate
(
new
DateTime
(
"2012-01-01T05:02:04.123-08:00"
).
getMillis
()),
periodNoOrigin
.
truncate
(
new
DateTime
(
"2012-01-15T07:01:04.123-08:00"
).
getMillis
()),
periodNoOrigin
.
truncate
(
new
DateTime
(
"2012-02-16T00:00:00.000-08:00"
).
getMillis
())
)
);
}
)
);
{
final
DateTime
origin
=
new
DateTime
(
"2012-01-02T05:00:00.000-08:00"
);
QueryGranularity
periodOrigin
=
new
PeriodGranularity
(
new
Period
(
"PT12H5M"
),
origin
,
DateTimeZone
.
forID
(
"America/Los_Angeles"
)
);
assertSame
(
Lists
.
newArrayList
(
new
DateTime
(
"2012-01-01T04:50:00.000-08:00"
),
new
DateTime
(
"2012-01-02T05:00:00.000-08:00"
),
new
DateTime
(
"2012-01-02T17:05:00.000-08:00"
),
new
DateTime
(
"2012-02-03T22:25:00.000-08:00"
)
),
Lists
.
newArrayList
(
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-01T05:00:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-02T07:00:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-03T00:20:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-02-03T22:25:00.000-08:00"
).
getMillis
())
)
);
}
}
@Test
public
void
testCompoundPeriodMillisTruncate
()
throws
Exception
{
final
DateTime
origin
=
new
DateTime
(
"2012-01-02T05:00:00.000-08:00"
);
QueryGranularity
periodOrigin
=
new
PeriodGranularity
(
new
Period
(
"PT12H5M"
),
origin
,
DateTimeZone
.
forID
(
"America/Los_Angeles"
));
assertSame
(
Lists
.
newArrayList
(
new
DateTime
(
"2012-01-01T04:50:00.000-08:00"
),
new
DateTime
(
"2012-01-02T05:00:00.000-08:00"
),
new
DateTime
(
"2012-01-02T17:05:00.000-08:00"
),
new
DateTime
(
"2012-02-03T22:25:00.000-08:00"
)
),
Lists
.
newArrayList
(
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-01T05:00:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-02T07:00:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-03T00:20:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-02-03T22:25:00.000-08:00"
).
getMillis
())
)
);
{
final
DateTime
origin
=
new
DateTime
(
"2012-01-02T05:00:00.000-08:00"
);
QueryGranularity
periodOrigin
=
new
PeriodGranularity
(
new
Period
(
"PT12H5M"
),
origin
,
DateTimeZone
.
UTC
);
assertSame
(
Lists
.
newArrayList
(
new
DateTime
(
"2012-01-01T04:50:00.000-08:00"
),
new
DateTime
(
"2012-01-02T05:00:00.000-08:00"
),
new
DateTime
(
"2012-01-02T17:05:00.000-08:00"
),
new
DateTime
(
"2012-02-03T22:25:00.000-08:00"
)
),
Lists
.
newArrayList
(
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-01T05:00:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-02T07:00:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-01-03T00:20:04.123-08:00"
).
getMillis
()),
periodOrigin
.
truncate
(
new
DateTime
(
"2012-02-03T22:25:00.000-08:00"
).
getMillis
())
)
);
}
}
@Test
public
void
testDurationTruncate
()
throws
Exception
{
{
final
DateTime
origin
=
new
DateTime
(
"2012-01-02T05:00:00.000-08:00"
);
QueryGranularity
gran
=
new
DurationGranularity
(
new
Period
(
"PT12H5M"
).
toStandardDuration
().
getMillis
(),
origin
);
assertSame
(
Lists
.
newArrayList
(
new
DateTime
(
"2012-01-01T04:50:00.000-08:00"
),
new
DateTime
(
"2012-01-02T05:00:00.000-08:00"
),
new
DateTime
(
"2012-01-02T17:05:00.000-08:00"
),
new
DateTime
(
"2012-02-03T22:25:00.000-08:00"
)
),
Lists
.
newArrayList
(
gran
.
truncate
(
new
DateTime
(
"2012-01-01T05:00:04.123-08:00"
).
getMillis
()),
gran
.
truncate
(
new
DateTime
(
"2012-01-02T07:00:04.123-08:00"
).
getMillis
()),
gran
.
truncate
(
new
DateTime
(
"2012-01-03T00:20:04.123-08:00"
).
getMillis
()),
gran
.
truncate
(
new
DateTime
(
"2012-02-03T22:25:00.000-08:00"
).
getMillis
())
)
);
}
}
@Test
public
void
testIterableAllSimple
()
throws
Exception
{
...
...
@@ -524,7 +584,7 @@ public class QueryGranularityTest
while
(
actualIter
.
hasNext
()
&&
expectedIter
.
hasNext
())
{
long
a
=
actualIter
.
next
().
longValue
();
Assert
.
assertEquals
(
expectedIter
.
next
()
.
getMillis
(),
a
);
Assert
.
assertEquals
(
expectedIter
.
next
()
,
new
DateTime
(
a
)
);
}
Assert
.
assertFalse
(
"actualIter not exhausted!?"
,
actualIter
.
hasNext
());
Assert
.
assertFalse
(
"expectedIter not exhausted!?"
,
expectedIter
.
hasNext
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录