Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
bf6df12d
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,发现更多精彩内容 >>
提交
bf6df12d
编写于
6月 28, 2016
作者:
J
Jark Wu
提交者:
twalthr
7月 04, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-4109] [tableAPI] Change the name of ternary condition operator 'eval' to '?'
This closes #2173.
上级
b40cba60
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
30 addition
and
30 deletion
+30
-30
docs/apis/table.md
docs/apis/table.md
+2
-2
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/scala/table/expressionDsl.scala
...cala/org/apache/flink/api/scala/table/expressionDsl.scala
+4
-4
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/expressions/ExpressionParser.scala
...apache/flink/api/table/expressions/ExpressionParser.scala
+10
-10
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/expressions/logic.scala
.../scala/org/apache/flink/api/table/expressions/logic.scala
+2
-2
flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/batch/table/ExpressionsITCase.java
.../apache/flink/api/java/batch/table/ExpressionsITCase.java
+6
-6
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/batch/table/ExpressionsITCase.scala
...pache/flink/api/scala/batch/table/ExpressionsITCase.scala
+6
-6
未找到文件。
docs/apis/table.md
浏览文件 @
bf6df12d
...
...
@@ -748,7 +748,7 @@ unary = [ "!" | "-" ] , composite ;
composite = suffixed | atom ;
suffixed = cast | as | aggregation | nullCheck |
evaluate
| functionCall ;
suffixed = cast | as | aggregation | nullCheck |
if
| functionCall ;
cast = composite , ".cast(" , dataType , ")" ;
...
...
@@ -760,7 +760,7 @@ aggregation = composite , ( ".sum" | ".min" | ".max" | ".count" | ".avg" ) , [ "
nullCheck = composite , ( ".isNull" | ".isNotNull" ) , [ "()" ] ;
evaluate = composite , ".eval
(" , expression , "," , expression , ")" ;
if = composite , ".?
(" , expression , "," , expression , ")" ;
functionCall = composite , "." , functionIdentifier , "(" , [ expression , { "," , expression } ] , ")"
...
...
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/scala/table/expressionDsl.scala
浏览文件 @
bf6df12d
...
...
@@ -71,16 +71,16 @@ trait ImplicitExpressionOperations {
def
desc
=
Desc
(
expr
)
/**
*
C
onditional operator that decides which of two other expressions should be evaluated
*
Ternary c
onditional operator that decides which of two other expressions should be evaluated
* based on a evaluated boolean condition.
*
* e.g. (42 > 5).
eval
("A", "B") leads to "A"
* e.g. (42 > 5).
?
("A", "B") leads to "A"
*
* @param ifTrue expression to be evaluated if condition holds
* @param ifFalse expression to be evaluated if condition does not hold
*/
def
eval
(
ifTrue
:
Expression
,
ifFalse
:
Expression
)
=
{
Eval
(
expr
,
ifTrue
,
ifFalse
)
def
?
(
ifTrue
:
Expression
,
ifFalse
:
Expression
)
=
{
If
(
expr
,
ifTrue
,
ifFalse
)
}
// scalar functions
...
...
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/expressions/ExpressionParser.scala
浏览文件 @
bf6df12d
...
...
@@ -51,7 +51,7 @@ object ExpressionParser extends JavaTokenParsers with PackratParsers {
lazy
val
IS_NOT_NULL
:
Keyword
=
Keyword
(
"isNotNull"
)
lazy
val
CAST
:
Keyword
=
Keyword
(
"cast"
)
lazy
val
NULL
:
Keyword
=
Keyword
(
"Null"
)
lazy
val
EVAL
:
Keyword
=
Keyword
(
"eval
"
)
lazy
val
IF
:
Keyword
=
Keyword
(
"?
"
)
lazy
val
ASC
:
Keyword
=
Keyword
(
"asc"
)
lazy
val
DESC
:
Keyword
=
Keyword
(
"desc"
)
lazy
val
TO_DATE
:
Keyword
=
Keyword
(
"toDate"
)
...
...
@@ -61,7 +61,7 @@ object ExpressionParser extends JavaTokenParsers with PackratParsers {
def
functionIdent
:
ExpressionParser.Parser
[
String
]
=
not
(
AS
)
~
not
(
COUNT
)
~
not
(
AVG
)
~
not
(
MIN
)
~
not
(
MAX
)
~
not
(
SUM
)
~
not
(
IS_NULL
)
~
not
(
IS_NOT_NULL
)
~
not
(
CAST
)
~
not
(
NULL
)
~
not
(
EVAL
)
~>
super
.
ident
not
(
IF
)
~>
super
.
ident
// data types
...
...
@@ -173,9 +173,9 @@ object ExpressionParser extends JavaTokenParsers with PackratParsers {
Trim
(
TrimConstants
.
TRIM_BOTH
,
TrimConstants
.
TRIM_DEFAULT_CHAR
,
e
)
}
lazy
val
suffix
Eval
:
PackratParser
[
Expression
]
=
composite
~
"."
~
EVAL
~
"("
~
expression
~
","
~
expression
~
")"
^^
{
case
condition
~
_
~
_
~
_
~
ifTrue
~
_
~
ifFalse
~
_
=>
Eval
(
condition
,
ifTrue
,
ifFalse
)
lazy
val
suffix
If
:
PackratParser
[
Expression
]
=
composite
~
"."
~
IF
~
"("
~
expression
~
","
~
expression
~
")"
^^
{
case
condition
~
_
~
_
~
_
~
ifTrue
~
_
~
ifFalse
~
_
=>
If
(
condition
,
ifTrue
,
ifFalse
)
}
lazy
val
suffixFunctionCall
=
...
...
@@ -200,7 +200,7 @@ object ExpressionParser extends JavaTokenParsers with PackratParsers {
lazy
val
suffixed
:
PackratParser
[
Expression
]
=
suffixIsNull
|
suffixIsNotNull
|
suffixSum
|
suffixMin
|
suffixMax
|
suffixCount
|
suffixAvg
|
suffixCast
|
suffixAs
|
suffixTrim
|
suffixTrimWithoutArgs
|
suffix
Eval
|
suffixFunctionCall
|
suffixCast
|
suffixAs
|
suffixTrim
|
suffixTrimWithoutArgs
|
suffix
If
|
suffixFunctionCall
|
suffixAsc
|
suffixDesc
|
suffixToDate
|
suffixToTimestamp
|
suffixToTime
// prefix operators
...
...
@@ -236,9 +236,9 @@ object ExpressionParser extends JavaTokenParsers with PackratParsers {
case
_
~
_
~
e
~
_
~
target
~
_
=>
Alias
(
e
,
target
.
name
)
}
lazy
val
prefix
Eval
:
PackratParser
[
Expression
]
=
composite
~
EVAL
~
"("
~
expression
~
","
~
expression
~
","
~
expression
~
")"
^^
{
case
_
~
_
~
condition
~
_
~
ifTrue
~
_
~
ifFalse
~
_
=>
Eval
(
condition
,
ifTrue
,
ifFalse
)
lazy
val
prefix
If
:
PackratParser
[
Expression
]
=
composite
~
IF
~
"("
~
expression
~
","
~
expression
~
","
~
expression
~
")"
^^
{
case
_
~
_
~
condition
~
_
~
ifTrue
~
_
~
ifFalse
~
_
=>
If
(
condition
,
ifTrue
,
ifFalse
)
}
lazy
val
prefixFunctionCall
=
functionIdent
~
"("
~
repsep
(
expression
,
","
)
~
")"
^^
{
...
...
@@ -263,7 +263,7 @@ object ExpressionParser extends JavaTokenParsers with PackratParsers {
lazy
val
prefixed
:
PackratParser
[
Expression
]
=
prefixIsNull
|
prefixIsNotNull
|
prefixSum
|
prefixMin
|
prefixMax
|
prefixCount
|
prefixAvg
|
prefixCast
|
prefixAs
|
prefixTrim
|
prefixTrimWithoutArgs
|
prefix
Eval
|
prefixFunctionCall
prefixCast
|
prefixAs
|
prefixTrim
|
prefixTrimWithoutArgs
|
prefix
If
|
prefixFunctionCall
// suffix/prefix composite
...
...
flink-libraries/flink-table/src/main/scala/org/apache/flink/api/table/expressions/logic.scala
浏览文件 @
bf6df12d
...
...
@@ -76,7 +76,7 @@ case class Or(left: Expression, right: Expression) extends BinaryPredicate {
}
}
case
class
Eval
(
case
class
If
(
condition
:
Expression
,
ifTrue
:
Expression
,
ifFalse
:
Expression
)
...
...
@@ -100,7 +100,7 @@ case class Eval(
ValidationSuccess
}
else
{
ValidationFailure
(
s
"
Eval
should have boolean condition and same type of ifTrue and ifFalse, get "
+
s
"
If
should have boolean condition and same type of ifTrue and ifFalse, get "
+
s
"(${condition.resultType}, ${ifTrue.resultType}, ${ifFalse.resultType})"
)
}
}
...
...
flink-libraries/flink-table/src/test/java/org/apache/flink/api/java/batch/table/ExpressionsITCase.java
浏览文件 @
bf6df12d
...
...
@@ -135,7 +135,7 @@ public class ExpressionsITCase extends TableProgramsTestBase {
}
@Test
public
void
test
Eval
()
throws
Exception
{
public
void
test
If
()
throws
Exception
{
ExecutionEnvironment
env
=
ExecutionEnvironment
.
getExecutionEnvironment
();
BatchTableEnvironment
tableEnv
=
TableEnvironment
.
getTableEnvironment
(
env
,
config
());
...
...
@@ -146,9 +146,9 @@ public class ExpressionsITCase extends TableProgramsTestBase {
tableEnv
.
fromDataSet
(
input
,
"a, b"
);
Table
result
=
table
.
select
(
"(b && true).
eval
('true', 'false'),"
+
"false.
eval
('true', 'false'),"
+
"true.
eval(true.eval(true.eval
(10, 4), 4), 4)"
);
"(b && true).
?
('true', 'false'),"
+
"false.
?
('true', 'false'),"
+
"true.
?(true.?(true.?
(10, 4), 4), 4)"
);
DataSet
<
Row
>
ds
=
tableEnv
.
toDataSet
(
result
,
Row
.
class
);
List
<
Row
>
results
=
ds
.
collect
();
...
...
@@ -157,7 +157,7 @@ public class ExpressionsITCase extends TableProgramsTestBase {
}
@Test
(
expected
=
ValidationException
.
class
)
public
void
test
Eval
InvalidTypes
()
throws
Exception
{
public
void
test
If
InvalidTypes
()
throws
Exception
{
ExecutionEnvironment
env
=
ExecutionEnvironment
.
getExecutionEnvironment
();
BatchTableEnvironment
tableEnv
=
TableEnvironment
.
getTableEnvironment
(
env
,
config
());
...
...
@@ -167,7 +167,7 @@ public class ExpressionsITCase extends TableProgramsTestBase {
Table
table
=
tableEnv
.
fromDataSet
(
input
,
"a, b"
);
Table
result
=
table
.
select
(
"(b && true).
eval
(5, 'false')"
);
Table
result
=
table
.
select
(
"(b && true).
?
(5, 'false')"
);
DataSet
<
Row
>
ds
=
tableEnv
.
toDataSet
(
result
,
Row
.
class
);
List
<
Row
>
results
=
ds
.
collect
();
...
...
flink-libraries/flink-table/src/test/scala/org/apache/flink/api/scala/batch/table/ExpressionsITCase.scala
浏览文件 @
bf6df12d
...
...
@@ -129,15 +129,15 @@ class ExpressionsITCase(
}
@Test
def
test
Eval
()
:
Unit
=
{
def
test
If
()
:
Unit
=
{
val
env
=
ExecutionEnvironment
.
getExecutionEnvironment
val
tEnv
=
TableEnvironment
.
getTableEnvironment
(
env
,
config
)
val
t
=
env
.
fromElements
((
5
,
true
)).
toTable
(
tEnv
,
'a
,
'b
)
.
select
(
(
'b
&&
true
).
eval
(
"true"
,
"false"
),
false
.
eval
(
"true"
,
"false"
),
true
.
eval
(
true
.
eval
(
true
.
eval
(
10
,
4
),
4
),
4
))
(
'b
&&
true
).
?
(
"true"
,
"false"
),
false
.
?
(
"true"
,
"false"
),
true
.
?(
true
.?(
true
.?
(
10
,
4
),
4
),
4
))
val
expected
=
"true,false,10"
val
results
=
t
.
toDataSet
[
Row
].
collect
()
...
...
@@ -145,12 +145,12 @@ class ExpressionsITCase(
}
@Test
(
expected
=
classOf
[
ValidationException
])
def
test
Eval
InvalidTypes
()
:
Unit
=
{
def
test
If
InvalidTypes
()
:
Unit
=
{
val
env
=
ExecutionEnvironment
.
getExecutionEnvironment
val
tEnv
=
TableEnvironment
.
getTableEnvironment
(
env
,
config
)
val
t
=
env
.
fromElements
((
5
,
true
)).
toTable
(
tEnv
,
'a
,
'b
)
.
select
((
'b
&&
true
).
eval
(
5
,
"false"
))
.
select
((
'b
&&
true
).
?
(
5
,
"false"
))
val
expected
=
"true,false,3,10"
val
results
=
t
.
toDataSet
[
Row
].
collect
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录