Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature][runtime] Add dateSubFun #43

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public final class OpKeys {
public static final BinaryOpKeys STRING_INT = new BinaryOpKeys(Types.STRING, Types.INT);
public static final BinaryOpKeys DECIMAL_INT = new BinaryOpKeys(Types.DECIMAL, Types.INT);
public static final BinaryOpKeys DATE_STRING = new BinaryOpKeys(Types.DATE, Types.STRING);
public static final BinaryOpKeys DATE_LONG = new BinaryOpKeys(Types.DATE, Types.LONG);
public static final BinaryOpKeys TIME_STRING = new BinaryOpKeys(Types.TIME, Types.STRING);
public static final BinaryOpKeys TIMESTAMP_STRING = new BinaryOpKeys(Types.TIMESTAMP, Types.STRING);
public static final TertiaryOpKeys STRING_INT_INT = new TertiaryOpKeys(Types.STRING, Types.INT, Types.INT);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright 2021 DataCanvas
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.dingodb.expr.runtime.op.time;

import io.dingodb.expr.annotations.Operators;
import io.dingodb.expr.runtime.ExprConfig;
import io.dingodb.expr.runtime.op.BinaryOp;
import io.dingodb.expr.runtime.op.OpKey;
import io.dingodb.expr.runtime.op.OpKeys;
import io.dingodb.expr.runtime.type.Type;
import io.dingodb.expr.runtime.type.Types;
import org.checkerframework.checker.nullness.qual.NonNull;

import java.sql.Date;

@Operators
public class DateSubFun extends BinaryOp {
public static final String NAME = "DATE_SUB";
private static final long serialVersionUID = 3693816042300916311L;

@Override
protected Date evalNonNullValue(@NonNull Object value0, @NonNull Object value1,
ExprConfig config) {
Date dateVal = (Date) value0;
Long val1 = (Long) value1;
long newDateLongVal = dateVal.getTime() - val1;
return new Date(newDateLongVal);
}

@Override
public final OpKey bestKeyOf(@NonNull Type @NonNull [] types) {
return OpKeys.DATE_LONG.bestKeyOf(types);
}

@Override
public @NonNull String getName() {
return NAME;
}

@Override
public Type getType() {
return Types.DATE;
}

@Override
public OpKey getKey() {
return keyOf(Types.DATE, Types.LONG);
}
}
Loading