Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
5784f395
F
flink
项目概览
doujutun3207
/
flink
与 Fork 源项目一致
从无法访问的项目Fork
通知
24
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flink
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5784f395
编写于
5月 22, 2016
作者:
F
Fabian Hueske
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-3936] [tableAPI] Add MIN/MAX aggregation for Boolean.
This closes #2035
上级
ec38a212
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
86 addition
and
6 deletion
+86
-6
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/runtime/aggregate/AggregateUtil.scala
...che/flink/api/table/runtime/aggregate/AggregateUtil.scala
+4
-0
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/runtime/aggregate/MaxAggregate.scala
...ache/flink/api/table/runtime/aggregate/MaxAggregate.scala
+12
-3
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/runtime/aggregate/MinAggregate.scala
...ache/flink/api/table/runtime/aggregate/MinAggregate.scala
+12
-3
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/runtime/aggregate/MaxAggregateTest.scala
.../flink/api/table/runtime/aggregate/MaxAggregateTest.scala
+29
-0
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/runtime/aggregate/MinAggregateTest.scala
.../flink/api/table/runtime/aggregate/MinAggregateTest.scala
+29
-0
未找到文件。
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/runtime/aggregate/AggregateUtil.scala
浏览文件 @
5784f395
...
...
@@ -192,6 +192,8 @@ object AggregateUtil {
new
FloatMinAggregate
case
DOUBLE
=>
new
DoubleMinAggregate
case
BOOLEAN
=>
new
BooleanMinAggregate
case
sqlType
:
SqlTypeName
=>
throw
new
TableException
(
"Min aggregate does no support type:"
+
sqlType
)
}
...
...
@@ -209,6 +211,8 @@ object AggregateUtil {
new
FloatMaxAggregate
case
DOUBLE
=>
new
DoubleMaxAggregate
case
BOOLEAN
=>
new
BooleanMaxAggregate
case
sqlType
:
SqlTypeName
=>
throw
new
TableException
(
"Max aggregate does no support type:"
+
sqlType
)
}
...
...
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/runtime/aggregate/MaxAggregate.scala
浏览文件 @
5784f395
...
...
@@ -20,9 +20,8 @@ package org.apache.flink.api.table.runtime.aggregate
import
org.apache.flink.api.common.typeinfo.BasicTypeInfo
import
org.apache.flink.api.table.Row
abstract
class
MaxAggregate
[
T
:
Numeric
]
extends
Aggregate
[
T
]
{
abstract
class
MaxAggregate
[
T
](
implicit
ord
:
Ordering
[
T
])
extends
Aggregate
[
T
]
{
private
val
numeric
=
implicitly
[
Numeric
[
T
]]
protected
var
maxIndex
=
-
1
/**
...
...
@@ -49,7 +48,8 @@ abstract class MaxAggregate[T: Numeric] extends Aggregate[T] {
override
def
merge
(
intermediate
:
Row
,
buffer
:
Row
)
:
Unit
=
{
val
partialValue
=
intermediate
.
productElement
(
maxIndex
).
asInstanceOf
[
T
]
val
bufferValue
=
buffer
.
productElement
(
maxIndex
).
asInstanceOf
[
T
]
buffer
.
setField
(
maxIndex
,
numeric
.
max
(
partialValue
,
bufferValue
))
val
max
:
T
=
if
(
ord
.
compare
(
partialValue
,
bufferValue
)
>
0
)
partialValue
else
bufferValue
buffer
.
setField
(
maxIndex
,
max
)
}
/**
...
...
@@ -122,3 +122,12 @@ class DoubleMaxAggregate extends MaxAggregate[Double] {
intermediate
.
setField
(
maxIndex
,
Double
.
MinValue
)
}
}
class
BooleanMaxAggregate
extends
MaxAggregate
[
Boolean
]
{
override
def
intermediateDataType
=
Array
(
BasicTypeInfo
.
BOOLEAN_TYPE_INFO
)
override
def
initiate
(
intermediate
:
Row
)
:
Unit
=
{
intermediate
.
setField
(
maxIndex
,
false
)
}
}
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/runtime/aggregate/MinAggregate.scala
浏览文件 @
5784f395
...
...
@@ -20,9 +20,8 @@ package org.apache.flink.api.table.runtime.aggregate
import
org.apache.flink.api.common.typeinfo.BasicTypeInfo
import
org.apache.flink.api.table.Row
abstract
class
MinAggregate
[
T
:
Numeric
]
extends
Aggregate
[
T
]{
abstract
class
MinAggregate
[
T
](
implicit
ord
:
Ordering
[
T
])
extends
Aggregate
[
T
]{
private
val
numeric
=
implicitly
[
Numeric
[
T
]]
protected
var
minIndex
:
Int
=
_
/**
...
...
@@ -49,7 +48,8 @@ abstract class MinAggregate[T: Numeric] extends Aggregate[T]{
override
def
merge
(
partial
:
Row
,
buffer
:
Row
)
:
Unit
=
{
val
partialValue
=
partial
.
productElement
(
minIndex
).
asInstanceOf
[
T
]
val
bufferValue
=
buffer
.
productElement
(
minIndex
).
asInstanceOf
[
T
]
buffer
.
setField
(
minIndex
,
numeric
.
min
(
partialValue
,
bufferValue
))
val
min
:
T
=
if
(
ord
.
compare
(
partialValue
,
bufferValue
)
<
0
)
partialValue
else
bufferValue
buffer
.
setField
(
minIndex
,
min
)
}
/**
...
...
@@ -122,3 +122,12 @@ class DoubleMinAggregate extends MinAggregate[Double] {
intermediate
.
setField
(
minIndex
,
Double
.
MaxValue
)
}
}
class
BooleanMinAggregate
extends
MinAggregate
[
Boolean
]
{
override
def
intermediateDataType
=
Array
(
BasicTypeInfo
.
BOOLEAN_TYPE_INFO
)
override
def
initiate
(
intermediate
:
Row
)
:
Unit
=
{
intermediate
.
setField
(
minIndex
,
true
)
}
}
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/runtime/aggregate/MaxAggregateTest.scala
浏览文件 @
5784f395
...
...
@@ -91,3 +91,32 @@ class DoubleMaxAggregateTest extends MaxAggregateTestBase[Double] {
override
def
aggregator
:
Aggregate
[
Double
]
=
new
DoubleMaxAggregate
()
}
class
BooleanMaxAggregateTest
extends
AggregateTestBase
[
Boolean
]
{
override
def
inputValueSets
:
Seq
[
Seq
[
Boolean
]]
=
Seq
(
Seq
(
false
,
false
,
false
),
Seq
(
true
,
true
,
true
),
Seq
(
true
,
false
,
null
.
asInstanceOf
[
Boolean
],
true
,
false
,
true
,
null
.
asInstanceOf
[
Boolean
]
)
)
override
def
expectedResults
:
Seq
[
Boolean
]
=
Seq
(
false
,
true
,
true
)
override
def
aggregator
:
Aggregate
[
Boolean
]
=
new
BooleanMaxAggregate
()
}
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/table/runtime/aggregate/MinAggregateTest.scala
浏览文件 @
5784f395
...
...
@@ -91,3 +91,32 @@ class DoubleMinAggregateTest extends MinAggregateTestBase[Double] {
override
def
aggregator
:
Aggregate
[
Double
]
=
new
DoubleMinAggregate
()
}
class
BooleanMinAggregateTest
extends
AggregateTestBase
[
Boolean
]
{
override
def
inputValueSets
:
Seq
[
Seq
[
Boolean
]]
=
Seq
(
Seq
(
false
,
false
,
false
),
Seq
(
true
,
true
,
true
),
Seq
(
true
,
false
,
null
.
asInstanceOf
[
Boolean
],
true
,
false
,
true
,
null
.
asInstanceOf
[
Boolean
]
)
)
override
def
expectedResults
:
Seq
[
Boolean
]
=
Seq
(
false
,
true
,
false
)
override
def
aggregator
:
Aggregate
[
Boolean
]
=
new
BooleanMinAggregate
()
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录