Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
da10d540
提交
da10d540
authored
8月 21, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Expression.getSubexpression() and getSubexpressionCount()
上级
3fc4e02e
隐藏空白字符变更
内嵌
并排
正在显示
11 个修改的文件
包含
115 行增加
和
102 行删除
+115
-102
Query.java
h2/src/main/org/h2/command/dml/Query.java
+12
-38
Comparison.java
h2/src/main/org/h2/expression/Comparison.java
+16
-14
ConditionAndOr.java
h2/src/main/org/h2/expression/ConditionAndOr.java
+13
-14
ConditionNot.java
h2/src/main/org/h2/expression/ConditionNot.java
+11
-7
Expression.java
h2/src/main/org/h2/expression/Expression.java
+20
-0
Function.java
h2/src/main/org/h2/expression/Function.java
+10
-0
Operation.java
h2/src/main/org/h2/expression/Operation.java
+13
-14
UnaryOperation.java
h2/src/main/org/h2/expression/UnaryOperation.java
+11
-7
FullText.java
h2/src/main/org/h2/fulltext/FullText.java
+5
-7
distinct.sql
h2/src/test/org/h2/test/scripts/distinct.sql
+3
-0
dictionary.txt
h2/src/tools/org/h2/build/doc/dictionary.txt
+1
-1
没有找到文件。
h2/src/main/org/h2/command/dml/Query.java
浏览文件 @
da10d540
...
...
@@ -12,19 +12,14 @@ import java.util.List;
import
org.h2.api.ErrorCode
;
import
org.h2.command.Prepared
;
import
org.h2.engine.Database
;
import
org.h2.engine.Session
;
import
org.h2.engine.Mode.ModeEnum
;
import
org.h2.engine.Session
;
import
org.h2.expression.Alias
;
import
org.h2.expression.Comparison
;
import
org.h2.expression.ConditionAndOr
;
import
org.h2.expression.ConditionNot
;
import
org.h2.expression.Expression
;
import
org.h2.expression.ExpressionColumn
;
import
org.h2.expression.ExpressionVisitor
;
import
org.h2.expression.Function
;
import
org.h2.expression.Operation
;
import
org.h2.expression.Parameter
;
import
org.h2.expression.UnaryOperation
;
import
org.h2.expression.ValueExpression
;
import
org.h2.message.DbException
;
import
org.h2.result.ResultInterface
;
...
...
@@ -530,6 +525,7 @@ public abstract class Query extends Prepared {
*/
private
static
boolean
checkOrderOther
(
Session
session
,
Expression
expr
,
ArrayList
<
String
>
expressionSQL
)
{
if
(
expr
.
isConstant
())
{
// ValueExpression or other
return
true
;
}
String
exprSQL
=
expr
.
getSQL
();
...
...
@@ -538,41 +534,19 @@ public abstract class Query extends Prepared {
return
true
;
}
}
if
(
expr
instanceof
Function
)
{
Function
function
=
(
Function
)
expr
;
if
(!
function
.
isDeterministic
())
{
int
count
=
expr
.
getSubexpressionCount
();
if
(
expr
instanceof
Function
?
!((
Function
)
expr
).
isDeterministic
()
:
count
<=
0
)
{
// If expression is a non-deterministic function or expression is an
// ExpressionColumn, Parameter, SequenceValue or has other
// unsupported type without subexpressions
return
false
;
}
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
if
(!
checkOrderOther
(
session
,
expr
.
getSubexpression
(
i
),
expressionSQL
))
{
return
false
;
}
for
(
Expression
e
:
function
.
getArgs
())
{
if
(!
checkOrderOther
(
session
,
e
,
expressionSQL
))
{
return
false
;
}
}
return
true
;
}
if
(
expr
instanceof
Operation
)
{
Operation
operation
=
(
Operation
)
expr
;
Expression
right
=
operation
.
getRightSubExpression
();
return
checkOrderOther
(
session
,
operation
.
getLeftSubExpression
(),
expressionSQL
)
&&
(
right
==
null
||
checkOrderOther
(
session
,
right
,
expressionSQL
));
}
if
(
expr
instanceof
UnaryOperation
)
{
return
checkOrderOther
(
session
,
((
UnaryOperation
)
expr
).
getSubExpression
(),
expressionSQL
);
}
if
(
expr
instanceof
ConditionAndOr
)
{
ConditionAndOr
condition
=
(
ConditionAndOr
)
expr
;
return
checkOrderOther
(
session
,
condition
.
getLeftSubExpression
(),
expressionSQL
)
&&
checkOrderOther
(
session
,
condition
.
getRightSubExpression
(),
expressionSQL
);
}
if
(
expr
instanceof
ConditionNot
)
{
return
checkOrderOther
(
session
,
((
ConditionNot
)
expr
).
getSubCondition
(),
expressionSQL
);
}
if
(
expr
instanceof
Comparison
)
{
Comparison
condition
=
(
Comparison
)
expr
;
return
checkOrderOther
(
session
,
condition
.
getLeftSubExpression
(),
expressionSQL
)
&&
checkOrderOther
(
session
,
condition
.
getRightSubExpression
(),
expressionSQL
);
}
return
false
;
return
true
;
}
/**
...
...
h2/src/main/org/h2/expression/Comparison.java
浏览文件 @
da10d540
...
...
@@ -587,22 +587,24 @@ public class Comparison extends Condition {
return
null
;
}
/**
* Get the left sub-expression of this condition.
*
* @return the left sub-expression
*/
public
Expression
getLeftSubExpression
()
{
return
left
;
@Override
public
int
getSubexpressionCount
()
{
return
compareType
==
IS_NULL
||
compareType
==
IS_NOT_NULL
?
1
:
2
;
}
/**
* Get the right sub-expression of this condition.
*
* @return the right sub-expression
*/
public
Expression
getRightSubExpression
()
{
return
right
;
@Override
public
Expression
getSubexpression
(
int
index
)
{
switch
(
index
)
{
case
0
:
return
left
;
case
1
:
if
(
compareType
!=
IS_NULL
&&
compareType
!=
IS_NOT_NULL
)
{
return
right
;
}
//$FALL-THROUGH$
default
:
throw
new
IndexOutOfBoundsException
();
}
}
}
h2/src/main/org/h2/expression/ConditionAndOr.java
浏览文件 @
da10d540
...
...
@@ -283,22 +283,21 @@ public class ConditionAndOr extends Condition {
return
left
.
getCost
()
+
right
.
getCost
();
}
/**
* Get the left sub-expression of this condition.
*
* @return the left sub-expression
*/
public
Expression
getLeftSubExpression
()
{
return
left
;
@Override
public
int
getSubexpressionCount
()
{
return
2
;
}
/**
* Get the right sub-expression of this condition.
*
* @return the right sub-expression
*/
public
Expression
getRightSubExpression
()
{
return
right
;
@Override
public
Expression
getSubexpression
(
int
index
)
{
switch
(
index
)
{
case
0
:
return
left
;
case
1
:
return
right
;
default
:
throw
new
IndexOutOfBoundsException
();
}
}
}
h2/src/main/org/h2/expression/ConditionNot.java
浏览文件 @
da10d540
...
...
@@ -98,13 +98,17 @@ public class ConditionNot extends Condition {
return
condition
.
getCost
();
}
/**
* Get the sub-expression of this condition.
*
* @return the sub-expression
*/
public
Expression
getSubCondition
()
{
return
condition
;
@Override
public
int
getSubexpressionCount
()
{
return
1
;
}
@Override
public
Expression
getSubexpression
(
int
index
)
{
if
(
index
==
0
)
{
return
condition
;
}
throw
new
IndexOutOfBoundsException
();
}
}
h2/src/main/org/h2/expression/Expression.java
浏览文件 @
da10d540
...
...
@@ -357,4 +357,24 @@ public abstract class Expression {
}
}
/**
* Returns count of subexpressions.
*
* @return count of subexpressions
*/
public
int
getSubexpressionCount
()
{
return
0
;
}
/**
* Returns subexpression with specified index.
*
* @param index 0-based index
* @return subexpression with specified index
* @throws IndexOutOfBoundsException if specified index is not valid
*/
public
Expression
getSubexpression
(
int
index
)
{
throw
new
IndexOutOfBoundsException
();
}
}
h2/src/main/org/h2/expression/Function.java
浏览文件 @
da10d540
...
...
@@ -2710,4 +2710,14 @@ public class Function extends Expression implements FunctionCall {
return
info
.
type
==
NEXTVAL
;
}
@Override
public
int
getSubexpressionCount
()
{
return
args
.
length
;
}
@Override
public
Expression
getSubexpression
(
int
index
)
{
return
args
[
index
];
}
}
h2/src/main/org/h2/expression/Operation.java
浏览文件 @
da10d540
...
...
@@ -451,22 +451,21 @@ public class Operation extends Expression {
return
left
.
getCost
()
+
right
.
getCost
()
+
1
;
}
/**
* Get the left sub-expression of this operation.
*
* @return the left sub-expression
*/
public
Expression
getLeftSubExpression
()
{
return
left
;
@Override
public
int
getSubexpressionCount
()
{
return
2
;
}
/**
* Get the right sub-expression of this operation.
*
* @return the right sub-expression
*/
public
Expression
getRightSubExpression
()
{
return
right
;
@Override
public
Expression
getSubexpression
(
int
index
)
{
switch
(
index
)
{
case
0
:
return
left
;
case
1
:
return
right
;
default
:
throw
new
IndexOutOfBoundsException
();
}
}
}
h2/src/main/org/h2/expression/UnaryOperation.java
浏览文件 @
da10d540
...
...
@@ -96,13 +96,17 @@ public class UnaryOperation extends Expression {
return
arg
.
getCost
()
+
1
;
}
/**
* Get the sub-expression of this operation.
*
* @return the sub-expression
*/
public
Expression
getSubExpression
()
{
return
arg
;
@Override
public
int
getSubexpressionCount
()
{
return
1
;
}
@Override
public
Expression
getSubexpression
(
int
index
)
{
if
(
index
==
0
)
{
return
arg
;
}
throw
new
IndexOutOfBoundsException
();
}
}
h2/src/main/org/h2/fulltext/FullText.java
浏览文件 @
da10d540
...
...
@@ -669,19 +669,17 @@ public class FullText {
ArrayList
<
String
>
data
,
Expression
expr
)
{
if
(
expr
instanceof
ConditionAndOr
)
{
ConditionAndOr
and
=
(
ConditionAndOr
)
expr
;
Expression
left
=
and
.
getLeftSubExpression
();
Expression
right
=
and
.
getRightSubExpression
();
addColumnData
(
columns
,
data
,
left
);
addColumnData
(
columns
,
data
,
right
);
addColumnData
(
columns
,
data
,
and
.
getSubexpression
(
0
));
addColumnData
(
columns
,
data
,
and
.
getSubexpression
(
1
));
}
else
{
Comparison
comp
=
(
Comparison
)
expr
;
ExpressionColumn
ec
=
(
ExpressionColumn
)
comp
.
getLeftSubExpression
();
ValueExpression
ev
=
(
ValueExpression
)
comp
.
getRightSubExpression
();
ExpressionColumn
ec
=
(
ExpressionColumn
)
comp
.
getSubexpression
(
0
);
String
columnName
=
ec
.
getColumnName
();
columns
.
add
(
columnName
);
if
(
e
v
==
null
)
{
if
(
e
xpr
.
getSubexpressionCount
()
==
1
)
{
data
.
add
(
null
);
}
else
{
ValueExpression
ev
=
(
ValueExpression
)
comp
.
getSubexpression
(
1
);
data
.
add
(
ev
.
getValue
(
null
).
getString
());
}
}
...
...
h2/src/test/org/h2/test/scripts/distinct.sql
浏览文件 @
da10d540
...
...
@@ -66,6 +66,9 @@ SELECT DISTINCT NAME, ID + 1 FROM TEST ORDER BY UPPER(NAME) || (ID + 1);
SELECT
DISTINCT
ID
FROM
TEST
ORDER
BY
NAME
;
>
exception
ORDER_BY_NOT_IN_RESULT
SELECT
DISTINCT
ID
FROM
TEST
ORDER
BY
UPPER
(
NAME
);
>
exception
ORDER_BY_NOT_IN_RESULT
SELECT
DISTINCT
ID
FROM
TEST
ORDER
BY
CURRENT_TIMESTAMP
;
>
exception
ORDER_BY_NOT_IN_RESULT
...
...
h2/src/tools/org/h2/build/doc/dictionary.txt
浏览文件 @
da10d540
...
...
@@ -789,4 +789,4 @@ inconsistencies discover eliminated violates tweaks postpone leftovers
tied ties
launched unavailable smallmoney erroneously multiplier newid pan streamline unmap preview unexpectedly presumably
converging smth rng curs casts unmapping unmapper
immediate hhmmss scheduled hhmm prematurely postponed arranges
immediate hhmmss scheduled hhmm prematurely postponed arranges
subexpression subexpressions
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论