Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
e789bb71
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,发现更多精彩内容 >>
未验证
提交
e789bb71
编写于
3月 31, 2020
作者:
J
Jingsong Lee
提交者:
GitHub
3月 31, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-16857][table-planner-blink] Support partition prune by getPartitions of source
This closes #11560
上级
ee1e83ce
变更
5
展开全部
隐藏空白更改
内联
并排
Showing
5 changed file
with
447 addition
and
128 deletion
+447
-128
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/HiveTableSource.java
...ava/org/apache/flink/connectors/hive/HiveTableSource.java
+1
-1
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/rules/logical/PushPartitionIntoTableSourceScanRule.scala
.../rules/logical/PushPartitionIntoTableSourceScanRule.scala
+42
-30
flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/planner/plan/rules/logical/PushPartitionIntoTableSourceScanRuleTest.xml
...ules/logical/PushPartitionIntoTableSourceScanRuleTest.xml
+370
-72
flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/plan/rules/logical/PushPartitionIntoTableSourceScanRuleTest.scala
...es/logical/PushPartitionIntoTableSourceScanRuleTest.scala
+14
-3
flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/utils/testTableSources.scala
...g/apache/flink/table/planner/utils/testTableSources.scala
+20
-22
未找到文件。
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/connectors/hive/HiveTableSource.java
浏览文件 @
e789bb71
...
...
@@ -234,7 +234,7 @@ public class HiveTableSource implements
@Override
public
List
<
Map
<
String
,
String
>>
getPartitions
()
{
throw
new
RuntimeException
(
"This method is not expected to be called. "
+
throw
new
UnsupportedOperationException
(
"Please use Catalog API to retrieve all partitions of a table"
);
}
...
...
flink-table/flink-table-planner-blink/src/main/scala/org/apache/flink/table/planner/plan/rules/logical/PushPartitionIntoTableSourceScanRule.scala
浏览文件 @
e789bb71
...
...
@@ -107,12 +107,20 @@ class PushPartitionIntoTableSourceScanRule extends RelOptRule(
inputFieldType
.
getFieldList
.
get
(
index
).
getType
}.
map
(
FlinkTypeFactory
.
toLogicalType
)
val
partitionsFromSource
=
try
{
Some
(
tableSource
.
getPartitions
)
}
catch
{
case
_:
UnsupportedOperationException
=>
None
}
def
getAllPartitions
:
util.List
[
util.Map
[
String
,
String
]]
=
{
catalogOption
match
{
case
Some
(
c
)
=>
c
.
listPartitions
(
tableIdentifier
.
toObjectPath
)
.
map
(
_
.
getPartitionSpec
).
toList
case
None
=>
tableSource
.
getPartitions
partitionsFromSource
match
{
case
Some
(
parts
)
=>
parts
case
None
=>
catalogOption
match
{
case
Some
(
catalog
)
=>
catalog
.
listPartitions
(
tableIdentifier
.
toObjectPath
).
map
(
_
.
getPartitionSpec
).
toList
case
None
=>
throw
new
TableException
(
s
"The $tableSource must be a catalog."
)
}
}
}
...
...
@@ -132,35 +140,39 @@ class PushPartitionIntoTableSourceScanRule extends RelOptRule(
)
}
val
remainingPartitions
:
util.List
[
util.Map
[
String
,
String
]]
=
catalogOption
match
{
case
Some
(
catalog
)
=>
val
converter
=
new
RexNodeToExpressionConverter
(
inputFields
,
context
.
getFunctionCatalog
,
context
.
getCatalogManager
,
TimeZone
.
getTimeZone
(
config
.
getLocalTimeZone
))
def
toExpressions
:
Option
[
Seq
[
Expression
]]
=
{
val
expressions
=
new
mutable
.
ArrayBuffer
[
Expression
]()
for
(
predicate
<-
partitionPredicates
)
{
predicate
.
accept
(
converter
)
match
{
case
Some
(
expr
)
=>
expressions
.
add
(
expr
)
case
None
=>
return
None
val
remainingPartitions
:
util.List
[
util.Map
[
String
,
String
]]
=
partitionsFromSource
match
{
case
Some
(
_
)
=>
internalPartitionPrune
()
case
None
=>
catalogOption
match
{
case
Some
(
catalog
)
=>
val
converter
=
new
RexNodeToExpressionConverter
(
inputFields
,
context
.
getFunctionCatalog
,
context
.
getCatalogManager
,
TimeZone
.
getTimeZone
(
config
.
getLocalTimeZone
))
def
toExpressions
:
Option
[
Seq
[
Expression
]]
=
{
val
expressions
=
new
mutable
.
ArrayBuffer
[
Expression
]()
for
(
predicate
<-
partitionPredicates
)
{
predicate
.
accept
(
converter
)
match
{
case
Some
(
expr
)
=>
expressions
.
add
(
expr
)
case
None
=>
return
None
}
}
Some
(
expressions
)
}
}
Some
(
expressions
)
}
toExpressions
match
{
case
Some
(
expressions
)
=>
try
{
catalog
.
listPartitionsByFilter
(
tableIdentifier
.
toObjectPath
,
expressions
)
.
map
(
_
.
getPartitionSpec
)
}
catch
{
case
_:
UnsupportedOperationException
=>
internalPartitionPrune
()
toExpressions
match
{
case
Some
(
expressions
)
=>
try
{
catalog
.
listPartitionsByFilter
(
tableIdentifier
.
toObjectPath
,
expressions
)
.
map
(
_
.
getPartitionSpec
)
}
catch
{
case
_:
UnsupportedOperationException
=>
internalPartitionPrune
()
}
case
None
=>
internalPartitionPrune
()
}
case
None
=>
internalPartitionPrune
()
}
case
None
=>
internalPartitionPrune
()
}
val
newTableSource
=
tableSource
.
applyPartitionPruning
(
remainingPartitions
)
...
...
flink-table/flink-table-planner-blink/src/test/resources/org/apache/flink/table/planner/plan/rules/logical/PushPartitionIntoTableSourceScanRuleTest.xml
浏览文件 @
e789bb71
此差异已折叠。
点击以展开。
flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/plan/rules/logical/PushPartitionIntoTableSourceScanRuleTest.scala
浏览文件 @
e789bb71
...
...
@@ -25,12 +25,16 @@ import org.apache.flink.table.planner.utils.{TableConfigUtils, TableTestBase, Te
import
org.apache.calcite.plan.hep.HepMatchOrder
import
org.apache.calcite.rel.rules.FilterProjectTransposeRule
import
org.apache.calcite.tools.RuleSets
import
org.junit.runner.RunWith
import
org.junit.runners.Parameterized
import
org.junit.
{
Before
,
Test
}
/**
* Test for [[PushPartitionIntoTableSourceScanRule]].
*/
class
PushPartitionIntoTableSourceScanRuleTest
extends
TableTestBase
{
@RunWith
(
classOf
[
Parameterized
])
class
PushPartitionIntoTableSourceScanRuleTest
(
sourceFetchPartitions
:
Boolean
)
extends
TableTestBase
{
private
val
util
=
batchTestUtil
()
@Before
...
...
@@ -63,9 +67,9 @@ class PushPartitionIntoTableSourceScanRuleTest extends TableTestBase {
.
build
()
TestPartitionableSourceFactory
.
registerTableSource
(
util
.
tableEnv
,
"MyTable"
,
tableSchema
=
tableSchema
,
isBounded
=
true
)
tableSchema
=
tableSchema
,
isBounded
=
true
,
sourceFetchPartitions
=
sourceFetchPartitions
)
TestPartitionableSourceFactory
.
registerTableSource
(
util
.
tableEnv
,
"VirtualTable"
,
tableSchema
=
tableSchema2
,
isBounded
=
true
)
tableSchema
=
tableSchema2
,
isBounded
=
true
,
sourceFetchPartitions
=
sourceFetchPartitions
)
}
@Test
...
...
@@ -161,3 +165,10 @@ class PushPartitionIntoTableSourceScanRuleTest extends TableTestBase {
}
}
object
PushPartitionIntoTableSourceScanRuleTest
{
@Parameterized
.
Parameters
(
name
=
"{0}"
)
def
parameters
()
:
java.util.Collection
[
Boolean
]
=
{
java
.
util
.
Arrays
.
asList
(
true
,
false
)
}
}
flink-table/flink-table-planner-blink/src/test/scala/org/apache/flink/table/planner/utils/testTableSources.scala
浏览文件 @
e789bb71
...
...
@@ -605,7 +605,7 @@ class TestFilterableTableSourceFactory extends StreamTableSourceFactory[Row] {
class
TestPartitionableTableSource
(
override
val
isBounded
:
Boolean
,
remainingPartitions
:
JList
[
JMap
[
String
,
String
]],
isCatalogTable
:
Boolean
)
sourceFetchPartitions
:
Boolean
)
extends
StreamTableSource
[
Row
]
with
PartitionableTableSource
{
...
...
@@ -626,8 +626,8 @@ class TestPartitionableTableSource(
)
override
def
getPartitions
:
JList
[
JMap
[
String
,
String
]]
=
{
if
(
isCatalogTable
)
{
throw
new
RuntimeException
(
"Should not expected."
)
if
(
!
sourceFetchPartitions
)
{
throw
new
UnsupportedOperationException
(
)
}
List
(
Map
(
"part1"
->
"A"
,
"part2"
->
"1"
).
asJava
,
...
...
@@ -639,7 +639,7 @@ class TestPartitionableTableSource(
override
def
applyPartitionPruning
(
remainingPartitions
:
JList
[
JMap
[
String
,
String
]])
:
TableSource
[
_
]
=
{
new
TestPartitionableTableSource
(
isBounded
,
remainingPartitions
,
isCatalogTable
)
new
TestPartitionableTableSource
(
isBounded
,
remainingPartitions
,
sourceFetchPartitions
)
}
override
def
getDataStream
(
execEnv
:
StreamExecutionEnvironment
)
:
DataStream
[
Row
]
=
{
...
...
@@ -787,7 +787,7 @@ class TestPartitionableSourceFactory extends TableSourceFactory[Row] {
dp
.
putProperties
(
properties
)
val
isBounded
=
dp
.
getBoolean
(
"is-bounded"
)
val
isCatalogTable
=
dp
.
getBoolean
(
"is-catalog-table
"
)
val
sourceFetchPartitions
=
dp
.
getBoolean
(
"source-fetch-partitions
"
)
val
remainingPartitions
=
dp
.
getOptionalArray
(
"remaining-partition"
,
new
function
.
Function
[
String
,
util.Map
[
String
,
String
]]
{
override
def
apply
(
t
:
String
)
:
util.Map
[
String
,
String
]
=
{
...
...
@@ -800,7 +800,7 @@ class TestPartitionableSourceFactory extends TableSourceFactory[Row] {
new
TestPartitionableTableSource
(
isBounded
,
remainingPartitions
,
isCatalogTable
)
sourceFetchPartitions
)
}
}
...
...
@@ -827,11 +827,11 @@ object TestPartitionableSourceFactory {
tableName
:
String
,
isBounded
:
Boolean
,
tableSchema
:
TableSchema
=
tableSchema
,
remainingPartitions
:
JList
[
JMap
[
String
,
String
]]
=
null
)
:
Unit
=
{
remainingPartitions
:
JList
[
JMap
[
String
,
String
]]
=
null
,
sourceFetchPartitions
:
Boolean
=
false
)
:
Unit
=
{
val
properties
=
new
DescriptorProperties
()
properties
.
putString
(
"is-bounded"
,
isBounded
.
toString
)
val
isCatalogTable
=
true
properties
.
putBoolean
(
"is-catalog-table"
,
isCatalogTable
)
properties
.
putBoolean
(
"source-fetch-partitions"
,
sourceFetchPartitions
)
properties
.
putString
(
CONNECTOR_TYPE
,
"TestPartitionableSource"
)
if
(
remainingPartitions
!=
null
)
{
remainingPartitions
.
zipWithIndex
.
foreach
{
case
(
part
,
i
)
=>
...
...
@@ -854,19 +854,17 @@ object TestPartitionableSourceFactory {
val
path
=
new
ObjectPath
(
tEnv
.
getCurrentDatabase
,
tableName
)
catalog
.
createTable
(
path
,
table
,
false
)
if
(
isCatalogTable
)
{
val
partitions
=
List
(
Map
(
"part1"
->
"A"
,
"part2"
->
"1"
).
asJava
,
Map
(
"part1"
->
"A"
,
"part2"
->
"2"
).
asJava
,
Map
(
"part1"
->
"B"
,
"part2"
->
"3"
).
asJava
,
Map
(
"part1"
->
"C"
,
"part2"
->
"1"
).
asJava
)
partitions
.
foreach
(
spec
=>
catalog
.
createPartition
(
path
,
new
CatalogPartitionSpec
(
new
java
.
util
.
LinkedHashMap
(
spec
)),
new
CatalogPartitionImpl
(
Map
[
String
,
String
](),
""
),
true
))
}
val
partitions
=
List
(
Map
(
"part1"
->
"A"
,
"part2"
->
"1"
).
asJava
,
Map
(
"part1"
->
"A"
,
"part2"
->
"2"
).
asJava
,
Map
(
"part1"
->
"B"
,
"part2"
->
"3"
).
asJava
,
Map
(
"part1"
->
"C"
,
"part2"
->
"1"
).
asJava
)
partitions
.
foreach
(
spec
=>
catalog
.
createPartition
(
path
,
new
CatalogPartitionSpec
(
new
java
.
util
.
LinkedHashMap
(
spec
)),
new
CatalogPartitionImpl
(
Map
[
String
,
String
](),
""
),
true
))
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录