Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
2b82578a
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,发现更多精彩内容 >>
提交
2b82578a
编写于
9月 26, 2017
作者:
T
twalthr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-7596] [table] Restrict equality and improve tests
上级
62ebda3f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
30 deletion
+31
-30
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/calcite/FlinkTypeFactory.scala
...ala/org/apache/flink/table/calcite/FlinkTypeFactory.scala
+20
-25
flink-libraries/flink-table/src/test/scala/org/apache/flink/table/runtime/stream/table/SetOperatorsITCase.scala
...flink/table/runtime/stream/table/SetOperatorsITCase.scala
+11
-5
未找到文件。
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/calcite/FlinkTypeFactory.scala
浏览文件 @
2b82578a
...
...
@@ -19,7 +19,6 @@
package
org.apache.flink.table.calcite
import
java.util
import
java.util.List
import
org.apache.calcite.avatica.util.TimeUnit
import
org.apache.calcite.jdbc.JavaTypeFactoryImpl
...
...
@@ -248,39 +247,35 @@ class FlinkTypeFactory(typeSystem: RelDataTypeSystem) extends JavaTypeFactoryImp
canonize
(
newType
)
}
private
def
resolveAnySqlType
(
types
:
java.util.List
[
RelDataType
])
:
RelDataType
=
{
val
hasAny
=
types
.
asScala
.
map
(
_
.
getSqlTypeName
).
exists
(
_
==
SqlTypeName
.
ANY
)
val
nullable
=
types
.
asScala
.
exists
(
sqlType
=>
sqlType
.
isNullable
||
sqlType
.
getSqlTypeName
==
SqlTypeName
.
NULL
)
if
(
hasAny
)
{
if
(
types
.
get
(
0
).
isInstanceOf
[
GenericRelDataType
]
&&
types
.
get
(
1
).
isInstanceOf
[
GenericRelDataType
])
{
createTypeWithNullability
(
types
.
get
(
0
),
nullable
)
}
else
{
throw
new
RuntimeException
(
"only GenericRelDataType of ANY is supported"
)
}
}
else
{
null
}
}
override
def
leastRestrictive
(
types
:
util.List
[
RelDataType
])
:
RelDataType
=
{
assert
(
types
!=
null
)
assert
(
types
.
size
>=
1
)
val
type0
=
types
.
get
(
0
)
if
(
type0
.
getSqlTypeName
!=
null
)
{
val
resultType
=
resolveAny
SqlType
(
types
)
val
resultType
=
resolveAny
(
types
)
if
(
resultType
!=
null
)
{
resultType
return
resultType
}
}
super
.
leastRestrictive
(
types
)
}
private
def
resolveAny
(
types
:
util.List
[
RelDataType
])
:
RelDataType
=
{
val
allTypes
=
types
.
asScala
val
hasAny
=
allTypes
.
exists
(
_
.
getSqlTypeName
==
SqlTypeName
.
ANY
)
if
(
hasAny
)
{
val
head
=
allTypes
.
head
// only allow ANY with exactly the same GenericRelDataType for all types
if
(
allTypes
.
forall
(
_
==
head
))
{
val
nullable
=
allTypes
.
exists
(
sqlType
=>
sqlType
.
isNullable
||
sqlType
.
getSqlTypeName
==
SqlTypeName
.
NULL
)
createTypeWithNullability
(
head
,
nullable
)
}
else
{
super
.
leastRestrictive
(
types
)
throw
TableException
(
"Generic ANY types must have a common type information."
)
}
}
else
{
super
.
leastRestrictive
(
types
)
null
}
}
}
object
FlinkTypeFactory
{
...
...
flink-libraries/flink-table/src/test/scala/org/apache/flink/table/runtime/stream/table/SetOperatorsITCase.scala
浏览文件 @
2b82578a
...
...
@@ -73,18 +73,24 @@ class SetOperatorsITCase extends StreamingMultipleProgramsTestBase {
@Test
def
testUnionWithAnyType
()
:
Unit
=
{
val
list
=
List
((
1
,
new
NODE
),
(
2
,
new
NODE
))
val
list2
=
List
((
3
,
new
NODE
),
(
4
,
new
NODE
))
val
env
=
StreamExecutionEnvironment
.
getExecutionEnvironment
val
tEnv
=
TableEnvironment
.
getTableEnvironment
(
env
)
val
s1
=
tEnv
.
fromDataStream
(
env
.
fromCollection
(
list
))
val
s2
=
tEnv
.
fromDataStream
(
env
.
fromCollection
(
list2
))
StreamITCase
.
testResults
=
mutable
.
MutableList
()
val
s1
=
env
.
fromElements
((
1
,
new
NonPojo
),
(
2
,
new
NonPojo
)).
toTable
(
tEnv
,
'a
,
'b
)
val
s2
=
env
.
fromElements
((
3
,
new
NonPojo
),
(
4
,
new
NonPojo
)).
toTable
(
tEnv
,
'a
,
'b
)
val
result
=
s1
.
unionAll
(
s2
).
toAppendStream
[
Row
]
result
.
addSink
(
new
StreamITCase
.
StringSink
[
Row
])
env
.
execute
()
val
expected
=
mutable
.
MutableList
(
"1,{}"
,
"2,{}"
,
"3,{}"
,
"4,{}"
)
assertEquals
(
expected
.
sorted
,
StreamITCase
.
testResults
.
sorted
)
}
class
N
ODE
{
class
N
onPojo
{
val
x
=
new
java
.
util
.
HashMap
[
String
,
String
]()
override
def
toString
:
String
=
x
.
toString
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录