Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
17dd915e
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,发现更多精彩内容 >>
提交
17dd915e
编写于
3月 20, 2017
作者:
Z
Zhenghua Gao
提交者:
twalthr
3月 21, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-6124] [table] support max/min aggregations for string type
This closes #3579.
上级
86d32ac8
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
90 addition
and
27 deletion
+90
-27
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/aggfunctions/MaxAggFunction.scala
...e/flink/table/functions/aggfunctions/MaxAggFunction.scala
+8
-0
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/aggfunctions/MinAggFunction.scala
...e/flink/table/functions/aggfunctions/MinAggFunction.scala
+8
-0
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/aggregate/AggregateUtil.scala
.../apache/flink/table/runtime/aggregate/AggregateUtil.scala
+4
-0
flink-libraries/flink-table/src/test/scala/org/apache/flink/table/api/scala/batch/sql/AggregationsITCase.scala
.../flink/table/api/scala/batch/sql/AggregationsITCase.scala
+4
-27
flink-libraries/flink-table/src/test/scala/org/apache/flink/table/functions/aggfunctions/MaxAggFunctionTest.scala
...ink/table/functions/aggfunctions/MaxAggFunctionTest.scala
+33
-0
flink-libraries/flink-table/src/test/scala/org/apache/flink/table/functions/aggfunctions/MinAggFunctionTest.scala
...ink/table/functions/aggfunctions/MinAggFunctionTest.scala
+33
-0
未找到文件。
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/aggfunctions/MaxAggFunction.scala
浏览文件 @
17dd915e
...
...
@@ -155,3 +155,11 @@ class DecimalMaxAggFunction extends MaxAggFunction[BigDecimal] {
override
def
getInitValue
=
BigDecimal
.
ZERO
override
def
getValueTypeInfo
=
BasicTypeInfo
.
BIG_DEC_TYPE_INFO
}
/**
* Built-in String Max aggregate function
*/
class
StringMaxAggFunction
extends
MaxAggFunction
[
String
]
{
override
def
getInitValue
=
""
.
toString
override
def
getValueTypeInfo
=
BasicTypeInfo
.
STRING_TYPE_INFO
}
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/functions/aggfunctions/MinAggFunction.scala
浏览文件 @
17dd915e
...
...
@@ -155,3 +155,11 @@ class DecimalMinAggFunction extends MinAggFunction[BigDecimal] {
override
def
getInitValue
:
BigDecimal
=
BigDecimal
.
ZERO
override
def
getValueTypeInfo
=
BasicTypeInfo
.
BIG_DEC_TYPE_INFO
}
/**
* Built-in String Min aggregate function
*/
class
StringMinAggFunction
extends
MinAggFunction
[
String
]
{
override
def
getInitValue
=
""
.
toString
override
def
getValueTypeInfo
=
BasicTypeInfo
.
STRING_TYPE_INFO
}
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/runtime/aggregate/AggregateUtil.scala
浏览文件 @
17dd915e
...
...
@@ -916,6 +916,8 @@ object AggregateUtil {
new
DecimalMinAggFunction
case
BOOLEAN
=>
new
BooleanMinAggFunction
case
VARCHAR
|
CHAR
=>
new
StringMinAggFunction
case
sqlType
:
SqlTypeName
=>
throw
new
TableException
(
"Min aggregate does no support type:"
+
sqlType
)
}
...
...
@@ -961,6 +963,8 @@ object AggregateUtil {
new
DecimalMaxAggFunction
case
BOOLEAN
=>
new
BooleanMaxAggFunction
case
VARCHAR
|
CHAR
=>
new
StringMaxAggFunction
case
sqlType
:
SqlTypeName
=>
throw
new
TableException
(
"Max aggregate does no support type:"
+
sqlType
)
}
...
...
flink-libraries/flink-table/src/test/scala/org/apache/flink/table/api/scala/batch/sql/AggregationsITCase.scala
浏览文件 @
17dd915e
...
...
@@ -92,36 +92,13 @@ class AggregationsITCase(
}
@Test
def
test
Working
AggregationDataTypes
()
:
Unit
=
{
def
testAggregationDataTypes
()
:
Unit
=
{
val
env
=
ExecutionEnvironment
.
getExecutionEnvironment
val
tEnv
=
TableEnvironment
.
getTableEnvironment
(
env
,
config
)
val
sqlQuery
=
"SELECT avg(_1), avg(_2), avg(_3), avg(_4), avg(_5), avg(_6), count(_7), "
+
" sum(CAST(_6 AS DECIMAL))"
+
"FROM MyTable"
val
ds
=
env
.
fromElements
(
(
1
:
Byte
,
1
:
Short
,
1
,
1L
,
1.0f
,
1.0d
,
"Hello"
),
(
2
:
Byte
,
2
:
Short
,
2
,
2L
,
2.0f
,
2.0d
,
"Ciao"
))
tEnv
.
registerDataSet
(
"MyTable"
,
ds
)
val
result
=
tEnv
.
sql
(
sqlQuery
)
val
expected
=
"1,1,1,1,1.5,1.5,2,3.0"
val
results
=
result
.
toDataSet
[
Row
].
collect
()
TestBaseUtils
.
compareResultAsText
(
results
.
asJava
,
expected
)
}
@Test
def
testTableWorkingAggregationDataTypes
()
:
Unit
=
{
val
env
=
ExecutionEnvironment
.
getExecutionEnvironment
val
tEnv
=
TableEnvironment
.
getTableEnvironment
(
env
,
config
)
val
sqlQuery
=
"SELECT avg(a), avg(b), avg(c), avg(d), avg(e), avg(f), count(g)"
+
"FROM MyTable"
val
sqlQuery
=
"SELECT avg(a), avg(b), avg(c), avg(d), avg(e), avg(f), count(g), "
+
"min(g), min('Ciao'), max(g), max('Ciao'), sum(CAST(f AS DECIMAL)) FROM MyTable"
val
ds
=
env
.
fromElements
(
(
1
:
Byte
,
1
:
Short
,
1
,
1L
,
1.0f
,
1.0d
,
"Hello"
),
...
...
@@ -130,7 +107,7 @@ class AggregationsITCase(
val
result
=
tEnv
.
sql
(
sqlQuery
)
val
expected
=
"1,1,1,1,1.5,1.5,2"
val
expected
=
"1,1,1,1,1.5,1.5,2
,Ciao,Ciao,Hello,Ciao,3.0
"
val
results
=
result
.
toDataSet
[
Row
].
collect
()
TestBaseUtils
.
compareResultAsText
(
results
.
asJava
,
expected
)
}
...
...
flink-libraries/flink-table/src/test/scala/org/apache/flink/table/functions/aggfunctions/MaxAggFunctionTest.scala
浏览文件 @
17dd915e
...
...
@@ -192,3 +192,36 @@ class DecimalMaxAggFunctionTest extends AggFunctionTestBase[BigDecimal] {
override
def
supportRetraction
:
Boolean
=
false
}
class
StringMaxAggFunctionTest
extends
AggFunctionTestBase
[
String
]
{
override
def
inputValueSets
:
Seq
[
Seq
[
_
]]
=
Seq
(
Seq
(
new
String
(
"a"
),
new
String
(
"b"
),
new
String
(
"c"
),
null
.
asInstanceOf
[
String
],
new
String
(
"d"
)
),
Seq
(
null
.
asInstanceOf
[
String
],
null
.
asInstanceOf
[
String
],
null
.
asInstanceOf
[
String
]
),
Seq
(
new
String
(
"1House"
),
new
String
(
"Household"
),
new
String
(
"house"
),
new
String
(
"household"
)
)
)
override
def
expectedResults
:
Seq
[
String
]
=
Seq
(
new
String
(
"d"
),
null
.
asInstanceOf
[
String
],
new
String
(
"household"
)
)
override
def
aggregator
:
AggregateFunction
[
String
]
=
new
StringMaxAggFunction
()
override
def
supportRetraction
:
Boolean
=
false
}
flink-libraries/flink-table/src/test/scala/org/apache/flink/table/functions/aggfunctions/MinAggFunctionTest.scala
浏览文件 @
17dd915e
...
...
@@ -192,3 +192,36 @@ class DecimalMinAggFunctionTest extends AggFunctionTestBase[BigDecimal] {
override
def
supportRetraction
:
Boolean
=
false
}
class
StringMinAggFunctionTest
extends
AggFunctionTestBase
[
String
]
{
override
def
inputValueSets
:
Seq
[
Seq
[
_
]]
=
Seq
(
Seq
(
new
String
(
"a"
),
new
String
(
"b"
),
new
String
(
"c"
),
null
.
asInstanceOf
[
String
],
new
String
(
"d"
)
),
Seq
(
null
.
asInstanceOf
[
String
],
null
.
asInstanceOf
[
String
],
null
.
asInstanceOf
[
String
]
),
Seq
(
new
String
(
"1House"
),
new
String
(
"Household"
),
new
String
(
"house"
),
new
String
(
"household"
)
)
)
override
def
expectedResults
:
Seq
[
String
]
=
Seq
(
new
String
(
"a"
),
null
.
asInstanceOf
[
String
],
new
String
(
"1House"
)
)
override
def
aggregator
:
AggregateFunction
[
String
]
=
new
StringMinAggFunction
()
override
def
supportRetraction
:
Boolean
=
false
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录