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 {
}
}
}
else
if
(
equalsToken
(
"INTERVAL"
,
name
))
{
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
{
r
=
ValueExpression
.
get
(
DateTimeUtils
.
parseInterval
(
qualifier
,
negative
,
s
));
}
catch
(
Exception
e
)
{
throw
DbException
.
get
(
ErrorCode
.
INVALID_DATETIME_CONSTANT_2
,
e
,
"INTERVAL"
,
s
);
}
r
=
readInterval
();
}
else
if
(
currentTokenType
==
VALUE
&&
currentValue
.
getType
()
==
Value
.
STRING
)
{
if
(
equalsToken
(
"DATE"
,
name
)
||
...
...
@@ -3718,6 +3664,64 @@ public class Parser {
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
)
{
// Only "CURRENT" name is supported
if
(
readIf
(
"TIMESTAMP"
))
{
...
...
h2/src/main/org/h2/expression/IntervalOperation.java
浏览文件 @
e2c2fc78
...
...
@@ -139,61 +139,7 @@ public class IntervalOperation extends Expression {
}
case
DATETIME_PLUS_INTERVAL:
case
DATETIME_MINUS_INTERVAL:
switch
(
lType
)
{
case
Value
.
TIME
:
{
if
(
DataType
.
isYearMonthIntervalType
(
rType
))
{
throw
DbException
.
throwInternalError
(
"type="
+
rType
);
}
BigInteger
a1
=
BigInteger
.
valueOf
(((
ValueTime
)
l
).
getNanos
());
BigInteger
a2
=
DateTimeUtils
.
intervalToAbsolute
((
ValueInterval
)
r
);
BigInteger
n
=
opType
==
IntervalOpType
.
DATETIME_PLUS_INTERVAL
?
a1
.
add
(
a2
)
:
a1
.
subtract
(
a2
);
if
(
n
.
signum
()
<
0
||
n
.
compareTo
(
BigInteger
.
valueOf
(
DateTimeUtils
.
NANOS_PER_DAY
))
>=
0
)
{
throw
DbException
.
get
(
ErrorCode
.
NUMERIC_VALUE_OUT_OF_RANGE_1
,
n
.
toString
());
}
return
ValueTime
.
fromNanos
(
n
.
longValue
());
}
case
Value
.
DATE
:
case
Value
.
TIMESTAMP
:
case
Value
.
TIMESTAMP_TZ
:
if
(
DataType
.
isYearMonthIntervalType
(
rType
))
{
long
m
=
DateTimeUtils
.
intervalToAbsolute
((
ValueInterval
)
r
).
longValue
();
if
(
opType
==
IntervalOpType
.
DATETIME_MINUS_INTERVAL
)
{
m
=
-
m
;
}
return
DateTimeFunctions
.
dateadd
(
"MONTH"
,
m
,
l
);
}
else
{
BigInteger
a2
=
DateTimeUtils
.
intervalToAbsolute
((
ValueInterval
)
r
);
if
(
lType
==
Value
.
DATE
)
{
BigInteger
a1
=
BigInteger
.
valueOf
(
DateTimeUtils
.
absoluteDayFromDateValue
(((
ValueDate
)
l
).
getDateValue
()));
a2
=
a2
.
divide
(
BigInteger
.
valueOf
(
DateTimeUtils
.
NANOS_PER_DAY
));
BigInteger
n
=
opType
==
IntervalOpType
.
DATETIME_PLUS_INTERVAL
?
a1
.
add
(
a2
)
:
a1
.
subtract
(
a2
);
return
ValueDate
.
fromDateValue
(
DateTimeUtils
.
dateValueFromAbsoluteDay
(
n
.
longValue
()));
}
else
{
long
[]
a
=
DateTimeUtils
.
dateAndTimeFromValue
(
l
);
long
absoluteDay
=
DateTimeUtils
.
absoluteDayFromDateValue
(
a
[
0
]);
long
timeNanos
=
a
[
1
];
BigInteger
[]
dr
=
a2
.
divideAndRemainder
(
BigInteger
.
valueOf
(
DateTimeUtils
.
NANOS_PER_DAY
));
if
(
opType
==
IntervalOpType
.
DATETIME_PLUS_INTERVAL
)
{
absoluteDay
+=
dr
[
0
].
longValue
();
timeNanos
+=
dr
[
1
].
longValue
();
}
else
{
absoluteDay
-=
dr
[
0
].
longValue
();
timeNanos
-=
dr
[
1
].
longValue
();
}
if
(
timeNanos
>=
DateTimeUtils
.
NANOS_PER_DAY
)
{
timeNanos
-=
DateTimeUtils
.
NANOS_PER_DAY
;
absoluteDay
++;
}
else
if
(
timeNanos
<
0
)
{
timeNanos
+=
DateTimeUtils
.
NANOS_PER_DAY
;
absoluteDay
--;
}
return
DateTimeUtils
.
dateTimeToValue
(
l
,
DateTimeUtils
.
dateValueFromAbsoluteDay
(
absoluteDay
),
timeNanos
,
false
);
}
}
}
break
;
return
getDateTimeWithInterval
(
l
,
r
,
lType
,
rType
);
case
INTERVAL_MULTIPLY_NUMERIC:
case
INTERVAL_DIVIDE_NUMERIC:
{
BigDecimal
a1
=
new
BigDecimal
(
DateTimeUtils
.
intervalToAbsolute
((
ValueInterval
)
l
));
...
...
@@ -239,6 +185,64 @@ public class IntervalOperation extends Expression {
throw
DbException
.
throwInternalError
(
"type="
+
opType
);
}
private
Value
getDateTimeWithInterval
(
Value
l
,
Value
r
,
int
lType
,
int
rType
)
{
switch
(
lType
)
{
case
Value
.
TIME
:
{
if
(
DataType
.
isYearMonthIntervalType
(
rType
))
{
throw
DbException
.
throwInternalError
(
"type="
+
rType
);
}
BigInteger
a1
=
BigInteger
.
valueOf
(((
ValueTime
)
l
).
getNanos
());
BigInteger
a2
=
DateTimeUtils
.
intervalToAbsolute
((
ValueInterval
)
r
);
BigInteger
n
=
opType
==
IntervalOpType
.
DATETIME_PLUS_INTERVAL
?
a1
.
add
(
a2
)
:
a1
.
subtract
(
a2
);
if
(
n
.
signum
()
<
0
||
n
.
compareTo
(
BigInteger
.
valueOf
(
DateTimeUtils
.
NANOS_PER_DAY
))
>=
0
)
{
throw
DbException
.
get
(
ErrorCode
.
NUMERIC_VALUE_OUT_OF_RANGE_1
,
n
.
toString
());
}
return
ValueTime
.
fromNanos
(
n
.
longValue
());
}
case
Value
.
DATE
:
case
Value
.
TIMESTAMP
:
case
Value
.
TIMESTAMP_TZ
:
if
(
DataType
.
isYearMonthIntervalType
(
rType
))
{
long
m
=
DateTimeUtils
.
intervalToAbsolute
((
ValueInterval
)
r
).
longValue
();
if
(
opType
==
IntervalOpType
.
DATETIME_MINUS_INTERVAL
)
{
m
=
-
m
;
}
return
DateTimeFunctions
.
dateadd
(
"MONTH"
,
m
,
l
);
}
else
{
BigInteger
a2
=
DateTimeUtils
.
intervalToAbsolute
((
ValueInterval
)
r
);
if
(
lType
==
Value
.
DATE
)
{
BigInteger
a1
=
BigInteger
.
valueOf
(
DateTimeUtils
.
absoluteDayFromDateValue
(((
ValueDate
)
l
).
getDateValue
()));
a2
=
a2
.
divide
(
BigInteger
.
valueOf
(
DateTimeUtils
.
NANOS_PER_DAY
));
BigInteger
n
=
opType
==
IntervalOpType
.
DATETIME_PLUS_INTERVAL
?
a1
.
add
(
a2
)
:
a1
.
subtract
(
a2
);
return
ValueDate
.
fromDateValue
(
DateTimeUtils
.
dateValueFromAbsoluteDay
(
n
.
longValue
()));
}
else
{
long
[]
a
=
DateTimeUtils
.
dateAndTimeFromValue
(
l
);
long
absoluteDay
=
DateTimeUtils
.
absoluteDayFromDateValue
(
a
[
0
]);
long
timeNanos
=
a
[
1
];
BigInteger
[]
dr
=
a2
.
divideAndRemainder
(
BigInteger
.
valueOf
(
DateTimeUtils
.
NANOS_PER_DAY
));
if
(
opType
==
IntervalOpType
.
DATETIME_PLUS_INTERVAL
)
{
absoluteDay
+=
dr
[
0
].
longValue
();
timeNanos
+=
dr
[
1
].
longValue
();
}
else
{
absoluteDay
-=
dr
[
0
].
longValue
();
timeNanos
-=
dr
[
1
].
longValue
();
}
if
(
timeNanos
>=
DateTimeUtils
.
NANOS_PER_DAY
)
{
timeNanos
-=
DateTimeUtils
.
NANOS_PER_DAY
;
absoluteDay
++;
}
else
if
(
timeNanos
<
0
)
{
timeNanos
+=
DateTimeUtils
.
NANOS_PER_DAY
;
absoluteDay
--;
}
return
DateTimeUtils
.
dateTimeToValue
(
l
,
DateTimeUtils
.
dateValueFromAbsoluteDay
(
absoluteDay
),
timeNanos
,
false
);
}
}
}
throw
DbException
.
throwInternalError
(
"type="
+
opType
);
}
@Override
public
void
mapColumns
(
ColumnResolver
resolver
,
int
level
)
{
left
.
mapColumns
(
resolver
,
level
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论