Skip to content

Commit 9cd342b

Browse files
wt0530githubgxll
authored andcommitted
[fix][runtime] Fix construct intervals using table fields
1 parent d2d318e commit 9cd342b

File tree

4 files changed

+87
-35
lines changed

4 files changed

+87
-35
lines changed

runtime/src/main/java/io/dingodb/expr/runtime/expr/Exprs.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ public final class Exprs {
203203
io.dingodb.expr.runtime.op.interval.SubOpFactory.INSTANCE;
204204
public static final io.dingodb.expr.runtime.op.interval.AddOpFactory INTERVAL_ADD =
205205
io.dingodb.expr.runtime.op.interval.AddOpFactory.INSTANCE;
206+
public static final io.dingodb.expr.runtime.op.interval.MulOpFactory INTERVAL_MUL =
207+
io.dingodb.expr.runtime.op.interval.MulOpFactory.INSTANCE;
206208

207209
// Relations
208210
public static final EqOpFactory EQ = EqOpFactory.INSTANCE;

runtime/src/main/java/io/dingodb/expr/runtime/op/BinaryIntervalOp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public static IntervalType buildInterval(BigDecimal value0, IntervalType value1)
4444
return new IntervalYearType.IntervalYear(value0.multiply(new BigDecimal(12)),
4545
((IntervalYearType.IntervalYear) value1).elementType);
4646
} else if (value1 instanceof IntervalMonthType.IntervalMonth) {
47-
return new IntervalMonthType.IntervalMonth(value0, null);
47+
return new IntervalMonthType.IntervalMonth(value0, ((IntervalMonthType.IntervalMonth) value1).elementType);
4848
} else if (value1 instanceof IntervalDayType.IntervalDay) {
4949
return new IntervalDayType.IntervalDay(value0.multiply(new BigDecimal(24 * 60 * 60 * 1000)),
5050
((IntervalDayType.IntervalDay) value1).elementType

runtime/src/main/java/io/dingodb/expr/runtime/op/interval/AddOp.java

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -64,40 +64,6 @@ static Date add(Date value0, IntervalYearType.IntervalYear value1, ExprConfig co
6464
return (Date) processor.getTierProcessor().convertOutput(dateTime, DateTimeType.DATE);
6565
}
6666

67-
static IntervalType add(Integer value0, IntervalType value1) {
68-
BigDecimal decimal = new BigDecimal(Math.round(CastWithString.doubleCastWithStringCompat(value0.toString())));
69-
return buildInterval(decimal, value1);
70-
}
71-
72-
static IntervalType add(Long value0, IntervalType value1) {
73-
BigDecimal decimal = new BigDecimal(Math.round(CastWithString.doubleCastWithStringCompat(value0.toString())));
74-
return buildInterval(decimal, value1);
75-
}
76-
77-
static IntervalType add(Double value0, IntervalType value1) {
78-
BigDecimal decimal = new BigDecimal(Math.round(CastWithString.doubleCastWithStringCompat(value0.toString())));
79-
return buildInterval(decimal, value1);
80-
}
81-
82-
static IntervalType add(Float value0, IntervalType value1) {
83-
BigDecimal decimal = new BigDecimal(Math.round(CastWithString.doubleCastWithStringCompat(value0.toString())));
84-
return buildInterval(decimal, value1);
85-
}
86-
87-
static IntervalType add(Boolean value0, IntervalType value1) {
88-
BigDecimal decimal = new BigDecimal(value0 ? 1 : 0);
89-
return buildInterval(decimal, value1);
90-
}
91-
92-
static IntervalType add(BigDecimal value0, IntervalType value1) {
93-
BigDecimal decimal = new BigDecimal(Math.round(CastWithString.doubleCastWithStringCompat(value0.toString())));
94-
return buildInterval(decimal, value1);
95-
}
96-
97-
static IntervalType add(Void value0, IntervalType value1) {
98-
return null;
99-
}
100-
10167
static Date add(Date value0, IntervalMonthType.IntervalMonth value1, ExprConfig config) {
10268
DingoTimeZoneProcessor processor = config.getProcessor();
10369
DingoDateTime input = processor.getTierProcessor().convertInput(value0, DateTimeType.DATE);
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright 2021 DataCanvas
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.dingodb.expr.runtime.op.interval;
18+
19+
import io.dingodb.expr.annotations.Operators;
20+
import io.dingodb.expr.common.type.IntervalType;
21+
import io.dingodb.expr.common.utils.CastWithString;
22+
import io.dingodb.expr.runtime.op.BinaryIntervalOp;
23+
24+
import java.math.BigDecimal;
25+
import java.sql.Date;
26+
import java.sql.Time;
27+
import java.sql.Timestamp;
28+
29+
@Operators
30+
public class MulOp extends BinaryIntervalOp {
31+
32+
private static final long serialVersionUID = -1357285098612662070L;
33+
34+
static IntervalType mul(String value0, IntervalType value1) {
35+
BigDecimal decimal = new BigDecimal(CastWithString.longCastWithStringCompat(value0.split("\\.")[0]));
36+
return buildInterval(decimal, value1);
37+
}
38+
39+
static IntervalType mul(Integer value0, IntervalType value1) {
40+
BigDecimal decimal = new BigDecimal(Math.round(CastWithString.doubleCastWithStringCompat(value0.toString())));
41+
return buildInterval(decimal, value1);
42+
}
43+
44+
static IntervalType mul(Long value0, IntervalType value1) {
45+
BigDecimal decimal = new BigDecimal(Math.round(CastWithString.doubleCastWithStringCompat(value0.toString())));
46+
return buildInterval(decimal, value1);
47+
}
48+
49+
static IntervalType mul(Double value0, IntervalType value1) {
50+
BigDecimal decimal = new BigDecimal(Math.round(CastWithString.doubleCastWithStringCompat(value0.toString())));
51+
return buildInterval(decimal, value1);
52+
}
53+
54+
static IntervalType mul(Float value0, IntervalType value1) {
55+
BigDecimal decimal = new BigDecimal(Math.round(CastWithString.doubleCastWithStringCompat(value0.toString())));
56+
return buildInterval(decimal, value1);
57+
}
58+
59+
static IntervalType mul(Boolean value0, IntervalType value1) {
60+
BigDecimal decimal = new BigDecimal(value0 ? 1 : 0);
61+
return buildInterval(decimal, value1);
62+
}
63+
64+
static IntervalType mul(BigDecimal value0, IntervalType value1) {
65+
BigDecimal decimal = new BigDecimal(Math.round(CastWithString.doubleCastWithStringCompat(value0.toString())));
66+
return buildInterval(decimal, value1);
67+
}
68+
69+
static IntervalType mul(Date value0, IntervalType value1) {
70+
return null;
71+
}
72+
73+
static IntervalType mul(Time value0, IntervalType value1) {
74+
return null;
75+
}
76+
77+
static IntervalType mul(Timestamp value0, IntervalType value1) {
78+
return null;
79+
}
80+
81+
static IntervalType mul(Void value0, IntervalType value1) {
82+
return null;
83+
}
84+
}

0 commit comments

Comments
 (0)