Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Questdb
提交
810d5ffd
Q
Questdb
项目概览
jobily
/
Questdb
12 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
Questdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
810d5ffd
编写于
5月 28, 2020
作者:
J
jaugsburger
提交者:
GitHub
5月 28, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(griffin) - avg() ksum() nsum() sum() handling of infinity #313 (#338)
上级
982c77dd
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
57 addition
and
8 deletion
+57
-8
core/src/main/java/io/questdb/griffin/engine/functions/groupby/AvgDoubleGroupByFunction.java
...in/engine/functions/groupby/AvgDoubleGroupByFunction.java
+3
-2
core/src/main/java/io/questdb/griffin/engine/functions/groupby/KSumDoubleGroupByFunction.java
...n/engine/functions/groupby/KSumDoubleGroupByFunction.java
+3
-2
core/src/main/java/io/questdb/griffin/engine/functions/groupby/NSumDoubleGroupByFunction.java
...n/engine/functions/groupby/NSumDoubleGroupByFunction.java
+3
-2
core/src/main/java/io/questdb/griffin/engine/functions/groupby/SumDoubleGroupByFunction.java
...in/engine/functions/groupby/SumDoubleGroupByFunction.java
+3
-2
core/src/main/java/io/questdb/std/Numbers.java
core/src/main/java/io/questdb/std/Numbers.java
+4
-0
core/src/test/java/io/questdb/griffin/engine/functions/groupby/AvgDoubleGroupByFunctionFactoryTest.java
...unctions/groupby/AvgDoubleGroupByFunctionFactoryTest.java
+41
-0
未找到文件。
core/src/main/java/io/questdb/griffin/engine/functions/groupby/AvgDoubleGroupByFunction.java
浏览文件 @
810d5ffd
...
...
@@ -32,6 +32,7 @@ import io.questdb.cairo.sql.Record;
import
io.questdb.griffin.engine.functions.DoubleFunction
;
import
io.questdb.griffin.engine.functions.GroupByFunction
;
import
io.questdb.griffin.engine.functions.UnaryFunction
;
import
io.questdb.std.Numbers
;
import
org.jetbrains.annotations.NotNull
;
public
class
AvgDoubleGroupByFunction
extends
DoubleFunction
implements
GroupByFunction
,
UnaryFunction
{
...
...
@@ -46,7 +47,7 @@ public class AvgDoubleGroupByFunction extends DoubleFunction implements GroupByF
@Override
public
void
computeFirst
(
MapValue
mapValue
,
Record
record
)
{
final
double
d
=
arg
.
getDouble
(
record
);
if
(
d
==
d
)
{
if
(
Numbers
.
isFinite
(
d
)
)
{
mapValue
.
putDouble
(
valueIndex
,
d
);
mapValue
.
putLong
(
valueIndex
+
1
,
1L
);
}
else
{
...
...
@@ -58,7 +59,7 @@ public class AvgDoubleGroupByFunction extends DoubleFunction implements GroupByF
@Override
public
void
computeNext
(
MapValue
mapValue
,
Record
record
)
{
final
double
d
=
arg
.
getDouble
(
record
);
if
(
d
==
d
)
{
if
(
Numbers
.
isFinite
(
d
)
)
{
mapValue
.
addDouble
(
valueIndex
,
d
);
mapValue
.
addLong
(
valueIndex
+
1
,
1L
);
}
...
...
core/src/main/java/io/questdb/griffin/engine/functions/groupby/KSumDoubleGroupByFunction.java
浏览文件 @
810d5ffd
...
...
@@ -32,6 +32,7 @@ import io.questdb.cairo.sql.Record;
import
io.questdb.griffin.engine.functions.DoubleFunction
;
import
io.questdb.griffin.engine.functions.GroupByFunction
;
import
io.questdb.griffin.engine.functions.UnaryFunction
;
import
io.questdb.std.Numbers
;
import
org.jetbrains.annotations.NotNull
;
public
class
KSumDoubleGroupByFunction
extends
DoubleFunction
implements
GroupByFunction
,
UnaryFunction
{
...
...
@@ -46,7 +47,7 @@ public class KSumDoubleGroupByFunction extends DoubleFunction implements GroupBy
@Override
public
void
computeFirst
(
MapValue
mapValue
,
Record
record
)
{
final
double
value
=
arg
.
getDouble
(
record
);
if
(
value
==
value
)
{
if
(
Numbers
.
isFinite
(
value
)
)
{
mapValue
.
putDouble
(
valueIndex
,
value
);
mapValue
.
putDouble
(
valueIndex
+
1
,
value
-
value
);
mapValue
.
putLong
(
valueIndex
+
2
,
1
);
...
...
@@ -60,7 +61,7 @@ public class KSumDoubleGroupByFunction extends DoubleFunction implements GroupBy
@Override
public
void
computeNext
(
MapValue
mapValue
,
Record
record
)
{
final
double
value
=
arg
.
getDouble
(
record
);
if
(
value
==
value
)
{
if
(
Numbers
.
isFinite
(
value
)
)
{
double
sum
=
mapValue
.
getDouble
(
valueIndex
);
double
c
=
mapValue
.
getDouble
(
valueIndex
+
1
);
double
y
=
value
-
c
;
...
...
core/src/main/java/io/questdb/griffin/engine/functions/groupby/NSumDoubleGroupByFunction.java
浏览文件 @
810d5ffd
...
...
@@ -32,6 +32,7 @@ import io.questdb.cairo.sql.Record;
import
io.questdb.griffin.engine.functions.DoubleFunction
;
import
io.questdb.griffin.engine.functions.GroupByFunction
;
import
io.questdb.griffin.engine.functions.UnaryFunction
;
import
io.questdb.std.Numbers
;
import
org.jetbrains.annotations.NotNull
;
public
class
NSumDoubleGroupByFunction
extends
DoubleFunction
implements
GroupByFunction
,
UnaryFunction
{
...
...
@@ -46,7 +47,7 @@ public class NSumDoubleGroupByFunction extends DoubleFunction implements GroupBy
@Override
public
void
computeFirst
(
MapValue
mapValue
,
Record
record
)
{
final
double
value
=
arg
.
getDouble
(
record
);
if
(
value
==
value
)
{
if
(
Numbers
.
isFinite
(
value
)
)
{
sum
(
mapValue
,
value
,
0
,
0
);
mapValue
.
putLong
(
valueIndex
+
2
,
1
);
}
else
{
...
...
@@ -59,7 +60,7 @@ public class NSumDoubleGroupByFunction extends DoubleFunction implements GroupBy
@Override
public
void
computeNext
(
MapValue
mapValue
,
Record
record
)
{
final
double
value
=
arg
.
getDouble
(
record
);
if
(
value
==
value
)
{
if
(
Numbers
.
isFinite
(
value
)
)
{
sum
(
mapValue
,
value
,
mapValue
.
getDouble
(
valueIndex
),
mapValue
.
getDouble
(
valueIndex
+
1
));
mapValue
.
addLong
(
valueIndex
+
2
,
1
);
}
...
...
core/src/main/java/io/questdb/griffin/engine/functions/groupby/SumDoubleGroupByFunction.java
浏览文件 @
810d5ffd
...
...
@@ -32,6 +32,7 @@ import io.questdb.cairo.sql.Record;
import
io.questdb.griffin.engine.functions.DoubleFunction
;
import
io.questdb.griffin.engine.functions.GroupByFunction
;
import
io.questdb.griffin.engine.functions.UnaryFunction
;
import
io.questdb.std.Numbers
;
import
org.jetbrains.annotations.NotNull
;
public
class
SumDoubleGroupByFunction
extends
DoubleFunction
implements
GroupByFunction
,
UnaryFunction
{
...
...
@@ -46,7 +47,7 @@ public class SumDoubleGroupByFunction extends DoubleFunction implements GroupByF
@Override
public
void
computeFirst
(
MapValue
mapValue
,
Record
record
)
{
final
double
value
=
arg
.
getDouble
(
record
);
if
(
value
==
value
)
{
if
(
Numbers
.
isFinite
(
value
)
)
{
mapValue
.
putDouble
(
valueIndex
,
value
);
mapValue
.
putLong
(
valueIndex
+
1
,
1
);
}
else
{
...
...
@@ -58,7 +59,7 @@ public class SumDoubleGroupByFunction extends DoubleFunction implements GroupByF
@Override
public
void
computeNext
(
MapValue
mapValue
,
Record
record
)
{
final
double
value
=
arg
.
getDouble
(
record
);
if
(
value
==
value
)
{
if
(
Numbers
.
isFinite
(
value
)
)
{
mapValue
.
addDouble
(
valueIndex
,
value
);
mapValue
.
addLong
(
valueIndex
+
1
,
1
);
}
...
...
core/src/main/java/io/questdb/std/Numbers.java
浏览文件 @
810d5ffd
...
...
@@ -1073,6 +1073,10 @@ public final class Numbers {
return
Double
.
longBitsToDouble
(
Double
.
doubleToRawLongBits
(
roundUp00PosScale
(
absValue
,
scale
))
|
signMask
);
}
public
static
boolean
isFinite
(
double
d
)
{
return
((
Double
.
doubleToRawLongBits
(
d
)
&
EXP_BIT_MASK
)
!=
EXP_BIT_MASK
);
}
private
static
void
appendLongHex4
(
CharSink
sink
,
long
value
)
{
appendLongHexPad
(
sink
,
hexDigits
[(
int
)
((
value
)
&
0xf
)]);
}
...
...
core/src/test/java/io/questdb/griffin/engine/functions/groupby/AvgDoubleGroupByFunctionFactoryTest.java
浏览文件 @
810d5ffd
...
...
@@ -28,11 +28,19 @@ import io.questdb.cairo.sql.RecordCursor;
import
io.questdb.cairo.sql.RecordCursorFactory
;
import
io.questdb.griffin.AbstractGriffinTest
;
import
io.questdb.griffin.CompiledQuery
;
import
io.questdb.griffin.engine.functions.rnd.SharedRandom
;
import
io.questdb.std.Rnd
;
import
io.questdb.test.tools.TestUtils
;
import
org.junit.Before
;
import
org.junit.Test
;
public
class
AvgDoubleGroupByFunctionFactoryTest
extends
AbstractGriffinTest
{
@Before
public
void
setUp3
()
{
SharedRandom
.
RANDOM
.
set
(
new
Rnd
());
}
@Test
public
void
testAll
()
throws
Exception
{
assertMemoryLeak
(()
->
{
...
...
@@ -51,4 +59,37 @@ public class AvgDoubleGroupByFunctionFactoryTest extends AbstractGriffinTest {
});
}
@Test
public
void
testAvgWithInfinity
()
throws
Exception
{
assertMemoryLeak
(()
->
{
compiler
.
compile
(
"create table test2 as(select case when rnd_double() > 0.6 then 1.0 else 0.0 end val from long_sequence(100));"
,
sqlExecutionContext
);
CompiledQuery
cq
=
compiler
.
compile
(
"select avg(1/val) from test2"
,
sqlExecutionContext
);
try
(
RecordCursorFactory
factory
=
cq
.
getRecordCursorFactory
())
{
sink
.
clear
();
try
(
RecordCursor
cursor
=
factory
.
getCursor
(
sqlExecutionContext
))
{
printer
.
print
(
cursor
,
factory
.
getMetadata
(),
true
);
}
}
TestUtils
.
assertEquals
(
"avg\n1.0\n"
,
sink
);
});
}
@Test
public
void
testAllWithInfinity
()
throws
Exception
{
assertMemoryLeak
(()
->
{
compiler
.
compile
(
"create table test2 as(select case when rnd_double() > 0.6 then 1.0 else 0.0 end val from long_sequence(100));"
,
sqlExecutionContext
);
CompiledQuery
cq
=
compiler
.
compile
(
"select sum(1/val) , avg(1/val), max(1/val), min(1/val), ksum(1/val), nsum(1/val) from test2"
,
sqlExecutionContext
);
try
(
RecordCursorFactory
factory
=
cq
.
getRecordCursorFactory
())
{
sink
.
clear
();
try
(
RecordCursor
cursor
=
factory
.
getCursor
(
sqlExecutionContext
))
{
printer
.
print
(
cursor
,
factory
.
getMetadata
(),
true
);
}
}
TestUtils
.
assertEquals
(
"sum\tavg\tmax\tmin\tksum\tnsum\n"
+
"44.0\t1.0\tInfinity\t1.0\t44.0\t44.0\n"
,
sink
);
});
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录