Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e2c2fc78
提交
e2c2fc78
authored
8月 15, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Split large methods in Parser and IntervalOperation
上级
5ea97cd3
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
118 行增加
和
110 行删除
+118
-110
Parser.java
h2/src/main/org/h2/command/Parser.java
+59
-55
IntervalOperation.java
h2/src/main/org/h2/expression/IntervalOperation.java
+59
-55
没有找到文件。
h2/src/main/org/h2/command/Parser.java
浏览文件 @
e2c2fc78
...
@@ -3512,61 +3512,7 @@ public class Parser {
...
@@ -3512,61 +3512,7 @@ public class Parser {
}
}
}
}
}
else
if
(
equalsToken
(
"INTERVAL"
,
name
))
{
}
else
if
(
equalsToken
(
"INTERVAL"
,
name
))
{
boolean
negative
=
readIf
(
MINUS_SIGN
);
r
=
readInterval
();
if
(!
negative
)
{
readIf
(
PLUS_SIGN
);
}
String
s
=
readString
();
IntervalQualifier
qualifier
;
if
(
readIf
(
"YEAR"
))
{
if
(
readIf
(
"TO"
))
{
read
(
"MONTH"
);
qualifier
=
IntervalQualifier
.
YEAR_TO_MONTH
;
}
else
{
qualifier
=
IntervalQualifier
.
YEAR
;
}
}
else
if
(
readIf
(
"MONTH"
))
{
qualifier
=
IntervalQualifier
.
MONTH
;
}
else
if
(
readIf
(
"DAY"
))
{
if
(
readIf
(
"TO"
))
{
if
(
readIf
(
"HOUR"
))
{
qualifier
=
IntervalQualifier
.
DAY_TO_HOUR
;
}
else
if
(
readIf
(
"MINUTE"
))
{
qualifier
=
IntervalQualifier
.
DAY_TO_MINUTE
;
}
else
{
read
(
"SECOND"
);
qualifier
=
IntervalQualifier
.
DAY_TO_SECOND
;
}
}
else
{
qualifier
=
IntervalQualifier
.
DAY
;
}
}
else
if
(
readIf
(
"HOUR"
))
{
if
(
readIf
(
"TO"
))
{
if
(
readIf
(
"MINUTE"
))
{
qualifier
=
IntervalQualifier
.
HOUR_TO_MINUTE
;
}
else
{
read
(
"SECOND"
);
qualifier
=
IntervalQualifier
.
HOUR_TO_SECOND
;
}
}
else
{
qualifier
=
IntervalQualifier
.
HOUR
;
}
}
else
if
(
readIf
(
"MINUTE"
))
{
if
(
readIf
(
"TO"
))
{
read
(
"SECOND"
);
qualifier
=
IntervalQualifier
.
MINUTE_TO_SECOND
;
}
else
{
qualifier
=
IntervalQualifier
.
MINUTE
;
}
}
else
{
read
(
"SECOND"
);
qualifier
=
IntervalQualifier
.
SECOND
;
}
try
{
r
=
ValueExpression
.
get
(
DateTimeUtils
.
parseInterval
(
qualifier
,
negative
,
s
));
}
catch
(
Exception
e
)
{
throw
DbException
.
get
(
ErrorCode
.
INVALID_DATETIME_CONSTANT_2
,
e
,
"INTERVAL"
,
s
);
}
}
else
if
(
currentTokenType
==
VALUE
&&
}
else
if
(
currentTokenType
==
VALUE
&&
currentValue
.
getType
()
==
Value
.
STRING
)
{
currentValue
.
getType
()
==
Value
.
STRING
)
{
if
(
equalsToken
(
"DATE"
,
name
)
||
if
(
equalsToken
(
"DATE"
,
name
)
||
...
@@ -3718,6 +3664,64 @@ public class Parser {
...
@@ -3718,6 +3664,64 @@ public class Parser {
return
r
;
return
r
;
}
}
private
Expression
readInterval
()
{
boolean
negative
=
readIf
(
MINUS_SIGN
);
if
(!
negative
)
{
readIf
(
PLUS_SIGN
);
}
String
s
=
readString
();
IntervalQualifier
qualifier
;
if
(
readIf
(
"YEAR"
))
{
if
(
readIf
(
"TO"
))
{
read
(
"MONTH"
);
qualifier
=
IntervalQualifier
.
YEAR_TO_MONTH
;
}
else
{
qualifier
=
IntervalQualifier
.
YEAR
;
}
}
else
if
(
readIf
(
"MONTH"
))
{
qualifier
=
IntervalQualifier
.
MONTH
;
}
else
if
(
readIf
(
"DAY"
))
{
if
(
readIf
(
"TO"
))
{
if
(
readIf
(
"HOUR"
))
{
qualifier
=
IntervalQualifier
.
DAY_TO_HOUR
;
}
else
if
(
readIf
(
"MINUTE"
))
{
qualifier
=
IntervalQualifier
.
DAY_TO_MINUTE
;
}
else
{
read
(
"SECOND"
);
qualifier
=
IntervalQualifier
.
DAY_TO_SECOND
;
}
}
else
{
qualifier
=
IntervalQualifier
.
DAY
;
}
}
else
if
(
readIf
(
"HOUR"
))
{
if
(
readIf
(
"TO"
))
{
if
(
readIf
(
"MINUTE"
))
{
qualifier
=
IntervalQualifier
.
HOUR_TO_MINUTE
;
}
else
{
read
(
"SECOND"
);
qualifier
=
IntervalQualifier
.
HOUR_TO_SECOND
;
}
}
else
{
qualifier
=
IntervalQualifier
.
HOUR
;
}
}
else
if
(
readIf
(
"MINUTE"
))
{
if
(
readIf
(
"TO"
))
{
read
(
"SECOND"
);
qualifier
=
IntervalQualifier
.
MINUTE_TO_SECOND
;
}
else
{
qualifier
=
IntervalQualifier
.
MINUTE
;
}
}
else
{
read
(
"SECOND"
);
qualifier
=
IntervalQualifier
.
SECOND
;
}
try
{
return
ValueExpression
.
get
(
DateTimeUtils
.
parseInterval
(
qualifier
,
negative
,
s
));
}
catch
(
Exception
e
)
{
throw
DbException
.
get
(
ErrorCode
.
INVALID_DATETIME_CONSTANT_2
,
e
,
"INTERVAL"
,
s
);
}
}
private
Expression
parseDB2SpecialRegisters
(
String
name
)
{
private
Expression
parseDB2SpecialRegisters
(
String
name
)
{
// Only "CURRENT" name is supported
// Only "CURRENT" name is supported
if
(
readIf
(
"TIMESTAMP"
))
{
if
(
readIf
(
"TIMESTAMP"
))
{
...
...
h2/src/main/org/h2/expression/IntervalOperation.java
浏览文件 @
e2c2fc78
...
@@ -139,6 +139,53 @@ public class IntervalOperation extends Expression {
...
@@ -139,6 +139,53 @@ public class IntervalOperation extends Expression {
}
}
case
DATETIME_PLUS_INTERVAL:
case
DATETIME_PLUS_INTERVAL:
case
DATETIME_MINUS_INTERVAL:
case
DATETIME_MINUS_INTERVAL:
return
getDateTimeWithInterval
(
l
,
r
,
lType
,
rType
);
case
INTERVAL_MULTIPLY_NUMERIC:
case
INTERVAL_DIVIDE_NUMERIC:
{
BigDecimal
a1
=
new
BigDecimal
(
DateTimeUtils
.
intervalToAbsolute
((
ValueInterval
)
l
));
BigDecimal
a2
=
r
.
getBigDecimal
();
return
DateTimeUtils
.
intervalFromAbsolute
(
IntervalQualifier
.
valueOf
(
lType
-
Value
.
INTERVAL_YEAR
),
(
opType
==
IntervalOpType
.
INTERVAL_MULTIPLY_NUMERIC
?
a1
.
multiply
(
a2
)
:
a1
.
divide
(
a2
))
.
toBigInteger
());
}
case
DATETIME_MINUS_DATETIME:
if
(
lType
==
Value
.
TIME
&&
rType
==
Value
.
TIME
)
{
long
diff
=
((
ValueTime
)
l
).
getNanos
()
-
((
ValueTime
)
r
).
getNanos
();
boolean
negative
=
diff
<
0
;
if
(
negative
)
{
diff
=
-
diff
;
}
return
ValueInterval
.
from
(
IntervalQualifier
.
HOUR_TO_SECOND
,
negative
,
diff
/
3_600_000_000_000L
,
diff
%
3_600_000_000_000L
);
}
else
if
(
lType
==
Value
.
DATE
&&
rType
==
Value
.
DATE
)
{
long
diff
=
DateTimeUtils
.
absoluteDayFromDateValue
(((
ValueDate
)
l
).
getDateValue
())
-
DateTimeUtils
.
absoluteDayFromDateValue
(((
ValueDate
)
r
).
getDateValue
());
boolean
negative
=
diff
<
0
;
if
(
negative
)
{
diff
=
-
diff
;
}
return
ValueInterval
.
from
(
IntervalQualifier
.
DAY
,
negative
,
diff
,
0L
);
}
else
{
long
[]
a
=
DateTimeUtils
.
dateAndTimeFromValue
(
l
);
long
[]
b
=
DateTimeUtils
.
dateAndTimeFromValue
(
r
);
BigInteger
bi1
=
BigInteger
.
valueOf
(
a
[
0
]).
multiply
(
BigInteger
.
valueOf
(
DateTimeUtils
.
NANOS_PER_DAY
))
.
add
(
BigInteger
.
valueOf
(
a
[
1
]));
BigInteger
bi2
=
BigInteger
.
valueOf
(
b
[
0
]).
multiply
(
BigInteger
.
valueOf
(
DateTimeUtils
.
NANOS_PER_DAY
))
.
add
(
BigInteger
.
valueOf
(
b
[
1
]));
BigInteger
diff
=
bi1
.
subtract
(
bi2
);
if
(
lType
==
Value
.
TIMESTAMP_TZ
||
rType
==
Value
.
TIMESTAMP_TZ
)
{
l
=
l
.
convertTo
(
Value
.
TIMESTAMP_TZ
);
r
=
r
.
convertTo
(
Value
.
TIMESTAMP_TZ
);
diff
=
diff
.
add
(
BigInteger
.
valueOf
((((
ValueTimestampTimeZone
)
r
).
getTimeZoneOffsetMins
()
-
((
ValueTimestampTimeZone
)
l
).
getTimeZoneOffsetMins
())
*
60_000_000_000L
));
}
return
DateTimeUtils
.
intervalFromAbsolute
(
IntervalQualifier
.
DAY_TO_SECOND
,
diff
);
}
}
throw
DbException
.
throwInternalError
(
"type="
+
opType
);
}
private
Value
getDateTimeWithInterval
(
Value
l
,
Value
r
,
int
lType
,
int
rType
)
{
switch
(
lType
)
{
switch
(
lType
)
{
case
Value
.
TIME
:
{
case
Value
.
TIME
:
{
if
(
DataType
.
isYearMonthIntervalType
(
rType
))
{
if
(
DataType
.
isYearMonthIntervalType
(
rType
))
{
...
@@ -193,49 +240,6 @@ public class IntervalOperation extends Expression {
...
@@ -193,49 +240,6 @@ public class IntervalOperation extends Expression {
}
}
}
}
}
}
break
;
case
INTERVAL_MULTIPLY_NUMERIC:
case
INTERVAL_DIVIDE_NUMERIC:
{
BigDecimal
a1
=
new
BigDecimal
(
DateTimeUtils
.
intervalToAbsolute
((
ValueInterval
)
l
));
BigDecimal
a2
=
r
.
getBigDecimal
();
return
DateTimeUtils
.
intervalFromAbsolute
(
IntervalQualifier
.
valueOf
(
lType
-
Value
.
INTERVAL_YEAR
),
(
opType
==
IntervalOpType
.
INTERVAL_MULTIPLY_NUMERIC
?
a1
.
multiply
(
a2
)
:
a1
.
divide
(
a2
))
.
toBigInteger
());
}
case
DATETIME_MINUS_DATETIME:
if
(
lType
==
Value
.
TIME
&&
rType
==
Value
.
TIME
)
{
long
diff
=
((
ValueTime
)
l
).
getNanos
()
-
((
ValueTime
)
r
).
getNanos
();
boolean
negative
=
diff
<
0
;
if
(
negative
)
{
diff
=
-
diff
;
}
return
ValueInterval
.
from
(
IntervalQualifier
.
HOUR_TO_SECOND
,
negative
,
diff
/
3_600_000_000_000L
,
diff
%
3_600_000_000_000L
);
}
else
if
(
lType
==
Value
.
DATE
&&
rType
==
Value
.
DATE
)
{
long
diff
=
DateTimeUtils
.
absoluteDayFromDateValue
(((
ValueDate
)
l
).
getDateValue
())
-
DateTimeUtils
.
absoluteDayFromDateValue
(((
ValueDate
)
r
).
getDateValue
());
boolean
negative
=
diff
<
0
;
if
(
negative
)
{
diff
=
-
diff
;
}
return
ValueInterval
.
from
(
IntervalQualifier
.
DAY
,
negative
,
diff
,
0L
);
}
else
{
long
[]
a
=
DateTimeUtils
.
dateAndTimeFromValue
(
l
);
long
[]
b
=
DateTimeUtils
.
dateAndTimeFromValue
(
r
);
BigInteger
bi1
=
BigInteger
.
valueOf
(
a
[
0
]).
multiply
(
BigInteger
.
valueOf
(
DateTimeUtils
.
NANOS_PER_DAY
))
.
add
(
BigInteger
.
valueOf
(
a
[
1
]));
BigInteger
bi2
=
BigInteger
.
valueOf
(
b
[
0
]).
multiply
(
BigInteger
.
valueOf
(
DateTimeUtils
.
NANOS_PER_DAY
))
.
add
(
BigInteger
.
valueOf
(
b
[
1
]));
BigInteger
diff
=
bi1
.
subtract
(
bi2
);
if
(
lType
==
Value
.
TIMESTAMP_TZ
||
rType
==
Value
.
TIMESTAMP_TZ
)
{
l
=
l
.
convertTo
(
Value
.
TIMESTAMP_TZ
);
r
=
r
.
convertTo
(
Value
.
TIMESTAMP_TZ
);
diff
=
diff
.
add
(
BigInteger
.
valueOf
((((
ValueTimestampTimeZone
)
r
).
getTimeZoneOffsetMins
()
-
((
ValueTimestampTimeZone
)
l
).
getTimeZoneOffsetMins
())
*
60_000_000_000L
));
}
return
DateTimeUtils
.
intervalFromAbsolute
(
IntervalQualifier
.
DAY_TO_SECOND
,
diff
);
}
}
throw
DbException
.
throwInternalError
(
"type="
+
opType
);
throw
DbException
.
throwInternalError
(
"type="
+
opType
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论