[Feature](Nereids) add executable function to support fold constant for functions (#18209)

1. Add date-time functions for fold constant for Nereids.
This is the list of executable date-time function nereids supports up to now:
- now()
- now(int)
- current_timestamp()
- current_timestamp(int)
- localtime()
- localtimestamp()
- curdate()
- current_date()
- curtime()
- current_time()
- date_{add/sub}(),{years/months/days/hours/minutes/seconds}_{add/sub}()
- datediff()
- {date/datev2}()
- {year/quarter/month/day/hour/minute/second}()
- dayof{year/month/week}()
- date_format()
- date_trunc()
- from_days()
- last_day()
- to_monday()
- from_unixtime()
- unix_timestamp()
- utc_timestamp()
- to_date()
- to_days()
- str_to_date()
- makedate()

2. solved problem:
- enable datev2/datetimev2 default.
- refactor Nereids foldConstantOnFE and support fold nested expression.
- separate the executable into multi-files for easily-reading and adding new functions
This commit is contained in:
mch_ucchi
2023-05-17 21:26:31 +08:00
committed by GitHub
parent 1eb929e1ca
commit 1d05feea1b
45 changed files with 6146 additions and 818 deletions

View File

@ -217,11 +217,15 @@ std::string SchemaColumnsScanner::_type_to_string(TColumnDesc& desc) {
return fmt::to_string(debug_string_buffer);
}
case TPrimitiveType::DATEV2:
return "datev2";
return "date";
case TPrimitiveType::DATETIMEV2: {
fmt::memory_buffer debug_string_buffer;
fmt::format_to(debug_string_buffer, "datetimev2({})",
desc.__isset.columnScale ? std::to_string(desc.columnScale) : "UNKNOWN");
if (!desc.__isset.columnScale || desc.columnScale == 0) {
fmt::format_to(debug_string_buffer, "datetime");
} else {
fmt::format_to(debug_string_buffer, "datetime({})",
desc.__isset.columnScale ? std::to_string(desc.columnScale) : "UNKNOWN");
}
return fmt::to_string(debug_string_buffer);
}
case TPrimitiveType::HLL: {

View File

@ -1505,8 +1505,8 @@ public class Config extends ConfigBase {
/**
* If set to TRUE, FE will convert date/datetime to datev2/datetimev2(0) automatically.
*/
@ConfField(mutable = true, masterOnly = true)
public static boolean enable_date_conversion = false;
@ConfField(mutable = true)
public static boolean enable_date_conversion = true;
@ConfField(mutable = false, masterOnly = true)
public static boolean enable_multi_tags = false;

View File

@ -686,8 +686,6 @@ public class AnalyticExpr extends Expr {
Preconditions.checkState(getFnCall().getChildren().size() == 3);
}
Type type = getFnCall().getChildren().get(2).getType();
try {
if (!Type.matchExactType(getFnCall().getChildren().get(0).getType(),
getFnCall().getChildren().get(2).getType())) {
@ -700,10 +698,10 @@ public class AnalyticExpr extends Expr {
+ getFnCall().getChildren().get(0).getType());
}
if (getFnCall().getChildren().get(2) instanceof CastExpr) {
throw new AnalysisException("Type = " + type + " can't not convert to "
+ getFnCall().getChildren().get(0).getType());
}
// if (getFnCall().getChildren().get(2) instanceof CastExpr) {
// throw new AnalysisException("Type = " + type + " can't not convert to "
// + getFnCall().getChildren().get(0).getType());
// }
// check the value whether out of range
checkDefaultValue(analyzer);

View File

@ -1349,6 +1349,7 @@ public class FunctionCallExpr extends Expr {
uncheckedCastChild(assignmentCompatibleType, 2);
}
}
childTypes[0] = Type.BOOLEAN;
childTypes[1] = assignmentCompatibleType;
childTypes[2] = assignmentCompatibleType;
fn = getBuiltinFunction(fnName.getFunction(), childTypes,

View File

@ -24,7 +24,6 @@ import org.apache.doris.catalog.PrimitiveType;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.thrift.TExprNode;
@ -146,10 +145,6 @@ public class TimestampArithmeticExpr extends Expr {
if (t1 == PrimitiveType.DATEV2) {
return Type.DATEV2;
}
if (Config.enable_date_conversion
&& PrimitiveType.isImplicitCast(t1, PrimitiveType.DATETIMEV2)) {
return Type.DATETIMEV2;
}
if (PrimitiveType.isImplicitCast(t1, PrimitiveType.DATETIME)) {
return Type.DATETIME;
}

View File

@ -51,6 +51,7 @@ import org.apache.doris.nereids.trees.expressions.functions.scalar.CurrentCatalo
import org.apache.doris.nereids.trees.expressions.functions.scalar.CurrentUser;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Database;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Date;
import org.apache.doris.nereids.trees.expressions.functions.scalar.If;
import org.apache.doris.nereids.trees.expressions.functions.scalar.User;
import org.apache.doris.nereids.trees.expressions.functions.scalar.Version;
import org.apache.doris.nereids.trees.expressions.literal.ArrayLiteral;
@ -69,11 +70,12 @@ import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.util.ExpressionUtils;
import org.apache.doris.qe.GlobalVariable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
/**
* evaluate an expression on fe.
@ -89,24 +91,12 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
} else if (expr instanceof AggregateExpression && ((AggregateExpression) expr).getFunction().isDistinct()) {
return expr;
}
expr = rewriteChildren(expr, ctx);
if (expr instanceof PropagateNullable
&& !(expr instanceof NullableAggregateFunction)
&& argsHasNullLiteral(expr)) {
return new NullLiteral(expr.getDataType());
}
return expr.accept(this, ctx);
}
/**
* process constant expression.
*/
@Override
public Expression visit(Expression expr, ExpressionRewriteContext ctx) {
return expr;
}
@Override
public Expression visitSlot(Slot slot, ExpressionRewriteContext context) {
return slot;
@ -119,24 +109,30 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
@Override
public Expression visitEqualTo(EqualTo equalTo, ExpressionRewriteContext context) {
if (!allArgsIsAllLiteral(equalTo)) {
return equalTo;
equalTo = rewriteChildren(equalTo, context);
Optional<Expression> checkedExpr = preProcess(equalTo);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
return BooleanLiteral.of(((Literal) equalTo.left()).compareTo((Literal) equalTo.right()) == 0);
}
@Override
public Expression visitGreaterThan(GreaterThan greaterThan, ExpressionRewriteContext context) {
if (!allArgsIsAllLiteral(greaterThan)) {
return greaterThan;
greaterThan = rewriteChildren(greaterThan, context);
Optional<Expression> checkedExpr = preProcess(greaterThan);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
return BooleanLiteral.of(((Literal) greaterThan.left()).compareTo((Literal) greaterThan.right()) > 0);
}
@Override
public Expression visitGreaterThanEqual(GreaterThanEqual greaterThanEqual, ExpressionRewriteContext context) {
if (!allArgsIsAllLiteral(greaterThanEqual)) {
return greaterThanEqual;
greaterThanEqual = rewriteChildren(greaterThanEqual, context);
Optional<Expression> checkedExpr = preProcess(greaterThanEqual);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
return BooleanLiteral.of(((Literal) greaterThanEqual.left())
.compareTo((Literal) greaterThanEqual.right()) >= 0);
@ -144,24 +140,30 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
@Override
public Expression visitLessThan(LessThan lessThan, ExpressionRewriteContext context) {
if (!allArgsIsAllLiteral(lessThan)) {
return lessThan;
lessThan = rewriteChildren(lessThan, context);
Optional<Expression> checkedExpr = preProcess(lessThan);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
return BooleanLiteral.of(((Literal) lessThan.left()).compareTo((Literal) lessThan.right()) < 0);
}
@Override
public Expression visitLessThanEqual(LessThanEqual lessThanEqual, ExpressionRewriteContext context) {
if (!allArgsIsAllLiteral(lessThanEqual)) {
return lessThanEqual;
lessThanEqual = rewriteChildren(lessThanEqual, context);
Optional<Expression> checkedExpr = preProcess(lessThanEqual);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
return BooleanLiteral.of(((Literal) lessThanEqual.left()).compareTo((Literal) lessThanEqual.right()) <= 0);
}
@Override
public Expression visitNullSafeEqual(NullSafeEqual nullSafeEqual, ExpressionRewriteContext context) {
if (!allArgsIsAllLiteral(nullSafeEqual)) {
return nullSafeEqual;
nullSafeEqual = rewriteChildren(nullSafeEqual, context);
Optional<Expression> checkedExpr = preProcess(nullSafeEqual);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
Literal l = (Literal) nullSafeEqual.left();
Literal r = (Literal) nullSafeEqual.right();
@ -176,8 +178,10 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
@Override
public Expression visitNot(Not not, ExpressionRewriteContext context) {
if (!allArgsIsAllLiteral(not)) {
return not;
not = rewriteChildren(not, context);
Optional<Expression> checkedExpr = preProcess(not);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
return BooleanLiteral.of(!((BooleanLiteral) not.child()).getValue());
}
@ -213,22 +217,20 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
@Override
public Expression visitAnd(And and, ExpressionRewriteContext context) {
if (and.getArguments().stream().anyMatch(BooleanLiteral.FALSE::equals)) {
return BooleanLiteral.FALSE;
List<Expression> nonTrueLiteral = Lists.newArrayList();
for (Expression e : and.children()) {
e = e.accept(this, context);
if (BooleanLiteral.FALSE.equals(e)) {
return BooleanLiteral.FALSE;
} else if (e instanceof NullLiteral) {
return e;
} else if (!BooleanLiteral.TRUE.equals(e)) {
nonTrueLiteral.add(e);
}
}
if (argsHasNullLiteral(and)) {
return new NullLiteral(BooleanType.INSTANCE);
}
List<Expression> nonTrueLiteral = and.children()
.stream()
.filter(conjunct -> !BooleanLiteral.TRUE.equals(conjunct))
.collect(ImmutableList.toImmutableList());
if (nonTrueLiteral.isEmpty()) {
return BooleanLiteral.TRUE;
}
if (nonTrueLiteral.size() == and.arity()) {
return and;
}
if (nonTrueLiteral.size() == 1) {
return nonTrueLiteral.get(0);
}
@ -237,22 +239,20 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
@Override
public Expression visitOr(Or or, ExpressionRewriteContext context) {
if (or.getArguments().stream().anyMatch(BooleanLiteral.TRUE::equals)) {
return BooleanLiteral.TRUE;
List<Expression> nonFalseLiteral = Lists.newArrayList();
for (Expression e : or.children()) {
e = e.accept(this, context);
if (BooleanLiteral.TRUE.equals(e)) {
return BooleanLiteral.TRUE;
} else if (e instanceof NullLiteral) {
return e;
} else if (!BooleanLiteral.FALSE.equals(e)) {
nonFalseLiteral.add(e);
}
}
if (ExpressionUtils.isAllNullLiteral(or.getArguments())) {
return new NullLiteral(BooleanType.INSTANCE);
}
List<Expression> nonFalseLiteral = or.children()
.stream()
.filter(conjunct -> !BooleanLiteral.FALSE.equals(conjunct))
.collect(ImmutableList.toImmutableList());
if (nonFalseLiteral.isEmpty()) {
return BooleanLiteral.FALSE;
}
if (nonFalseLiteral.size() == or.arity()) {
return or;
}
if (nonFalseLiteral.size() == 1) {
return nonFalseLiteral.get(0);
}
@ -266,8 +266,10 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
@Override
public Expression visitCast(Cast cast, ExpressionRewriteContext context) {
if (!allArgsIsAllLiteral(cast)) {
return cast;
cast = rewriteChildren(cast, context);
Optional<Expression> checkedExpr = preProcess(cast);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
Expression child = cast.child();
// todo: process other null case
@ -287,23 +289,31 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
@Override
public Expression visitBoundFunction(BoundFunction boundFunction, ExpressionRewriteContext context) {
boundFunction = rewriteChildren(boundFunction, context);
//functions, like current_date, do not have arg
if (boundFunction.getArguments().isEmpty()) {
return boundFunction;
}
if (!ExpressionUtils.isAllLiteral(boundFunction.getArguments())) {
return boundFunction;
Optional<Expression> checkedExpr = preProcess(boundFunction);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
return ExpressionEvaluator.INSTANCE.eval(boundFunction);
}
@Override
public Expression visitBinaryArithmetic(BinaryArithmetic binaryArithmetic, ExpressionRewriteContext context) {
binaryArithmetic = rewriteChildren(binaryArithmetic, context);
Optional<Expression> checkedExpr = preProcess(binaryArithmetic);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
return ExpressionEvaluator.INSTANCE.eval(binaryArithmetic);
}
@Override
public Expression visitCaseWhen(CaseWhen caseWhen, ExpressionRewriteContext context) {
caseWhen = rewriteChildren(caseWhen, context);
Expression newDefault = null;
boolean foundNewDefault = false;
@ -335,50 +345,68 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
return new CaseWhen(whenClauses, defaultResult);
}
@Override
public Expression visitIf(If ifExpr, ExpressionRewriteContext context) {
ifExpr = rewriteChildren(ifExpr, context);
if (ifExpr.child(0) instanceof NullLiteral || ifExpr.child(0).equals(BooleanLiteral.FALSE)) {
return ifExpr.child(2);
} else if (ifExpr.child(0).equals(BooleanLiteral.TRUE)) {
return ifExpr.child(1);
}
return ifExpr;
}
@Override
public Expression visitInPredicate(InPredicate inPredicate, ExpressionRewriteContext context) {
inPredicate = rewriteChildren(inPredicate, context);
Optional<Expression> checkedExpr = preProcess(inPredicate);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
// now the inPredicate contains literal only.
Expression value = inPredicate.child(0);
if (value.isNullLiteral()) {
return new NullLiteral(BooleanType.INSTANCE);
}
boolean valueIsLiteral = value.isLiteral();
if (!valueIsLiteral) {
return inPredicate;
}
boolean hasNull = false;
boolean isOptionContainsNull = false;
for (Expression item : inPredicate.getOptions()) {
if (item.isNullLiteral()) {
hasNull = true;
}
if (valueIsLiteral && value.equals(item)) {
if (value.equals(item)) {
return BooleanLiteral.TRUE;
} else if (item.isNullLiteral()) {
isOptionContainsNull = true;
}
}
if (hasNull) {
return NullLiteral.INSTANCE;
}
return BooleanLiteral.FALSE;
return isOptionContainsNull
? new NullLiteral(BooleanType.INSTANCE)
: BooleanLiteral.FALSE;
}
@Override
public Expression visitIsNull(IsNull isNull, ExpressionRewriteContext context) {
if (!allArgsIsAllLiteral(isNull)) {
return isNull;
isNull = rewriteChildren(isNull, context);
Optional<Expression> checkedExpr = preProcess(isNull);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
return Literal.of(isNull.child().nullable());
}
@Override
public Expression visitTimestampArithmetic(TimestampArithmetic arithmetic, ExpressionRewriteContext context) {
arithmetic = rewriteChildren(arithmetic, context);
Optional<Expression> checkedExpr = preProcess(arithmetic);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
return ExpressionEvaluator.INSTANCE.eval(arithmetic);
}
@Override
public Expression visitArray(Array array, ExpressionRewriteContext context) {
if (!allArgsIsAllLiteral(array)) {
return array;
array = rewriteChildren(array, context);
Optional<Expression> checkedExpr = preProcess(array);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
List<Literal> arguments = (List) array.getArguments();
return new ArrayLiteral(arguments);
@ -386,8 +414,10 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
@Override
public Expression visitDate(Date date, ExpressionRewriteContext context) {
if (!allArgsIsAllLiteral(date)) {
return date;
date = rewriteChildren(date, context);
Optional<Expression> checkedExpr = preProcess(date);
if (checkedExpr.isPresent()) {
return checkedExpr.get();
}
Literal child = (Literal) date.child();
if (child instanceof NullLiteral) {
@ -409,17 +439,8 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
return new StringLiteral(GlobalVariable.version);
}
private Expression rewriteChildren(Expression expr, ExpressionRewriteContext ctx) {
List<Expression> newChildren = new ArrayList<>();
boolean hasNewChildren = false;
for (Expression child : expr.children()) {
Expression newChild = rewrite(child, ctx);
if (newChild != child) {
hasNewChildren = true;
}
newChildren.add(newChild);
}
return hasNewChildren ? expr.withChildren(newChildren) : expr;
private <E> E rewriteChildren(Expression expr, ExpressionRewriteContext ctx) {
return (E) super.visit(expr, ctx);
}
private boolean allArgsIsAllLiteral(Expression expression) {
@ -429,5 +450,16 @@ public class FoldConstantRuleOnFE extends AbstractExpressionRewriteRule {
private boolean argsHasNullLiteral(Expression expression) {
return ExpressionUtils.hasNullLiteral(expression.getArguments());
}
private Optional<Expression> preProcess(Expression expression) {
if (expression instanceof PropagateNullable && !(expression instanceof NullableAggregateFunction)
&& argsHasNullLiteral(expression)) {
return Optional.of(new NullLiteral(expression.getDataType()));
}
if (!allArgsIsAllLiteral(expression)) {
return Optional.of(expression);
}
return Optional.empty();
}
}

View File

@ -22,6 +22,7 @@ import org.apache.doris.nereids.rules.expression.ExpressionRewriteContext;
import org.apache.doris.nereids.trees.expressions.EqualTo;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.InPredicate;
import org.apache.doris.nereids.trees.expressions.literal.BooleanLiteral;
import org.apache.doris.nereids.util.ExpressionUtils;
import com.google.common.base.Preconditions;
@ -52,13 +53,17 @@ public class InPredicateToEqualToRule extends AbstractExpressionRewriteRule {
Expression cmpExpr = inPredicate.getCompareExpr();
List<Expression> options = inPredicate.getOptions();
Preconditions.checkArgument(options.size() > 0, "InPredicate.options should not be empty");
if (options.size() > 2) {
if (options.size() > 2 || isOptionContainNullLiteral(options)) {
return new InPredicate(cmpExpr.accept(this, context), options);
}
Expression newCmpExpr = cmpExpr.accept(this, context);
List<Expression> disjunction = options.stream()
.map(option -> new EqualTo(newCmpExpr, option.accept(this, context)))
.collect(Collectors.toList());
return ExpressionUtils.or(disjunction);
return disjunction.isEmpty() ? BooleanLiteral.FALSE : ExpressionUtils.or(disjunction);
}
private boolean isOptionContainNullLiteral(List<Expression> options) {
return options.stream().anyMatch(Expression::isNullLiteral);
}
}

View File

@ -174,7 +174,7 @@ public class SimplifyComparisonPredicate extends AbstractExpressionRewriteRule {
private Expression migrateToDateV2(DateTimeLiteral l, AdjustType type) {
DateV2Literal d = new DateV2Literal(l.getYear(), l.getMonth(), l.getDay());
if (type == AdjustType.UPPER && (l.getHour() != 0 || l.getMinute() != 0 || l.getSecond() != 0)) {
d = d.plusDays(1);
d = ((DateV2Literal) d.plusDays(1));
}
return d;
}

View File

@ -19,13 +19,21 @@ package org.apache.doris.nereids.trees.expressions;
import org.apache.doris.catalog.Env;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.nereids.trees.expressions.functions.ExecutableFunctions;
import org.apache.doris.nereids.trees.expressions.functions.BoundFunction;
import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait;
import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeAcquire;
import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeArithmetic;
import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeExtractAndTransform;
import org.apache.doris.nereids.trees.expressions.functions.executable.ExecutableFunctions;
import org.apache.doris.nereids.trees.expressions.functions.executable.NumericArithmetic;
import org.apache.doris.nereids.trees.expressions.literal.DateLiteral;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.DecimalV3Type;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;
import java.lang.reflect.InvocationTargetException;
@ -65,6 +73,10 @@ public enum ExpressionEvaluator {
TimestampArithmetic arithmetic = (TimestampArithmetic) expression;
fnName = arithmetic.getFuncName();
args = new DataType[]{arithmetic.left().getDataType(), arithmetic.right().getDataType()};
} else if (expression instanceof BoundFunction) {
BoundFunction function = ((BoundFunction) expression);
fnName = function.getName();
args = function.children().stream().map(ExpressionTrait::getDataType).toArray(DataType[]::new);
}
if ((Env.getCurrentEnv().isNullResultWithOneNullParamFunction(fnName))) {
@ -123,15 +135,24 @@ public enum ExpressionEvaluator {
}
ImmutableMultimap.Builder<String, FunctionInvoker> mapBuilder =
new ImmutableMultimap.Builder<String, FunctionInvoker>();
Class clazz = ExecutableFunctions.class;
for (Method method : clazz.getDeclaredMethods()) {
ExecFunctionList annotationList = method.getAnnotation(ExecFunctionList.class);
if (annotationList != null) {
for (ExecFunction f : annotationList.value()) {
registerFEFunction(mapBuilder, method, f);
List<Class> classes = ImmutableList.of(
DateTimeExtractAndTransform.class,
ExecutableFunctions.class,
DateLiteral.class,
DateTimeArithmetic.class,
DateTimeAcquire.class,
NumericArithmetic.class
);
for (Class cls : classes) {
for (Method method : cls.getDeclaredMethods()) {
ExecFunctionList annotationList = method.getAnnotation(ExecFunctionList.class);
if (annotationList != null) {
for (ExecFunction f : annotationList.value()) {
registerFEFunction(mapBuilder, method, f);
}
}
registerFEFunction(mapBuilder, method, method.getAnnotation(ExecFunction.class));
}
registerFEFunction(mapBuilder, method, method.getAnnotation(ExecFunction.class));
}
this.functions = mapBuilder.build();
}

View File

@ -0,0 +1,100 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 org.apache.doris.nereids.trees.expressions.functions.executable;
import org.apache.doris.nereids.trees.expressions.ExecFunction;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.literal.DateLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeV2Literal;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import java.time.LocalDateTime;
import java.util.TimeZone;
/**
* executable functions:
* unclassified date function
*/
public class DateTimeAcquire {
/**
* date acquire function: now
*/
@ExecFunction(name = "now", argTypes = {}, returnType = "DATETIME")
public static Expression now() {
return DateTimeLiteral.fromJavaDateType(LocalDateTime.now());
}
@ExecFunction(name = "now", argTypes = {"INT"}, returnType = "DATETIMEV2")
public static Expression now(IntegerLiteral precision) {
return DateTimeV2Literal.fromJavaDateType(LocalDateTime.now(),
precision.getValue());
}
/**
* date acquire function: current_timestamp
*/
@ExecFunction(name = "current_timestamp", argTypes = {}, returnType = "DATETIME")
public static Expression currentTimestamp() {
return DateTimeLiteral.fromJavaDateType(LocalDateTime.now());
}
@ExecFunction(name = "current_timestamp", argTypes = {"INT"}, returnType = "DATETIMEV2")
public static Expression currentTimestamp(IntegerLiteral precision) {
return DateTimeV2Literal.fromJavaDateType(LocalDateTime.now(), precision.getValue());
}
/**
* date acquire function: localtime/localtimestamp
*/
@ExecFunction(name = "localtime", argTypes = {}, returnType = "DATETIME")
public static Expression localTime() {
return DateTimeLiteral.fromJavaDateType(LocalDateTime.now(TimeZone.getDefault().toZoneId()));
}
@ExecFunction(name = "localtimestamp", argTypes = {}, returnType = "DATETIME")
public static Expression localTimestamp() {
return DateTimeV2Literal.fromJavaDateType(LocalDateTime.now(TimeZone.getDefault().toZoneId()));
}
/**
* date acquire function: current_date
*/
@ExecFunction(name = "curdate", argTypes = {}, returnType = "DATE")
public static Expression curDate() {
return DateLiteral.fromJavaDateType(LocalDateTime.now());
}
@ExecFunction(name = "current_date", argTypes = {}, returnType = "DATE")
public static Expression currentDate() {
return DateLiteral.fromJavaDateType(LocalDateTime.now());
}
/**
* date acquire function: current_time
*/
@ExecFunction(name = "curtime", argTypes = {}, returnType = "DATETIME")
public static Expression curTime() {
return DateTimeLiteral.fromJavaDateType(LocalDateTime.now());
}
@ExecFunction(name = "current_time", argTypes = {}, returnType = "DATETIME")
public static Expression currentTime() {
return DateTimeLiteral.fromJavaDateType(LocalDateTime.now());
}
}

View File

@ -0,0 +1,337 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 org.apache.doris.nereids.trees.expressions.functions.executable;
import org.apache.doris.nereids.trees.expressions.ExecFunction;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.literal.DateLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeV2Literal;
import org.apache.doris.nereids.trees.expressions.literal.DateV2Literal;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
/**
* executable function:
* date_add/sub, years/months/days/hours/minutes/seconds_add/sub, datediff
*/
public class DateTimeArithmetic {
/**
* datetime arithmetic function date-add.
*/
@ExecFunction(name = "date_add", argTypes = {"DATE", "INT"}, returnType = "DATE")
public static Expression dateAdd(DateLiteral date, IntegerLiteral day) {
return daysAdd(date, day);
}
@ExecFunction(name = "date_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression dateAdd(DateTimeLiteral date, IntegerLiteral day) {
return daysAdd(date, day);
}
@ExecFunction(name = "date_add", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2")
public static Expression dateAdd(DateV2Literal date, IntegerLiteral day) {
return daysAdd(date, day);
}
@ExecFunction(name = "date_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression dateAdd(DateTimeV2Literal date, IntegerLiteral day) {
return daysAdd(date, day);
}
/**
* datetime arithmetic function date-sub.
*/
@ExecFunction(name = "date_sub", argTypes = {"DATE", "INT"}, returnType = "DATE")
public static Expression dateSub(DateLiteral date, IntegerLiteral day) {
return dateAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "date_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression dateSub(DateTimeLiteral date, IntegerLiteral day) {
return dateAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "date_sub", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2")
public static Expression dateSub(DateV2Literal date, IntegerLiteral day) {
return dateAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "date_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression dateSub(DateTimeV2Literal date, IntegerLiteral day) {
return dateAdd(date, new IntegerLiteral(-day.getValue()));
}
/**
* datetime arithmetic function years-add.
*/
@ExecFunction(name = "years_add", argTypes = {"DATE", "INT"}, returnType = "DATE")
public static Expression yearsAdd(DateLiteral date, IntegerLiteral year) {
return date.plusYears(year.getValue());
}
@ExecFunction(name = "years_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression yearsAdd(DateTimeLiteral date, IntegerLiteral year) {
return date.plusYears(year.getValue());
}
@ExecFunction(name = "years_add", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2")
public static Expression yearsAdd(DateV2Literal date, IntegerLiteral year) {
return date.plusYears(year.getValue());
}
@ExecFunction(name = "years_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression yearsAdd(DateTimeV2Literal date, IntegerLiteral year) {
return date.plusYears(year.getValue());
}
/**
* datetime arithmetic function months-add.
*/
@ExecFunction(name = "months_add", argTypes = {"DATE", "INT"}, returnType = "DATE")
public static Expression monthsAdd(DateLiteral date, IntegerLiteral month) {
return date.plusMonths(month.getValue());
}
@ExecFunction(name = "months_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression monthsAdd(DateTimeLiteral date, IntegerLiteral month) {
return date.plusMonths(month.getValue());
}
@ExecFunction(name = "months_add", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2")
public static Expression monthsAdd(DateV2Literal date, IntegerLiteral month) {
return date.plusMonths(month.getValue());
}
@ExecFunction(name = "months_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression monthsAdd(DateTimeV2Literal date, IntegerLiteral month) {
return date.plusMonths(month.getValue());
}
/**
* datetime arithmetic function days-add.
*/
@ExecFunction(name = "days_add", argTypes = {"DATE", "INT"}, returnType = "DATE")
public static Expression daysAdd(DateLiteral date, IntegerLiteral day) {
return date.plusDays(day.getValue());
}
@ExecFunction(name = "days_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression daysAdd(DateTimeLiteral date, IntegerLiteral day) {
return date.plusDays(day.getValue());
}
@ExecFunction(name = "days_add", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2")
public static Expression daysAdd(DateV2Literal date, IntegerLiteral day) {
return date.plusDays(day.getValue());
}
@ExecFunction(name = "days_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression daysAdd(DateTimeV2Literal date, IntegerLiteral day) {
return date.plusDays(day.getValue());
}
/**
* datetime arithmetic function hours-add.
*/
@ExecFunction(name = "hours_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression hoursAdd(DateTimeLiteral date, IntegerLiteral hour) {
return date.plusHours(hour.getValue());
}
@ExecFunction(name = "hours_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression hoursAdd(DateTimeV2Literal date, IntegerLiteral hour) {
return date.plusHours(hour.getValue());
}
/**
* datetime arithmetic function minutes-add.
*/
@ExecFunction(name = "minutes_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression minutesAdd(DateTimeLiteral date, IntegerLiteral minute) {
return date.plusMinutes(minute.getValue());
}
@ExecFunction(name = "minutes_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression minutesAdd(DateTimeV2Literal date, IntegerLiteral minute) {
return date.plusMinutes(minute.getValue());
}
/**
* datetime arithmetic function seconds-add.
*/
@ExecFunction(name = "seconds_add", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression secondsAdd(DateTimeLiteral date, IntegerLiteral second) {
return date.plusSeconds(second.getValue());
}
@ExecFunction(name = "seconds_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression secondsAdd(DateTimeV2Literal date, IntegerLiteral second) {
return date.plusSeconds(second.getValue());
}
/**
* datetime arithmetic function microseconds-add.
*/
@ExecFunction(name = "microseconds_add", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression microSecondsAdd(DateTimeV2Literal date, IntegerLiteral microSecond) {
return date.plusMicroSeconds(microSecond.getValue());
}
/**
* datetime arithmetic function years-sub.
*/
@ExecFunction(name = "years_sub", argTypes = {"DATE", "INT"}, returnType = "DATE")
public static Expression yearsSub(DateLiteral date, IntegerLiteral year) {
return yearsAdd(date, new IntegerLiteral(-year.getValue()));
}
@ExecFunction(name = "years_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression yearsSub(DateTimeLiteral date, IntegerLiteral year) {
return yearsAdd(date, new IntegerLiteral(-year.getValue()));
}
@ExecFunction(name = "years_sub", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2")
public static Expression yearsSub(DateV2Literal date, IntegerLiteral year) {
return yearsAdd(date, new IntegerLiteral(-year.getValue()));
}
@ExecFunction(name = "years_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression yearsSub(DateTimeV2Literal date, IntegerLiteral year) {
return yearsAdd(date, new IntegerLiteral(-year.getValue()));
}
/**
* datetime arithmetic function months-sub
*/
@ExecFunction(name = "months_sub", argTypes = {"DATE", "INT"}, returnType = "DATE")
public static Expression monthsSub(DateLiteral date, IntegerLiteral month) {
return monthsAdd(date, new IntegerLiteral(-month.getValue()));
}
@ExecFunction(name = "months_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression monthsSub(DateTimeLiteral date, IntegerLiteral month) {
return monthsAdd(date, new IntegerLiteral(-month.getValue()));
}
@ExecFunction(name = "months_sub", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2")
public static Expression monthsSub(DateV2Literal date, IntegerLiteral month) {
return monthsAdd(date, new IntegerLiteral(-month.getValue()));
}
@ExecFunction(name = "months_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression monthsSub(DateTimeV2Literal date, IntegerLiteral month) {
return monthsAdd(date, new IntegerLiteral(-month.getValue()));
}
/**
* datetime arithmetic function days-sub
*/
@ExecFunction(name = "days_sub", argTypes = {"DATE", "INT"}, returnType = "DATE")
public static Expression daysSub(DateLiteral date, IntegerLiteral day) {
return daysAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "days_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression daysSub(DateTimeLiteral date, IntegerLiteral day) {
return daysAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "days_sub", argTypes = {"DATEV2", "INT"}, returnType = "DATEV2")
public static Expression daysSub(DateV2Literal date, IntegerLiteral day) {
return daysAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "days_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression daysSub(DateTimeV2Literal date, IntegerLiteral day) {
return daysAdd(date, new IntegerLiteral(-day.getValue()));
}
/**
* datetime arithmetic function hours-sub
*/
@ExecFunction(name = "hours_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression hoursSub(DateTimeLiteral date, IntegerLiteral hour) {
return hoursAdd(date, new IntegerLiteral(-hour.getValue()));
}
@ExecFunction(name = "hours_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression hoursSub(DateTimeV2Literal date, IntegerLiteral hour) {
return hoursAdd(date, new IntegerLiteral(-hour.getValue()));
}
/**
* datetime arithmetic function minutes-sub
*/
@ExecFunction(name = "minutes_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression minutesSub(DateTimeLiteral date, IntegerLiteral minute) {
return minutesAdd(date, new IntegerLiteral(-minute.getValue()));
}
@ExecFunction(name = "minutes_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression minutesSub(DateTimeV2Literal date, IntegerLiteral minute) {
return minutesAdd(date, new IntegerLiteral(-minute.getValue()));
}
/**
* datetime arithmetic function seconds-sub
*/
@ExecFunction(name = "seconds_sub", argTypes = {"DATETIME", "INT"}, returnType = "DATETIME")
public static Expression secondsSub(DateTimeLiteral date, IntegerLiteral second) {
return secondsAdd(date, new IntegerLiteral(-second.getValue()));
}
@ExecFunction(name = "seconds_sub", argTypes = {"DATETIMEV2", "INT"}, returnType = "DATETIMEV2")
public static Expression secondsSub(DateTimeV2Literal date, IntegerLiteral second) {
return secondsAdd(date, new IntegerLiteral(-second.getValue()));
}
/**
* datetime arithmetic function datediff
*/
@ExecFunction(name = "datediff", argTypes = {"DATETIME", "DATETIME"}, returnType = "INT")
public static Expression dateDiff(DateTimeLiteral date1, DateTimeLiteral date2) {
return new IntegerLiteral(dateDiff(date1.toJavaDateType(), date2.toJavaDateType()));
}
@ExecFunction(name = "datediff", argTypes = {"DATEV2", "DATEV2"}, returnType = "INT")
public static Expression dateDiff(DateV2Literal date1, DateV2Literal date2) {
return new IntegerLiteral(dateDiff(date1.toJavaDateType(), date2.toJavaDateType()));
}
@ExecFunction(name = "datediff", argTypes = {"DATEV2", "DATETIMEV2"}, returnType = "INT")
public static Expression dateDiff(DateV2Literal date1, DateTimeV2Literal date2) {
return new IntegerLiteral(dateDiff(date1.toJavaDateType(), date2.toJavaDateType()));
}
@ExecFunction(name = "datediff", argTypes = {"DATETIMEV2", "DATEV2"}, returnType = "INT")
public static Expression dateDiff(DateTimeV2Literal date1, DateV2Literal date2) {
return new IntegerLiteral(dateDiff(date1.toJavaDateType(), date2.toJavaDateType()));
}
@ExecFunction(name = "datediff", argTypes = {"DATETIMEV2", "DATETIMEV2"}, returnType = "INT")
public static Expression dateDiff(DateTimeV2Literal date1, DateTimeV2Literal date2) {
return new IntegerLiteral(dateDiff(date1.toJavaDateType(), date2.toJavaDateType()));
}
private static int dateDiff(LocalDateTime date1, LocalDateTime date2) {
return ((int) ChronoUnit.DAYS.between(date2.toLocalDate(), date1.toLocalDate()));
}
}

View File

@ -0,0 +1,583 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 org.apache.doris.nereids.trees.expressions.functions.executable;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.ExecFunction;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.literal.DateLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeV2Literal;
import org.apache.doris.nereids.trees.expressions.literal.DateV2Literal;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
import org.apache.doris.nereids.util.DateUtils;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
/**
* executable function:
* year, quarter, month, week, dayOfYear, dayOfweek, dayOfMonth, hour, minute, second
*/
public class DateTimeExtractAndTransform {
/**
* datetime arithmetic function date-v2
*/
@ExecFunction(name = "datev2", argTypes = {"DATETIMEV2"}, returnType = "DATEV2")
public static Expression dateV2(DateTimeV2Literal dateTime) {
return new DateV2Literal(dateTime.getYear(), dateTime.getMonth(), dateTime.getDay());
}
/**
* Executable datetime extract year
*/
@ExecFunction(name = "year", argTypes = {"DATE"}, returnType = "INT")
public static Expression year(DateLiteral date) {
return new IntegerLiteral(((int) date.getYear()));
}
@ExecFunction(name = "year", argTypes = {"DATETIME"}, returnType = "INT")
public static Expression year(DateTimeLiteral date) {
return new IntegerLiteral(((int) date.getYear()));
}
@ExecFunction(name = "year", argTypes = {"DATEV2"}, returnType = "INT")
public static Expression year(DateV2Literal date) {
return new IntegerLiteral(((int) date.getYear()));
}
@ExecFunction(name = "year", argTypes = {"DATETIMEV2"}, returnType = "INT")
public static Expression year(DateTimeV2Literal date) {
return new IntegerLiteral(((int) date.getYear()));
}
/**
* Executable datetime extract quarter
*/
@ExecFunction(name = "quarter", argTypes = {"DATE"}, returnType = "INT")
public static Expression quarter(DateLiteral date) {
return new IntegerLiteral(((int) date.getMonth() - 1) / 3 + 1);
}
@ExecFunction(name = "quarter", argTypes = {"DATETIME"}, returnType = "INT")
public static Expression quarter(DateTimeLiteral date) {
return new IntegerLiteral(((int) date.getMonth() - 1) / 3 + 1);
}
@ExecFunction(name = "quarter", argTypes = {"DATEV2"}, returnType = "INT")
public static Expression quarter(DateV2Literal date) {
return new IntegerLiteral(((int) date.getMonth() - 1) / 3 + 1);
}
@ExecFunction(name = "quarter", argTypes = {"DATETIMEV2"}, returnType = "INT")
public static Expression quarter(DateTimeV2Literal date) {
return new IntegerLiteral(((int) date.getMonth() - 1) / 3 + 1);
}
/**
* Executable datetime extract month
*/
@ExecFunction(name = "month", argTypes = {"DATE"}, returnType = "INT")
public static Expression month(DateLiteral date) {
return new IntegerLiteral(((int) date.getMonth()));
}
@ExecFunction(name = "month", argTypes = {"DATETIME"}, returnType = "INT")
public static Expression month(DateTimeLiteral date) {
return new IntegerLiteral(((int) date.getMonth()));
}
@ExecFunction(name = "month", argTypes = {"DATEV2"}, returnType = "INT")
public static Expression month(DateV2Literal date) {
return new IntegerLiteral(((int) date.getMonth()));
}
@ExecFunction(name = "month", argTypes = {"DATETIMEV2"}, returnType = "INT")
public static Expression month(DateTimeV2Literal date) {
return new IntegerLiteral(((int) date.getMonth()));
}
/**
* Executable datetime extract day
*/
@ExecFunction(name = "day", argTypes = {"DATE"}, returnType = "INT")
public static Expression day(DateLiteral date) {
return new IntegerLiteral(((int) date.getDay()));
}
@ExecFunction(name = "day", argTypes = {"DATETIME"}, returnType = "INT")
public static Expression day(DateTimeLiteral date) {
return new IntegerLiteral(((int) date.getDay()));
}
@ExecFunction(name = "day", argTypes = {"DATEV2"}, returnType = "INT")
public static Expression day(DateV2Literal date) {
return new IntegerLiteral(((int) date.getDay()));
}
@ExecFunction(name = "day", argTypes = {"DATETIMEV2"}, returnType = "INT")
public static Expression day(DateTimeV2Literal date) {
return new IntegerLiteral(((int) date.getDay()));
}
/**
* Executable datetime extract hour
*/
@ExecFunction(name = "hour", argTypes = {"DATETIME"}, returnType = "INT")
public static Expression hour(DateTimeLiteral date) {
return new IntegerLiteral(((int) date.getHour()));
}
@ExecFunction(name = "hour", argTypes = {"DATETIMEV2"}, returnType = "INT")
public static Expression hour(DateTimeV2Literal date) {
return new IntegerLiteral(((int) date.getHour()));
}
/**
* Executable datetime extract hour
*/
@ExecFunction(name = "minute", argTypes = {"DATETIME"}, returnType = "INT")
public static Expression minute(DateTimeLiteral date) {
return new IntegerLiteral(((int) date.getMinute()));
}
@ExecFunction(name = "minute", argTypes = {"DATETIMEV2"}, returnType = "INT")
public static Expression minute(DateTimeV2Literal date) {
return new IntegerLiteral(((int) date.getMinute()));
}
/**
* Executable datetime extract hour
*/
@ExecFunction(name = "second", argTypes = {"DATETIME"}, returnType = "INT")
public static Expression second(DateTimeLiteral date) {
return new IntegerLiteral(((int) date.getSecond()));
}
@ExecFunction(name = "second", argTypes = {"DATETIMEV2"}, returnType = "INT")
public static Expression second(DateTimeV2Literal date) {
return new IntegerLiteral(((int) date.getSecond()));
}
/**
* Executable datetime extract dayofyear
*/
@ExecFunction(name = "dayofyear", argTypes = {"DATE"}, returnType = "INT")
public static Expression dayOfYear(DateLiteral date) {
return new IntegerLiteral(date.toJavaDateType().getDayOfYear());
}
@ExecFunction(name = "dayofyear", argTypes = {"DATETIME"}, returnType = "INT")
public static Expression dayOfYear(DateTimeLiteral date) {
return new IntegerLiteral(date.toJavaDateType().getDayOfYear());
}
@ExecFunction(name = "dayofyear", argTypes = {"DATEV2"}, returnType = "INT")
public static Expression dayOfYear(DateV2Literal date) {
return new IntegerLiteral(date.toJavaDateType().getDayOfYear());
}
@ExecFunction(name = "dayofyear", argTypes = {"DATETIMEV2"}, returnType = "INT")
public static Expression dayOfYear(DateTimeV2Literal date) {
return new IntegerLiteral(date.toJavaDateType().getDayOfYear());
}
/**
* Executable datetime extract dayofmonth
*/
@ExecFunction(name = "dayofmonth", argTypes = {"DATE"}, returnType = "INT")
public static Expression dayOfMonth(DateLiteral date) {
return new IntegerLiteral(date.toJavaDateType().getDayOfMonth());
}
@ExecFunction(name = "dayofmonth", argTypes = {"DATETIME"}, returnType = "INT")
public static Expression dayOfMonth(DateTimeLiteral date) {
return new IntegerLiteral(date.toJavaDateType().getDayOfMonth());
}
@ExecFunction(name = "dayofmonth", argTypes = {"DATEV2"}, returnType = "INT")
public static Expression dayOfMonth(DateV2Literal date) {
return new IntegerLiteral(date.toJavaDateType().getDayOfMonth());
}
@ExecFunction(name = "dayofmonth", argTypes = {"DATETIMEV2"}, returnType = "INT")
public static Expression dayOfMonth(DateTimeV2Literal date) {
return new IntegerLiteral(date.toJavaDateType().getDayOfMonth());
}
/**
* Executable datetime extract dayofweek
*/
@ExecFunction(name = "dayofweek", argTypes = {"DATE"}, returnType = "INT")
public static Expression dayOfWeek(DateLiteral date) {
return new IntegerLiteral(date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1);
}
@ExecFunction(name = "dayofweek", argTypes = {"DATETIME"}, returnType = "INT")
public static Expression dayOfWeek(DateTimeLiteral date) {
return new IntegerLiteral(date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1);
}
@ExecFunction(name = "dayofweek", argTypes = {"DATEV2"}, returnType = "INT")
public static Expression dayOfWeek(DateV2Literal date) {
return new IntegerLiteral(date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1);
}
@ExecFunction(name = "dayofweek", argTypes = {"DATETIMEV2"}, returnType = "INT")
public static Expression dayOfWeek(DateTimeV2Literal date) {
return new IntegerLiteral(date.toJavaDateType().getDayOfWeek().getValue() % 7 + 1);
}
private static int distanceToFirstDayOfWeek(LocalDateTime dateTime) {
return dateTime.getDayOfWeek().getValue() - 1;
}
private static LocalDateTime firstDayOfWeek(LocalDateTime dateTime) {
return dateTime.plusDays(-distanceToFirstDayOfWeek(dateTime));
}
/**
* datetime arithmetic function date-format
*/
@ExecFunction(name = "date_format", argTypes = {"DATE", "VARCHAR"}, returnType = "VARCHAR")
public static Expression dateFormat(DateLiteral date, VarcharLiteral format) {
return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format(
java.time.LocalDate.of(((int) date.getYear()), ((int) date.getMonth()), ((int) date.getDay()))));
}
@ExecFunction(name = "date_format", argTypes = {"DATETIME", "VARCHAR"}, returnType = "VARCHAR")
public static Expression dateFormat(DateTimeLiteral date, VarcharLiteral format) {
return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format(
java.time.LocalDateTime.of(((int) date.getYear()), ((int) date.getMonth()), ((int) date.getDay()),
((int) date.getHour()), ((int) date.getMinute()), ((int) date.getSecond()))));
}
@ExecFunction(name = "date_format", argTypes = {"DATEV2", "VARCHAR"}, returnType = "VARCHAR")
public static Expression dateFormat(DateV2Literal date, VarcharLiteral format) {
return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format(
java.time.LocalDate.of(((int) date.getYear()), ((int) date.getMonth()), ((int) date.getDay()))));
}
@ExecFunction(name = "date_format", argTypes = {"DATETIMEV2", "VARCHAR"}, returnType = "VARCHAR")
public static Expression dateFormat(DateTimeV2Literal date, VarcharLiteral format) {
return new VarcharLiteral(DateUtils.formatBuilder(format.getValue()).toFormatter().format(
java.time.LocalDateTime.of(((int) date.getYear()), ((int) date.getMonth()), ((int) date.getDay()),
((int) date.getHour()), ((int) date.getMinute()), ((int) date.getSecond()))));
}
/**
* datetime arithmetic function date
*/
@ExecFunction(name = "date", argTypes = {"DATETIME"}, returnType = "DATE")
public static Expression date(DateTimeLiteral dateTime) throws AnalysisException {
return new DateLiteral(dateTime.getYear(), dateTime.getMonth(), dateTime.getDay());
}
@ExecFunction(name = "date", argTypes = {"DATETIMEV2"}, returnType = "DATE")
public static Expression date(DateTimeV2Literal dateTime) throws AnalysisException {
return new DateLiteral(dateTime.getYear(), dateTime.getMonth(), dateTime.getDay());
}
/**
* datetime arithmetic function date-trunc
*/
@ExecFunction(name = "date_trunc", argTypes = {"DATETIME", "VARCHAR"}, returnType = "DATETIME")
public static Expression dateTrunc(DateTimeLiteral date, VarcharLiteral trunc) {
return DateTimeLiteral.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), trunc.getValue()));
}
@ExecFunction(name = "date_trunc", argTypes = {"DATETIMEV2", "VARCHAR"}, returnType = "DATETIMEV2")
public static Expression dateTrunc(DateTimeV2Literal date, VarcharLiteral trunc) {
return DateTimeV2Literal.fromJavaDateType(dateTruncHelper(date.toJavaDateType(), trunc.getValue()));
}
private static LocalDateTime dateTruncHelper(LocalDateTime dateTime, String trunc) {
int year = dateTime.getYear();
int month = dateTime.getMonthValue();
int day = dateTime.getDayOfMonth();
int hour = dateTime.getHour();
int minute = dateTime.getMinute();
int second = dateTime.getSecond();
switch (trunc.toLowerCase()) {
case "year":
month = 0;
case "quarter": // CHECKSTYLE IGNORE THIS LINE
month = ((month - 1) / 3) * 3 + 1;
case "month": // CHECKSTYLE IGNORE THIS LINE
day = 1;
break;
case "week":
LocalDateTime firstDayOfWeek = firstDayOfWeek(dateTime);
year = firstDayOfWeek.getYear();
month = firstDayOfWeek.getMonthValue();
day = firstDayOfWeek.getDayOfMonth();
default: // CHECKSTYLE IGNORE THIS LINE
break;
}
switch (trunc.toLowerCase()) {
case "year":
case "quarter":
case "month":
case "week":
case "day": // CHECKSTYLE IGNORE THIS LINE
hour = 0;
case "hour": // CHECKSTYLE IGNORE THIS LINE
minute = 0;
case "minute": // CHECKSTYLE IGNORE THIS LINE
second = 0;
default: // CHECKSTYLE IGNORE THIS LINE
}
return LocalDateTime.of(year, month, day, hour, minute, second);
}
/**
* from_days.
*/
@ExecFunction(name = "from_days", argTypes = {"INT"}, returnType = "DATE")
public static Expression fromDays(IntegerLiteral n) {
// doris treat 0000AD as ordinary year but java LocalDateTime treat it as lunar year.
LocalDateTime res = LocalDateTime.of(0, 1, 1, 0, 0, 0)
.plusDays(n.getValue());
if (res.isBefore(LocalDateTime.of(0, 3, 1, 0, 0, 0))) {
res = res.plusDays(-1);
}
return DateLiteral.fromJavaDateType(res);
}
@ExecFunction(name = "last_day", argTypes = {"DATE"}, returnType = "DATE")
public static Expression lastDay(DateLiteral date) {
LocalDateTime nextMonthFirstDay = LocalDateTime.of((int) date.getYear(), (int) date.getMonth(), 1,
0, 0, 0).plusMonths(1);
return DateLiteral.fromJavaDateType(nextMonthFirstDay.minusDays(1));
}
@ExecFunction(name = "last_day", argTypes = {"DATETIME"}, returnType = "DATE")
public static Expression lastDay(DateTimeLiteral date) {
LocalDateTime nextMonthFirstDay = LocalDateTime.of((int) date.getYear(), (int) date.getMonth(), 1,
0, 0, 0).plusMonths(1);
return DateLiteral.fromJavaDateType(nextMonthFirstDay.minusDays(1));
}
@ExecFunction(name = "last_day", argTypes = {"DATEV2"}, returnType = "DATEV2")
public static Expression lastDay(DateV2Literal date) {
LocalDateTime nextMonthFirstDay = LocalDateTime.of((int) date.getYear(), (int) date.getMonth(), 1,
0, 0, 0).plusMonths(1);
return DateV2Literal.fromJavaDateType(nextMonthFirstDay.minusDays(1));
}
@ExecFunction(name = "last_day", argTypes = {"DATETIMEV2"}, returnType = "DATEV2")
public static Expression lastDay(DateTimeV2Literal date) {
LocalDateTime nextMonthFirstDay = LocalDateTime.of((int) date.getYear(), (int) date.getMonth(), 1,
0, 0, 0).plusMonths(1);
return DateV2Literal.fromJavaDateType(nextMonthFirstDay.minusDays(1));
}
/**
* datetime transformation function: to_monday
*/
@ExecFunction(name = "to_monday", argTypes = {"DATE"}, returnType = "DATE")
public static Expression toMonday(DateLiteral date) {
return DateLiteral.fromJavaDateType(toMonday(date.toJavaDateType()));
}
@ExecFunction(name = "to_monday", argTypes = {"DATETIME"}, returnType = "DATE")
public static Expression toMonday(DateTimeLiteral date) {
return DateLiteral.fromJavaDateType(toMonday(date.toJavaDateType()));
}
@ExecFunction(name = "to_monday", argTypes = {"DATEV2"}, returnType = "DATEV2")
public static Expression toMonday(DateV2Literal date) {
return DateV2Literal.fromJavaDateType(toMonday(date.toJavaDateType()));
}
@ExecFunction(name = "to_monday", argTypes = {"DATETIMEV2"}, returnType = "DATEV2")
public static Expression toMonday(DateTimeV2Literal date) {
return DateV2Literal.fromJavaDateType(toMonday(date.toJavaDateType()));
}
private static LocalDateTime toMonday(LocalDateTime dateTime) {
LocalDateTime specialUpperBound = LocalDateTime.of(1970, 1, 4, 0, 0, 0);
LocalDateTime specialLowerBound = LocalDateTime.of(1970, 1, 1, 0, 0, 0);
if (dateTime.isAfter(specialUpperBound) || dateTime.isBefore(specialLowerBound)) {
return dateTime.plusDays(-dateTime.getDayOfWeek().getValue() + 1);
}
return specialLowerBound;
}
/**
* date transformation function: from_unixtime
*/
@ExecFunction(name = "from_unixtime", argTypes = {"INT"}, returnType = "VARCHAR")
public static Expression fromUnixTime(IntegerLiteral second) {
if (second.getValue() < 0 || second.getValue() >= 253402271999L) {
return null;
}
return fromUnixTime(second, new VarcharLiteral("%Y-%m-%d %H:%i:%s"));
}
/**
* date transformation function: from_unixtime
*/
@ExecFunction(name = "from_unixtime", argTypes = {"INT", "VARCHAR"}, returnType = "VARCHAR")
public static Expression fromUnixTime(IntegerLiteral second, VarcharLiteral format) {
if (second.getValue() < 0) {
return null;
}
ZonedDateTime dateTime = LocalDateTime.of(1970, 1, 1, 0, 0, 0)
.plusSeconds(second.getValue())
.atZone(ZoneId.of("UTC+0"))
.toOffsetDateTime()
.atZoneSameInstant(ZoneId.systemDefault());
return dateFormat(new DateTimeLiteral(dateTime.getYear(), dateTime.getMonthValue(),
dateTime.getDayOfMonth(), dateTime.getHour(), dateTime.getMinute(), dateTime.getSecond()),
format);
}
/**
* date transformation function: unix_timestamp
*/
@ExecFunction(name = "unix_timestamp", argTypes = {}, returnType = "INT")
public static Expression unixTimestamp() {
return new IntegerLiteral(getTimestamp(LocalDateTime.now()));
}
/**
* date transformation function: unix_timestamp
*/
@ExecFunction(name = "unix_timestamp", argTypes = {"DATE"}, returnType = "INT")
public static Expression unixTimestamp(DateLiteral date) {
return new IntegerLiteral(getTimestamp(date.toJavaDateType()));
}
@ExecFunction(name = "unix_timestamp", argTypes = {"DATETIME"}, returnType = "INT")
public static Expression unixTimestamp(DateTimeLiteral date) {
return new IntegerLiteral(getTimestamp(date.toJavaDateType()));
}
@ExecFunction(name = "unix_timestamp", argTypes = {"DATEV2"}, returnType = "INT")
public static Expression unixTimestamp(DateV2Literal date) {
return new IntegerLiteral(getTimestamp(date.toJavaDateType()));
}
@ExecFunction(name = "unix_timestamp", argTypes = {"DATETIMEV2"}, returnType = "INT")
public static Expression unixTimestamp(DateTimeV2Literal date) {
return new IntegerLiteral(getTimestamp(date.toJavaDateType()));
}
/**
* date transformation function: unix_timestamp
*/
@ExecFunction(name = "unix_timestamp", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "INT")
public static Expression unixTimestamp(VarcharLiteral date, VarcharLiteral format) {
DateTimeFormatter formatter = DateUtils.formatBuilder(format.getValue()).toFormatter();
LocalDateTime dateObj;
try {
dateObj = LocalDateTime.parse(date.getValue(), formatter);
} catch (DateTimeParseException e) {
// means the date string doesn't contain time fields.
dateObj = LocalDate.parse(date.getValue(), formatter).atStartOfDay();
}
return new IntegerLiteral(getTimestamp(dateObj));
}
private static Integer getTimestamp(LocalDateTime dateTime) {
LocalDateTime specialUpperBound = LocalDateTime.of(2038, 1, 19, 3, 14, 7);
LocalDateTime specialLowerBound = LocalDateTime.of(1970, 1, 1, 0, 0, 0);
if (dateTime.isBefore(specialLowerBound) || dateTime.isAfter(specialUpperBound)) {
return 0;
}
return ((int) Duration.between(
specialLowerBound,
dateTime
.atZone(ZoneId.systemDefault())
.toOffsetDateTime().atZoneSameInstant(ZoneId.of("UTC+0"))
.toLocalDateTime()).getSeconds());
}
/**
* date transformation function: utc_timestamp
*/
@ExecFunction(name = "utc_timestamp", argTypes = {}, returnType = "INT")
public static Expression utcTimestamp() {
return DateTimeLiteral.fromJavaDateType(LocalDateTime.now());
}
/**
* date transformation function: to_date
*/
@ExecFunction(name = "to_date", argTypes = {"DATETIME"}, returnType = "DATE")
public static Expression toDate(DateTimeLiteral date) {
return new DateLiteral(date.getYear(), date.getMonth(), date.getDay());
}
@ExecFunction(name = "to_date", argTypes = {"DATETIMEV2"}, returnType = "DATE")
public static Expression toDate(DateTimeV2Literal date) {
return new DateLiteral(date.getYear(), date.getMonth(), date.getDay());
}
/**
* date transformation function: to_days
*/
@ExecFunction(name = "to_days", argTypes = {"DATE"}, returnType = "INT")
public static Expression toDays(DateLiteral date) {
return new IntegerLiteral(((int) Duration.between(
LocalDateTime.of(0, 1, 1, 0, 0, 0), date.toJavaDateType()).toDays()));
}
@ExecFunction(name = "to_days", argTypes = {"DATETIME"}, returnType = "INT")
public static Expression toDays(DateTimeLiteral date) {
return new IntegerLiteral(((int) Duration.between(
LocalDateTime.of(0, 1, 1, 0, 0, 0), date.toJavaDateType()).toDays()));
}
@ExecFunction(name = "to_days", argTypes = {"DATEV2"}, returnType = "INT")
public static Expression toDays(DateV2Literal date) {
return new IntegerLiteral(((int) Duration.between(
LocalDateTime.of(0, 1, 1, 0, 0, 0), date.toJavaDateType()).toDays()));
}
@ExecFunction(name = "to_days", argTypes = {"DATETIMEV2"}, returnType = "INT")
public static Expression toDays(DateTimeV2Literal date) {
return new IntegerLiteral(((int) Duration.between(
LocalDateTime.of(0, 1, 1, 0, 0, 0), date.toJavaDateType()).toDays()));
}
/**
* date transformation function: makedate
*/
@ExecFunction(name = "makedate", argTypes = {"INT", "INT"}, returnType = "DATE")
public static Expression makeDate(IntegerLiteral year, IntegerLiteral dayOfYear) {
return DateLiteral.fromJavaDateType(LocalDateTime.of(year.getValue(), 1, 1, 0, 0, 0)
.plusDays(dayOfYear.getValue() - 1));
}
/**
* date transformation function: str_to_date
*/
@ExecFunction(name = "str_to_date", argTypes = {"VARCHAR, VARCHAR"}, returnType = "DATETIME")
public static Expression strToDate(VarcharLiteral str, VarcharLiteral format) {
return DateTimeLiteral.fromJavaDateType(DateUtils.getTime(DateUtils.formatBuilder(format.getValue())
.toFormatter(), str.getValue()));
}
}

View File

@ -0,0 +1,129 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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 org.apache.doris.nereids.trees.expressions.functions.executable;
import org.apache.doris.nereids.trees.expressions.ExecFunction;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DecimalLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DecimalV3Literal;
import org.apache.doris.nereids.trees.expressions.literal.DoubleLiteral;
import org.apache.doris.nereids.trees.expressions.literal.FloatLiteral;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.expressions.literal.LargeIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
import java.util.Random;
import java.util.UUID;
/**
* functions that can be executed in FE.
*/
public class ExecutableFunctions {
public static final ExecutableFunctions INSTANCE = new ExecutableFunctions();
private static final Random RANDOM = new Random();
/**
* other scalar function
*/
@ExecFunction(name = "abs", argTypes = {"TINYINT"}, returnType = "TINYINT")
public static Expression abs(TinyIntLiteral literal) {
return new TinyIntLiteral((byte) Math.abs(literal.getValue()));
}
@ExecFunction(name = "abs", argTypes = {"SMALLINT"}, returnType = "SMALLINT")
public static Expression abs(SmallIntLiteral literal) {
return new SmallIntLiteral((short) Math.abs(literal.getValue()));
}
@ExecFunction(name = "abs", argTypes = {"INT"}, returnType = "INT")
public static Expression abs(IntegerLiteral literal) {
return new IntegerLiteral(Math.abs(literal.getValue()));
}
@ExecFunction(name = "abs", argTypes = {"BIGINT"}, returnType = "BIGINT")
public static Expression abs(BigIntLiteral literal) {
return new BigIntLiteral(Math.abs(literal.getValue()));
}
@ExecFunction(name = "abs", argTypes = {"LARGEINT"}, returnType = "LARGEINT")
public static Expression abs(LargeIntLiteral literal) {
return new LargeIntLiteral(literal.getValue().abs());
}
@ExecFunction(name = "abs", argTypes = {"FLOAT"}, returnType = "FLOAT")
public static Expression abs(FloatLiteral literal) {
return new FloatLiteral(Math.abs(literal.getValue()));
}
@ExecFunction(name = "abs", argTypes = {"DOUBLE"}, returnType = "DOUBLE")
public static Expression abs(DoubleLiteral literal) {
return new DoubleLiteral(Math.abs(literal.getValue()));
}
@ExecFunction(name = "abs", argTypes = {"DECIMAL"}, returnType = "DECIMAL")
public static Expression abs(DecimalLiteral literal) {
return new DecimalLiteral(literal.getValue().abs());
}
@ExecFunction(name = "abs", argTypes = {"DECIMALV3"}, returnType = "DECIMALV3")
public static Expression abs(DecimalV3Literal literal) {
return new DecimalV3Literal(literal.getValue().abs());
}
@ExecFunction(name = "acos", argTypes = {"DOUBLE"}, returnType = "DOUBLE")
public static Expression acos(DoubleLiteral literal) {
return new DoubleLiteral(Math.acos(literal.getValue()));
}
@ExecFunction(name = "append_trailing_if_char_absent", argTypes = {"VARCHAR", "VARCHAR"}, returnType = "VARCHAR")
public static Expression appendTrailingIfCharAbsent(VarcharLiteral literal, VarcharLiteral chr) {
if (literal.getValue().length() != 1) {
return null;
}
return literal.getValue().endsWith(chr.getValue()) ? literal
: new VarcharLiteral(literal.getValue() + chr.getValue());
}
@ExecFunction(name = "e", argTypes = {}, returnType = "DOUBLE")
public static Expression e() { // CHECKSTYLE IGNORE THIS LINE
return new DoubleLiteral(Math.E);
}
@ExecFunction(name = "p1", argTypes = {}, returnType = "DOUBLE")
public static Expression pi() {
return new DoubleLiteral(Math.PI);
}
@ExecFunction(name = "uuid", argTypes = {}, returnType = "VARCHAR")
public static Expression uuid() {
return new VarcharLiteral(UUID.randomUUID().toString());
}
@ExecFunction(name = "rand", argTypes = {}, returnType = "DOUBLE")
public static Expression rand() {
return new DoubleLiteral(RANDOM.nextDouble());
}
@ExecFunction(name = "random", argTypes = {}, returnType = "DOUBLE")
public static Expression random() {
return new DoubleLiteral(RANDOM.nextDouble());
}
}

View File

@ -15,21 +15,16 @@
// specific language governing permissions and limitations
// under the License.
package org.apache.doris.nereids.trees.expressions.functions;
package org.apache.doris.nereids.trees.expressions.functions.executable;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.ExecFunction;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.literal.BigIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeV2Literal;
import org.apache.doris.nereids.trees.expressions.literal.DateV2Literal;
import org.apache.doris.nereids.trees.expressions.literal.DecimalLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DecimalV3Literal;
import org.apache.doris.nereids.trees.expressions.literal.DoubleLiteral;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.expressions.literal.LargeIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.TinyIntLiteral;
@ -39,509 +34,513 @@ import java.math.BigDecimal;
import java.math.BigInteger;
/**
* functions that can be executed in FE.
* executable functions:
* add, subtract, multiply, divide
*/
public class ExecutableFunctions {
public static final ExecutableFunctions INSTANCE = new ExecutableFunctions();
public class NumericArithmetic {
/**
* Executable arithmetic functions
* Executable arithmetic functions add
*/
@ExecFunction(name = "add", argTypes = {"TINYINT", "TINYINT"}, returnType = "SMALLINT")
public static SmallIntLiteral addTinyIntTinyInt(TinyIntLiteral first, TinyIntLiteral second) {
public static Expression addTinyIntTinyInt(TinyIntLiteral first, TinyIntLiteral second) {
short result = (short) Math.addExact(first.getValue(), second.getValue());
return new SmallIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"TINYINT", "SMALLINT"}, returnType = "INT")
public static IntegerLiteral addTinyIntSmallInt(TinyIntLiteral first, SmallIntLiteral second) {
public static Expression addTinyIntSmallInt(TinyIntLiteral first, SmallIntLiteral second) {
int result = Math.addExact(first.getValue(), second.getValue());
return new IntegerLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"TINYINT", "INT"}, returnType = "BIGINT")
public static BigIntLiteral addTinyIntInt(TinyIntLiteral first, IntegerLiteral second) {
public static Expression addTinyIntInt(TinyIntLiteral first, IntegerLiteral second) {
long result = Math.addExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"TINYINT", "BIGINT"}, returnType = "BIGINT")
public static BigIntLiteral addTinyIntBigInt(TinyIntLiteral first, BigIntLiteral second) {
public static Expression addTinyIntBigInt(TinyIntLiteral first, BigIntLiteral second) {
long result = Math.addExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"TINYINT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral addTinyIntLargeInt(TinyIntLiteral first, LargeIntLiteral second) {
public static Expression addTinyIntLargeInt(TinyIntLiteral first, LargeIntLiteral second) {
BigInteger result = second.getValue().add(new BigInteger(first.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"SMALLINT", "TINYINT"}, returnType = "INT")
public static IntegerLiteral addSmallIntTinyInt(SmallIntLiteral first, TinyIntLiteral second) {
public static Expression addSmallIntTinyInt(SmallIntLiteral first, TinyIntLiteral second) {
int result = Math.addExact(first.getValue(), second.getValue());
return new IntegerLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"SMALLINT", "SMALLINT"}, returnType = "INT")
public static IntegerLiteral addSmallIntSmallInt(SmallIntLiteral first, SmallIntLiteral second) {
public static Expression addSmallIntSmallInt(SmallIntLiteral first, SmallIntLiteral second) {
int result = Math.addExact(first.getValue(), second.getValue());
return new IntegerLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"SMALLINT", "INT"}, returnType = "BIGINT")
public static BigIntLiteral addSmallIntInt(SmallIntLiteral first, IntegerLiteral second) {
public static Expression addSmallIntInt(SmallIntLiteral first, IntegerLiteral second) {
long result = Math.addExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"SMALLINT", "BIGINT"}, returnType = "BIGINT")
public static BigIntLiteral addSmallIntBigInt(SmallIntLiteral first, BigIntLiteral second) {
public static Expression addSmallIntBigInt(SmallIntLiteral first, BigIntLiteral second) {
long result = Math.addExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"SMALLINT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral addSmallIntLargeInt(SmallIntLiteral first, LargeIntLiteral second) {
public static Expression addSmallIntLargeInt(SmallIntLiteral first, LargeIntLiteral second) {
BigInteger result = second.getValue().add(new BigInteger(first.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"INT", "TINYINT"}, returnType = "BIGINT")
public static BigIntLiteral addIntTinyInt(IntegerLiteral first, TinyIntLiteral second) {
public static Expression addIntTinyInt(IntegerLiteral first, TinyIntLiteral second) {
long result = Math.addExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"INT", "SMALLINT"}, returnType = "BIGINT")
public static BigIntLiteral addIntSmallInt(IntegerLiteral first, SmallIntLiteral second) {
public static Expression addIntSmallInt(IntegerLiteral first, SmallIntLiteral second) {
long result = Math.addExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"INT", "INT"}, returnType = "BIGINT")
public static BigIntLiteral addIntInt(IntegerLiteral first, IntegerLiteral second) {
public static Expression addIntInt(IntegerLiteral first, IntegerLiteral second) {
long result = Math.addExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"INT", "BIGINT"}, returnType = "BIGINT")
public static BigIntLiteral addIntBigInt(IntegerLiteral first, BigIntLiteral second) {
public static Expression addIntBigInt(IntegerLiteral first, BigIntLiteral second) {
long result = Math.addExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"INT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral addIntLargeInt(IntegerLiteral first, LargeIntLiteral second) {
public static Expression addIntLargeInt(IntegerLiteral first, LargeIntLiteral second) {
BigInteger result = second.getValue().add(new BigInteger(first.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"BIGINT", "TINYINT"}, returnType = "BIGINT")
public static BigIntLiteral addBigIntTinyInt(BigIntLiteral first, TinyIntLiteral second) {
public static Expression addBigIntTinyInt(BigIntLiteral first, TinyIntLiteral second) {
long result = Math.addExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"BIGINT", "SMALLINT"}, returnType = "BIGINT")
public static BigIntLiteral addBigIntSmallInt(BigIntLiteral first, SmallIntLiteral second) {
public static Expression addBigIntSmallInt(BigIntLiteral first, SmallIntLiteral second) {
long result = Math.addExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"BIGINT", "INT"}, returnType = "BIGINT")
public static BigIntLiteral addBigIntInt(BigIntLiteral first, IntegerLiteral second) {
public static Expression addBigIntInt(BigIntLiteral first, IntegerLiteral second) {
long result = Math.addExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"BIGINT", "BIGINT"}, returnType = "BIGINT")
public static BigIntLiteral addBigIntBigInt(BigIntLiteral first, BigIntLiteral second) {
public static Expression addBigIntBigInt(BigIntLiteral first, BigIntLiteral second) {
long result = Math.addExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"BIGINT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral addBigIntLargeInt(BigIntLiteral first, LargeIntLiteral second) {
public static Expression addBigIntLargeInt(BigIntLiteral first, LargeIntLiteral second) {
BigInteger result = second.getValue().add(new BigInteger(first.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"LARGEINT", "TINYINT"}, returnType = "BIGINT")
public static LargeIntLiteral addLargeIntTinyInt(LargeIntLiteral first, TinyIntLiteral second) {
public static Expression addLargeIntTinyInt(LargeIntLiteral first, TinyIntLiteral second) {
BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"LARGEINT", "SMALLINT"}, returnType = "BIGINT")
public static LargeIntLiteral addLargeIntSmallInt(LargeIntLiteral first, SmallIntLiteral second) {
public static Expression addLargeIntSmallInt(LargeIntLiteral first, SmallIntLiteral second) {
BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"LARGEINT", "INT"}, returnType = "BIGINT")
public static LargeIntLiteral addLargeIntInt(LargeIntLiteral first, IntegerLiteral second) {
public static Expression addLargeIntInt(LargeIntLiteral first, IntegerLiteral second) {
BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"LARGEINT", "BIGINT"}, returnType = "BIGINT")
public static LargeIntLiteral addLargeIntBigInt(LargeIntLiteral first, BigIntLiteral second) {
public static Expression addLargeIntBigInt(LargeIntLiteral first, BigIntLiteral second) {
BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"LARGEINT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral addLargeIntLargeInt(LargeIntLiteral first, LargeIntLiteral second) {
public static Expression addLargeIntLargeInt(LargeIntLiteral first, LargeIntLiteral second) {
BigInteger result = first.getValue().add(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"DOUBLE", "DOUBLE"}, returnType = "DOUBLE")
public static DoubleLiteral addDoubleDouble(DoubleLiteral first, DoubleLiteral second) {
public static Expression addDoubleDouble(DoubleLiteral first, DoubleLiteral second) {
double result = first.getValue() + second.getValue();
return new DoubleLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
public static DecimalLiteral addDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
public static Expression addDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
BigDecimal result = first.getValue().add(second.getValue());
return new DecimalLiteral(result);
}
@ExecFunction(name = "add", argTypes = {"DECIMALV3", "DECIMALV3"}, returnType = "DECIMALV3")
public static DecimalV3Literal addDecimalV3DecimalV3(DecimalV3Literal first, DecimalV3Literal second) {
public static Expression addDecimalV3DecimalV3(DecimalV3Literal first, DecimalV3Literal second) {
BigDecimal result = first.getValue().add(second.getValue());
return new DecimalV3Literal((DecimalV3Type) first.getDataType(), result);
}
/**
* Executable arithmetic functions subtract
*/
@ExecFunction(name = "subtract", argTypes = {"TINYINT", "TINYINT"}, returnType = "SMALLINT")
public static SmallIntLiteral subtractTinyIntTinyInt(TinyIntLiteral first, TinyIntLiteral second) {
public static Expression subtractTinyIntTinyInt(TinyIntLiteral first, TinyIntLiteral second) {
short result = (short) Math.subtractExact(first.getValue(), second.getValue());
return new SmallIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"TINYINT", "SMALLINT"}, returnType = "INT")
public static IntegerLiteral subtractTinyIntSmallInt(TinyIntLiteral first, SmallIntLiteral second) {
public static Expression subtractTinyIntSmallInt(TinyIntLiteral first, SmallIntLiteral second) {
int result = Math.subtractExact(first.getValue(), second.getValue());
return new IntegerLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"TINYINT", "INT"}, returnType = "BIGINT")
public static BigIntLiteral subtractTinyIntInt(TinyIntLiteral first, IntegerLiteral second) {
public static Expression subtractTinyIntInt(TinyIntLiteral first, IntegerLiteral second) {
long result = Math.subtractExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"TINYINT", "BIGINT"}, returnType = "BIGINT")
public static BigIntLiteral subtractTinyIntBigInt(TinyIntLiteral first, BigIntLiteral second) {
public static Expression subtractTinyIntBigInt(TinyIntLiteral first, BigIntLiteral second) {
long result = Math.subtractExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"TINYINT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral subtractTinyIntLargeInt(TinyIntLiteral first, LargeIntLiteral second) {
public static Expression subtractTinyIntLargeInt(TinyIntLiteral first, LargeIntLiteral second) {
BigInteger result = second.getValue().subtract(new BigInteger(first.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"SMALLINT", "TINYINT"}, returnType = "INT")
public static IntegerLiteral subtractSmallIntTinyInt(SmallIntLiteral first, TinyIntLiteral second) {
public static Expression subtractSmallIntTinyInt(SmallIntLiteral first, TinyIntLiteral second) {
int result = Math.subtractExact(first.getValue(), second.getValue());
return new IntegerLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"SMALLINT", "SMALLINT"}, returnType = "INT")
public static IntegerLiteral subtractSmallIntSmallInt(SmallIntLiteral first, SmallIntLiteral second) {
public static Expression subtractSmallIntSmallInt(SmallIntLiteral first, SmallIntLiteral second) {
int result = Math.subtractExact(first.getValue(), second.getValue());
return new IntegerLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"SMALLINT", "INT"}, returnType = "BIGINT")
public static BigIntLiteral subtractSmallIntInt(SmallIntLiteral first, IntegerLiteral second) {
public static Expression subtractSmallIntInt(SmallIntLiteral first, IntegerLiteral second) {
long result = Math.subtractExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"SMALLINT", "BIGINT"}, returnType = "BIGINT")
public static BigIntLiteral subtractSmallIntBigInt(SmallIntLiteral first, BigIntLiteral second) {
public static Expression subtractSmallIntBigInt(SmallIntLiteral first, BigIntLiteral second) {
long result = Math.subtractExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"SMALLINT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral subtractSmallIntLargeInt(SmallIntLiteral first, LargeIntLiteral second) {
public static Expression subtractSmallIntLargeInt(SmallIntLiteral first, LargeIntLiteral second) {
BigInteger result = second.getValue().subtract(new BigInteger(first.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"INT", "TINYINT"}, returnType = "BIGINT")
public static BigIntLiteral subtractIntTinyInt(IntegerLiteral first, TinyIntLiteral second) {
public static Expression subtractIntTinyInt(IntegerLiteral first, TinyIntLiteral second) {
long result = Math.subtractExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"INT", "SMALLINT"}, returnType = "BIGINT")
public static BigIntLiteral subtractIntSmallInt(IntegerLiteral first, SmallIntLiteral second) {
public static Expression subtractIntSmallInt(IntegerLiteral first, SmallIntLiteral second) {
long result = Math.subtractExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"INT", "INT"}, returnType = "BIGINT")
public static BigIntLiteral subtractIntInt(IntegerLiteral first, IntegerLiteral second) {
public static Expression subtractIntInt(IntegerLiteral first, IntegerLiteral second) {
long result = Math.subtractExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"INT", "BIGINT"}, returnType = "BIGINT")
public static BigIntLiteral subtractIntBigInt(IntegerLiteral first, BigIntLiteral second) {
public static Expression subtractIntBigInt(IntegerLiteral first, BigIntLiteral second) {
long result = Math.subtractExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"INT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral subtractIntLargeInt(IntegerLiteral first, LargeIntLiteral second) {
public static Expression subtractIntLargeInt(IntegerLiteral first, LargeIntLiteral second) {
BigInteger result = second.getValue().subtract(new BigInteger(first.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"BIGINT", "TINYINT"}, returnType = "BIGINT")
public static BigIntLiteral subtractBigIntTinyInt(BigIntLiteral first, TinyIntLiteral second) {
public static Expression subtractBigIntTinyInt(BigIntLiteral first, TinyIntLiteral second) {
long result = Math.subtractExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"BIGINT", "SMALLINT"}, returnType = "BIGINT")
public static BigIntLiteral subtractBigIntSmallInt(BigIntLiteral first, SmallIntLiteral second) {
public static Expression subtractBigIntSmallInt(BigIntLiteral first, SmallIntLiteral second) {
long result = Math.subtractExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"BIGINT", "INT"}, returnType = "BIGINT")
public static BigIntLiteral subtractBigIntInt(BigIntLiteral first, IntegerLiteral second) {
public static Expression subtractBigIntInt(BigIntLiteral first, IntegerLiteral second) {
long result = Math.subtractExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"BIGINT", "BIGINT"}, returnType = "BIGINT")
public static BigIntLiteral subtractBigIntBigInt(BigIntLiteral first, BigIntLiteral second) {
public static Expression subtractBigIntBigInt(BigIntLiteral first, BigIntLiteral second) {
long result = Math.subtractExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"BIGINT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral subtractBigIntLargeInt(BigIntLiteral first, LargeIntLiteral second) {
public static Expression subtractBigIntLargeInt(BigIntLiteral first, LargeIntLiteral second) {
BigInteger result = second.getValue().subtract(new BigInteger(first.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"LARGEINT", "TINYINT"}, returnType = "BIGINT")
public static LargeIntLiteral subtractLargeIntTinyInt(LargeIntLiteral first, TinyIntLiteral second) {
public static Expression subtractLargeIntTinyInt(LargeIntLiteral first, TinyIntLiteral second) {
BigInteger result = first.getValue().subtract(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"LARGEINT", "SMALLINT"}, returnType = "BIGINT")
public static LargeIntLiteral subtractLargeIntSmallInt(LargeIntLiteral first, SmallIntLiteral second) {
public static Expression subtractLargeIntSmallInt(LargeIntLiteral first, SmallIntLiteral second) {
BigInteger result = first.getValue().subtract(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"LARGEINT", "INT"}, returnType = "BIGINT")
public static LargeIntLiteral subtractLargeIntInt(LargeIntLiteral first, IntegerLiteral second) {
public static Expression subtractLargeIntInt(LargeIntLiteral first, IntegerLiteral second) {
BigInteger result = first.getValue().subtract(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"LARGEINT", "BIGINT"}, returnType = "BIGINT")
public static LargeIntLiteral subtractLargeIntBigInt(LargeIntLiteral first, BigIntLiteral second) {
public static Expression subtractLargeIntBigInt(LargeIntLiteral first, BigIntLiteral second) {
BigInteger result = first.getValue().subtract(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"LARGEINT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral subtractLargeIntLargeInt(LargeIntLiteral first, LargeIntLiteral second) {
public static Expression subtractLargeIntLargeInt(LargeIntLiteral first, LargeIntLiteral second) {
BigInteger result = first.getValue().subtract(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"DOUBLE", "DOUBLE"}, returnType = "DOUBLE")
public static DoubleLiteral subtractDoubleDouble(DoubleLiteral first, DoubleLiteral second) {
public static Expression subtractDoubleDouble(DoubleLiteral first, DoubleLiteral second) {
double result = first.getValue() - second.getValue();
return new DoubleLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
public static DecimalLiteral subtractDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
public static Expression subtractDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
BigDecimal result = first.getValue().subtract(second.getValue());
return new DecimalLiteral(result);
}
@ExecFunction(name = "subtract", argTypes = {"DECIMALV3", "DECIMALV3"}, returnType = "DECIMALV3")
public static DecimalV3Literal subtractDecimalV3DecimalV3(DecimalV3Literal first, DecimalV3Literal second) {
public static Expression subtractDecimalV3DecimalV3(DecimalV3Literal first, DecimalV3Literal second) {
BigDecimal result = first.getValue().subtract(second.getValue());
return new DecimalV3Literal((DecimalV3Type) first.getDataType(), result);
}
/**
* Executable arithmetic functions multiply
*/
@ExecFunction(name = "multiply", argTypes = {"TINYINT", "TINYINT"}, returnType = "SMALLINT")
public static SmallIntLiteral multiplyTinyIntTinyInt(TinyIntLiteral first, TinyIntLiteral second) {
public static Expression multiplyTinyIntTinyInt(TinyIntLiteral first, TinyIntLiteral second) {
short result = (short) Math.multiplyExact(first.getValue(), second.getValue());
return new SmallIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"TINYINT", "SMALLINT"}, returnType = "INT")
public static IntegerLiteral multiplyTinyIntSmallInt(TinyIntLiteral first, SmallIntLiteral second) {
public static Expression multiplyTinyIntSmallInt(TinyIntLiteral first, SmallIntLiteral second) {
int result = Math.multiplyExact(first.getValue(), second.getValue());
return new IntegerLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"TINYINT", "INT"}, returnType = "BIGINT")
public static BigIntLiteral multiplyTinyIntInt(TinyIntLiteral first, IntegerLiteral second) {
public static Expression multiplyTinyIntInt(TinyIntLiteral first, IntegerLiteral second) {
long result = Math.multiplyExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"TINYINT", "BIGINT"}, returnType = "BIGINT")
public static BigIntLiteral multiplyTinyIntBigInt(TinyIntLiteral first, BigIntLiteral second) {
public static Expression multiplyTinyIntBigInt(TinyIntLiteral first, BigIntLiteral second) {
long result = Math.multiplyExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"TINYINT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral multiplyTinyIntLargeInt(TinyIntLiteral first, LargeIntLiteral second) {
public static Expression multiplyTinyIntLargeInt(TinyIntLiteral first, LargeIntLiteral second) {
BigInteger result = second.getValue().multiply(new BigInteger(first.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"SMALLINT", "TINYINT"}, returnType = "INT")
public static IntegerLiteral multiplySmallIntTinyInt(SmallIntLiteral first, TinyIntLiteral second) {
public static Expression multiplySmallIntTinyInt(SmallIntLiteral first, TinyIntLiteral second) {
int result = Math.multiplyExact(first.getValue(), second.getValue());
return new IntegerLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"SMALLINT", "SMALLINT"}, returnType = "INT")
public static IntegerLiteral multiplySmallIntSmallInt(SmallIntLiteral first, SmallIntLiteral second) {
public static Expression multiplySmallIntSmallInt(SmallIntLiteral first, SmallIntLiteral second) {
int result = Math.multiplyExact(first.getValue(), second.getValue());
return new IntegerLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"SMALLINT", "INT"}, returnType = "BIGINT")
public static BigIntLiteral multiplySmallIntInt(SmallIntLiteral first, IntegerLiteral second) {
public static Expression multiplySmallIntInt(SmallIntLiteral first, IntegerLiteral second) {
long result = Math.multiplyExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"SMALLINT", "BIGINT"}, returnType = "BIGINT")
public static BigIntLiteral multiplySmallIntBigInt(SmallIntLiteral first, BigIntLiteral second) {
public static Expression multiplySmallIntBigInt(SmallIntLiteral first, BigIntLiteral second) {
long result = Math.multiplyExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"SMALLINT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral multiplySmallIntLargeInt(SmallIntLiteral first, LargeIntLiteral second) {
public static Expression multiplySmallIntLargeInt(SmallIntLiteral first, LargeIntLiteral second) {
BigInteger result = second.getValue().multiply(new BigInteger(first.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"INT", "TINYINT"}, returnType = "BIGINT")
public static BigIntLiteral multiplyIntTinyInt(IntegerLiteral first, TinyIntLiteral second) {
public static Expression multiplyIntTinyInt(IntegerLiteral first, TinyIntLiteral second) {
long result = Math.multiplyExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"INT", "SMALLINT"}, returnType = "BIGINT")
public static BigIntLiteral multiplyIntSmallInt(IntegerLiteral first, SmallIntLiteral second) {
public static Expression multiplyIntSmallInt(IntegerLiteral first, SmallIntLiteral second) {
long result = Math.multiplyExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"INT", "INT"}, returnType = "BIGINT")
public static BigIntLiteral multiplyIntInt(IntegerLiteral first, IntegerLiteral second) {
public static Expression multiplyIntInt(IntegerLiteral first, IntegerLiteral second) {
long result = Math.multiplyExact((long) first.getValue(), (long) second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"INT", "BIGINT"}, returnType = "BIGINT")
public static BigIntLiteral multiplyIntBigInt(IntegerLiteral first, BigIntLiteral second) {
public static Expression multiplyIntBigInt(IntegerLiteral first, BigIntLiteral second) {
long result = Math.multiplyExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"INT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral multiplyIntLargeInt(IntegerLiteral first, LargeIntLiteral second) {
public static Expression multiplyIntLargeInt(IntegerLiteral first, LargeIntLiteral second) {
BigInteger result = second.getValue().multiply(new BigInteger(first.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"BIGINT", "TINYINT"}, returnType = "BIGINT")
public static BigIntLiteral multiplyBigIntTinyInt(BigIntLiteral first, TinyIntLiteral second) {
public static Expression multiplyBigIntTinyInt(BigIntLiteral first, TinyIntLiteral second) {
long result = Math.multiplyExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"BIGINT", "SMALLINT"}, returnType = "BIGINT")
public static BigIntLiteral multiplyBigIntSmallInt(BigIntLiteral first, SmallIntLiteral second) {
public static Expression multiplyBigIntSmallInt(BigIntLiteral first, SmallIntLiteral second) {
long result = Math.multiplyExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"BIGINT", "INT"}, returnType = "BIGINT")
public static BigIntLiteral multiplyBigIntInt(BigIntLiteral first, IntegerLiteral second) {
public static Expression multiplyBigIntInt(BigIntLiteral first, IntegerLiteral second) {
long result = Math.multiplyExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"BIGINT", "BIGINT"}, returnType = "BIGINT")
public static BigIntLiteral multiplyBigIntBigInt(BigIntLiteral first, BigIntLiteral second) {
public static Expression multiplyBigIntBigInt(BigIntLiteral first, BigIntLiteral second) {
long result = Math.multiplyExact(first.getValue(), second.getValue());
return new BigIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"BIGINT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral multiplyBigIntLargeInt(BigIntLiteral first, LargeIntLiteral second) {
public static Expression multiplyBigIntLargeInt(BigIntLiteral first, LargeIntLiteral second) {
BigInteger result = second.getValue().multiply(new BigInteger(first.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"LARGEINT", "TINYINT"}, returnType = "BIGINT")
public static LargeIntLiteral multiplyLargeIntTinyInt(LargeIntLiteral first, TinyIntLiteral second) {
public static Expression multiplyLargeIntTinyInt(LargeIntLiteral first, TinyIntLiteral second) {
BigInteger result = first.getValue().multiply(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"LARGEINT", "SMALLINT"}, returnType = "BIGINT")
public static LargeIntLiteral multiplyLargeIntSmallInt(LargeIntLiteral first, SmallIntLiteral second) {
public static Expression multiplyLargeIntSmallInt(LargeIntLiteral first, SmallIntLiteral second) {
BigInteger result = first.getValue().multiply(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"LARGEINT", "INT"}, returnType = "BIGINT")
public static LargeIntLiteral multiplyLargeIntInt(LargeIntLiteral first, IntegerLiteral second) {
public static Expression multiplyLargeIntInt(LargeIntLiteral first, IntegerLiteral second) {
BigInteger result = first.getValue().multiply(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"LARGEINT", "BIGINT"}, returnType = "BIGINT")
public static LargeIntLiteral multiplyLargeIntBigInt(LargeIntLiteral first, BigIntLiteral second) {
public static Expression multiplyLargeIntBigInt(LargeIntLiteral first, BigIntLiteral second) {
BigInteger result = first.getValue().multiply(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"LARGEINT", "LARGEINT"}, returnType = "LARGEINT")
public static LargeIntLiteral multiplyLargeIntLargeInt(LargeIntLiteral first, LargeIntLiteral second) {
public static Expression multiplyLargeIntLargeInt(LargeIntLiteral first, LargeIntLiteral second) {
BigInteger result = first.getValue().multiply(new BigInteger(second.getValue().toString()));
return new LargeIntLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"DOUBLE", "DOUBLE"}, returnType = "DOUBLE")
public static DoubleLiteral multiplyDoubleDouble(DoubleLiteral first, DoubleLiteral second) {
public static Expression multiplyDoubleDouble(DoubleLiteral first, DoubleLiteral second) {
double result = first.getValue() * second.getValue();
return new DoubleLiteral(result);
}
@ExecFunction(name = "multiply", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
public static DecimalLiteral multiplyDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
public static Expression multiplyDecimalDecimal(DecimalLiteral first, DecimalLiteral second) {
BigDecimal result = first.getValue().multiply(second.getValue());
return new DecimalLiteral(result);
}
@ -550,7 +549,7 @@ public class ExecutableFunctions {
* decimalV3 multiply in FE
*/
@ExecFunction(name = "multiply", argTypes = {"DECIMALV3", "DECIMALV3"}, returnType = "DECIMALV3")
public static DecimalV3Literal multiplyDecimalV3DecimalV3(DecimalV3Literal first, DecimalV3Literal second) {
public static Expression multiplyDecimalV3DecimalV3(DecimalV3Literal first, DecimalV3Literal second) {
BigDecimal result = first.getValue().multiply(second.getValue());
DecimalV3Type t1 = (DecimalV3Type) first.getDataType();
DecimalV3Type t2 = (DecimalV3Type) second.getDataType();
@ -559,8 +558,11 @@ public class ExecutableFunctions {
return new DecimalV3Literal(DecimalV3Type.createDecimalV3Type(precision, scale), result);
}
/**
* Executable arithmetic functions divide
*/
@ExecFunction(name = "divide", argTypes = {"DOUBLE", "DOUBLE"}, returnType = "DOUBLE")
public static Literal divideDouble(DoubleLiteral first, DoubleLiteral second) {
public static Expression divideDouble(DoubleLiteral first, DoubleLiteral second) {
if (second.getValue() == 0.0) {
return new NullLiteral(first.getDataType());
}
@ -569,7 +571,7 @@ public class ExecutableFunctions {
}
@ExecFunction(name = "divide", argTypes = {"DECIMAL", "DECIMAL"}, returnType = "DECIMAL")
public static Literal divideDecimal(DecimalLiteral first, DecimalLiteral second) {
public static Expression divideDecimal(DecimalLiteral first, DecimalLiteral second) {
if (first.getValue().compareTo(BigDecimal.ZERO) == 0) {
return new NullLiteral(first.getDataType());
}
@ -581,7 +583,7 @@ public class ExecutableFunctions {
* decimalv3 divide in FE
*/
@ExecFunction(name = "divide", argTypes = {"DECIMALV3", "DECIMALV3"}, returnType = "DECIMALV3")
public static Literal divideDecimalV3(DecimalV3Literal first, DecimalV3Literal second) {
public static Expression divideDecimalV3(DecimalV3Literal first, DecimalV3Literal second) {
if (first.getValue().compareTo(BigDecimal.ZERO) == 0) {
return new NullLiteral(first.getDataType());
}
@ -591,224 +593,4 @@ public class ExecutableFunctions {
return new DecimalV3Literal(DecimalV3Type.createDecimalV3Type(
t1.getPrecision(), t1.getScale() - t2.getScale()), result);
}
@ExecFunction(name = "date_sub", argTypes = { "DATE", "INT" }, returnType = "DATE")
public static DateLiteral dateSub(DateLiteral date, IntegerLiteral day) throws AnalysisException {
return dateAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "date_sub", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral dateSub(DateTimeLiteral date, IntegerLiteral day) throws AnalysisException {
return dateAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "date_sub", argTypes = { "DATEV2", "INT" }, returnType = "DATEV2")
public static DateV2Literal dateSub(DateV2Literal date, IntegerLiteral day) throws AnalysisException {
return dateAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "date_sub", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal dateSub(DateTimeV2Literal date, IntegerLiteral day) throws AnalysisException {
return dateAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "date_add", argTypes = { "DATE", "INT" }, returnType = "DATE")
public static DateLiteral dateAdd(DateLiteral date, IntegerLiteral day) throws AnalysisException {
return daysAdd(date, day);
}
@ExecFunction(name = "date_add", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral dateAdd(DateTimeLiteral date, IntegerLiteral day) throws AnalysisException {
return daysAdd(date, day);
}
@ExecFunction(name = "date_add", argTypes = { "DATEV2", "INT" }, returnType = "DATEV2")
public static DateV2Literal dateAdd(DateV2Literal date, IntegerLiteral day) throws AnalysisException {
return daysAdd(date, day);
}
@ExecFunction(name = "date_add", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal dateAdd(DateTimeV2Literal date, IntegerLiteral day) throws AnalysisException {
return daysAdd(date, day);
}
@ExecFunction(name = "years_add", argTypes = { "DATE", "INT" }, returnType = "DATE")
public static DateLiteral yearsAdd(DateLiteral date, IntegerLiteral year) throws AnalysisException {
return date.plusYears(year.getValue());
}
@ExecFunction(name = "years_add", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral yearsAdd(DateTimeLiteral date, IntegerLiteral year) throws AnalysisException {
return date.plusYears(year.getValue());
}
@ExecFunction(name = "years_add", argTypes = { "DATEV2", "INT" }, returnType = "DATEV2")
public static DateV2Literal yearsAdd(DateV2Literal date, IntegerLiteral year) throws AnalysisException {
return date.plusYears(year.getValue());
}
@ExecFunction(name = "years_add", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal yearsAdd(DateTimeV2Literal date, IntegerLiteral year) throws AnalysisException {
return date.plusYears(year.getValue());
}
@ExecFunction(name = "months_add", argTypes = { "DATE", "INT" }, returnType = "DATE")
public static DateLiteral monthsAdd(DateLiteral date, IntegerLiteral month) throws AnalysisException {
return date.plusMonths(month.getValue());
}
@ExecFunction(name = "months_add", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral monthsAdd(DateTimeLiteral date, IntegerLiteral month) throws AnalysisException {
return date.plusMonths(month.getValue());
}
@ExecFunction(name = "months_add", argTypes = { "DATEV2", "INT" }, returnType = "DATEV2")
public static DateV2Literal monthsAdd(DateV2Literal date, IntegerLiteral month) throws AnalysisException {
return date.plusMonths(month.getValue());
}
@ExecFunction(name = "months_add", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal monthsAdd(DateTimeV2Literal date, IntegerLiteral month) throws AnalysisException {
return date.plusMonths(month.getValue());
}
@ExecFunction(name = "days_add", argTypes = { "DATE", "INT" }, returnType = "DATE")
public static DateLiteral daysAdd(DateLiteral date, IntegerLiteral day) throws AnalysisException {
return date.plusDays(day.getValue());
}
@ExecFunction(name = "days_add", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral daysAdd(DateTimeLiteral date, IntegerLiteral day) throws AnalysisException {
return date.plusDays(day.getValue());
}
@ExecFunction(name = "days_add", argTypes = { "DATEV2", "INT" }, returnType = "DATEV2")
public static DateV2Literal daysAdd(DateV2Literal date, IntegerLiteral day) throws AnalysisException {
return date.plusDays(day.getValue());
}
@ExecFunction(name = "days_add", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal daysAdd(DateTimeV2Literal date, IntegerLiteral day) throws AnalysisException {
return date.plusDays(day.getValue());
}
@ExecFunction(name = "hours_add", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral hoursAdd(DateTimeLiteral date, IntegerLiteral hour) throws AnalysisException {
return date.plusHours(hour.getValue());
}
@ExecFunction(name = "hours_add", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal hoursAdd(DateTimeV2Literal date, IntegerLiteral hour) throws AnalysisException {
return date.plusHours(hour.getValue());
}
@ExecFunction(name = "minutes_add", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral minutesAdd(DateTimeLiteral date, IntegerLiteral minute) throws AnalysisException {
return date.plusMinutes(minute.getValue());
}
@ExecFunction(name = "minutes_add", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal minutesAdd(DateTimeV2Literal date, IntegerLiteral minute) throws AnalysisException {
return date.plusMinutes(minute.getValue());
}
@ExecFunction(name = "seconds_add", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral secondsAdd(DateTimeLiteral date, IntegerLiteral second) throws AnalysisException {
return date.plusSeconds(second.getValue());
}
@ExecFunction(name = "seconds_add", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal secondsAdd(DateTimeV2Literal date, IntegerLiteral second) throws AnalysisException {
return date.plusSeconds(second.getValue());
}
@ExecFunction(name = "years_sub", argTypes = { "DATE", "INT" }, returnType = "DATE")
public static DateLiteral yearsSub(DateLiteral date, IntegerLiteral year) throws AnalysisException {
return yearsAdd(date, new IntegerLiteral(-year.getValue()));
}
@ExecFunction(name = "years_sub", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral yearsSub(DateTimeLiteral date, IntegerLiteral year) throws AnalysisException {
return yearsAdd(date, new IntegerLiteral(-year.getValue()));
}
@ExecFunction(name = "years_sub", argTypes = { "DATEV2", "INT" }, returnType = "DATEV2")
public static DateV2Literal yearsSub(DateV2Literal date, IntegerLiteral year) throws AnalysisException {
return yearsAdd(date, new IntegerLiteral(-year.getValue()));
}
@ExecFunction(name = "years_sub", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal yearsSub(DateTimeV2Literal date, IntegerLiteral year) throws AnalysisException {
return yearsAdd(date, new IntegerLiteral(-year.getValue()));
}
@ExecFunction(name = "months_sub", argTypes = { "DATE", "INT" }, returnType = "DATE")
public static DateLiteral monthsSub(DateLiteral date, IntegerLiteral month) throws AnalysisException {
return monthsAdd(date, new IntegerLiteral(-month.getValue()));
}
@ExecFunction(name = "months_sub", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral monthsSub(DateTimeLiteral date, IntegerLiteral month) throws AnalysisException {
return monthsAdd(date, new IntegerLiteral(-month.getValue()));
}
@ExecFunction(name = "months_sub", argTypes = { "DATEV2", "INT" }, returnType = "DATEV2")
public static DateV2Literal monthsSub(DateV2Literal date, IntegerLiteral month) throws AnalysisException {
return monthsAdd(date, new IntegerLiteral(-month.getValue()));
}
@ExecFunction(name = "months_sub", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal monthsSub(DateTimeV2Literal date, IntegerLiteral month) throws AnalysisException {
return monthsAdd(date, new IntegerLiteral(-month.getValue()));
}
@ExecFunction(name = "days_sub", argTypes = { "DATE", "INT" }, returnType = "DATE")
public static DateLiteral daysSub(DateLiteral date, IntegerLiteral day) throws AnalysisException {
return daysAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "days_sub", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral daysSub(DateTimeLiteral date, IntegerLiteral day) throws AnalysisException {
return daysAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "days_sub", argTypes = { "DATEV2", "INT" }, returnType = "DATEV2")
public static DateV2Literal daysSub(DateV2Literal date, IntegerLiteral day) throws AnalysisException {
return daysAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "days_sub", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal daysSub(DateTimeV2Literal date, IntegerLiteral day) throws AnalysisException {
return daysAdd(date, new IntegerLiteral(-day.getValue()));
}
@ExecFunction(name = "hours_sub", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral hoursSub(DateTimeLiteral date, IntegerLiteral hour) throws AnalysisException {
return hoursAdd(date, new IntegerLiteral(-hour.getValue()));
}
@ExecFunction(name = "hours_sub", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal hoursSub(DateTimeV2Literal date, IntegerLiteral hour) throws AnalysisException {
return hoursAdd(date, new IntegerLiteral(-hour.getValue()));
}
@ExecFunction(name = "minutes_sub", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral minutesSub(DateTimeLiteral date, IntegerLiteral minute) throws AnalysisException {
return minutesAdd(date, new IntegerLiteral(-minute.getValue()));
}
@ExecFunction(name = "minutes_sub", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal minutesSub(DateTimeV2Literal date, IntegerLiteral minute) throws AnalysisException {
return minutesAdd(date, new IntegerLiteral(-minute.getValue()));
}
@ExecFunction(name = "seconds_sub", argTypes = { "DATETIME", "INT" }, returnType = "DATETIME")
public static DateTimeLiteral secondsSub(DateTimeLiteral date, IntegerLiteral second) throws AnalysisException {
return secondsAdd(date, new IntegerLiteral(-second.getValue()));
}
@ExecFunction(name = "seconds_sub", argTypes = { "DATETIMEV2", "INT" }, returnType = "DATETIMEV2")
public static DateTimeV2Literal secondsSub(DateTimeV2Literal date, IntegerLiteral second) throws AnalysisException {
return secondsAdd(date, new IntegerLiteral(-second.getValue()));
}
}

View File

@ -48,7 +48,7 @@ public class SecondsSub extends ScalarFunction
);
public SecondsSub(Expression arg0, Expression arg1) {
super("Seconds_sub", arg0, arg1);
super("seconds_sub", arg0, arg1);
}
@Override

View File

@ -20,6 +20,7 @@ package org.apache.doris.nereids.trees.expressions.literal;
import org.apache.doris.analysis.LiteralExpr;
import org.apache.doris.catalog.Type;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DataType;
import org.apache.doris.nereids.types.DateType;
@ -44,7 +45,10 @@ public class DateLiteral extends Literal {
protected static DateTimeFormatter DATE_FORMATTER = null;
protected static DateTimeFormatter DATE_FORMATTER_TWO_DIGIT = null;
protected static DateTimeFormatter DATEKEY_FORMATTER = null;
// for cast datetime type to date type.
protected static DateTimeFormatter DATE_TIME_FORMATTER = null;
private static final LocalDateTime startOfAD = LocalDateTime.of(0, 1, 1, 0, 0, 0);
private static final LocalDateTime endOfAD = LocalDateTime.of(9999, 12, 31, 23, 59, 59);
private static final Logger LOG = LogManager.getLogger(DateLiteral.class);
private static final DateLiteral MIN_DATE = new DateLiteral(0000, 1, 1);
@ -61,6 +65,7 @@ public class DateLiteral extends Literal {
DATE_FORMATTER = DateUtils.formatBuilder("%Y-%m-%d").toFormatter();
DATEKEY_FORMATTER = DateUtils.formatBuilder("%Y%m%d").toFormatter();
DATE_FORMATTER_TWO_DIGIT = DateUtils.formatBuilder("%y-%m-%d").toFormatter();
DATE_TIME_FORMATTER = DateUtils.formatBuilder("%Y-%m-%d %H:%i:%s").toFormatter();
} catch (AnalysisException e) {
LOG.error("invalid date format", e);
System.exit(-1);
@ -114,6 +119,8 @@ public class DateLiteral extends Literal {
dateTime = DATE_FORMATTER_TWO_DIGIT.parse(s);
} else if (s.length() == DATEKEY_LENGTH && !s.contains("-")) {
dateTime = DATEKEY_FORMATTER.parse(s);
} else if (s.length() == 19) {
dateTime = DATE_TIME_FORMATTER.parse(s);
} else {
dateTime = DATE_FORMATTER.parse(s);
}
@ -143,6 +150,10 @@ public class DateLiteral extends Literal {
return false;
}
protected static boolean isDateOutOfRange(LocalDateTime dateTime) {
return dateTime.isBefore(startOfAD) || dateTime.isAfter(endOfAD);
}
@Override
public Long getValue() {
return (year * 10000 + month * 100 + day) * 1000000L;
@ -190,18 +201,25 @@ public class DateLiteral extends Literal {
return day;
}
public DateLiteral plusDays(int days) {
LocalDateTime dateTime = DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusDays(days);
return new DateLiteral(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth());
public Expression plusDays(int days) {
return fromJavaDateType(DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusDays(days));
}
public DateLiteral plusMonths(int months) {
LocalDateTime dateTime = DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusMonths(months);
return new DateLiteral(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth());
public Expression plusMonths(int months) {
return fromJavaDateType(DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusMonths(months));
}
public DateLiteral plusYears(int years) {
LocalDateTime dateTime = DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusYears(years);
return new DateLiteral(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth());
public Expression plusYears(int years) {
return fromJavaDateType(DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusYears(years));
}
public LocalDateTime toJavaDateType() {
return LocalDateTime.of(((int) getYear()), ((int) getMonth()), ((int) getDay()), 0, 0, 0);
}
public static Expression fromJavaDateType(LocalDateTime dateTime) {
return isDateOutOfRange(dateTime)
? new NullLiteral(DateType.INSTANCE)
: new DateLiteral(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth());
}
}

View File

@ -20,6 +20,7 @@ package org.apache.doris.nereids.trees.expressions.literal;
import org.apache.doris.analysis.LiteralExpr;
import org.apache.doris.catalog.Type;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.types.coercion.DateLikeType;
@ -44,8 +45,6 @@ import java.util.Objects;
* date time literal.
*/
public class DateTimeLiteral extends DateLiteral {
protected static DateTimeFormatter DATE_TIME_FORMATTER = null;
protected static DateTimeFormatter DATE_TIME_FORMATTER_TO_HOUR = null;
protected static DateTimeFormatter DATE_TIME_FORMATTER_TO_MINUTE = null;
protected static DateTimeFormatter DATE_TIME_FORMATTER_TWO_DIGIT = null;
@ -272,40 +271,28 @@ public class DateTimeLiteral extends DateLiteral {
return new org.apache.doris.analysis.DateLiteral(year, month, day, hour, minute, second, Type.DATETIME);
}
public DateTimeLiteral plusDays(int days) {
LocalDateTime d = DateUtils.getTime(DATE_TIME_FORMATTER, getStringValue()).plusDays(days);
return new DateTimeLiteral(d.getYear(), d.getMonthValue(), d.getDayOfMonth(),
d.getHour(), d.getMinute(), d.getSecond());
public Expression plusYears(int years) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER, getStringValue()).plusYears(years));
}
public DateTimeLiteral plusYears(int years) {
LocalDateTime d = DateUtils.getTime(DATE_TIME_FORMATTER, getStringValue()).plusYears(years);
return new DateTimeLiteral(d.getYear(), d.getMonthValue(), d.getDayOfMonth(),
d.getHour(), d.getMinute(), d.getSecond());
public Expression plusMonths(int months) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER, getStringValue()).plusMonths(months));
}
public DateTimeLiteral plusMonths(int months) {
LocalDateTime d = DateUtils.getTime(DATE_TIME_FORMATTER, getStringValue()).plusMonths(months);
return new DateTimeLiteral(d.getYear(), d.getMonthValue(), d.getDayOfMonth(),
d.getHour(), d.getMinute(), d.getSecond());
public Expression plusDays(int days) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER, getStringValue()).plusDays(days));
}
public DateTimeLiteral plusHours(int hours) {
LocalDateTime d = DateUtils.getTime(DATE_TIME_FORMATTER, getStringValue()).plusHours(hours);
return new DateTimeLiteral(d.getYear(), d.getMonthValue(), d.getDayOfMonth(),
d.getHour(), d.getMinute(), d.getSecond());
public Expression plusHours(int hours) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER, getStringValue()).plusHours(hours));
}
public DateTimeLiteral plusMinutes(int minutes) {
LocalDateTime d = DateUtils.getTime(DATE_TIME_FORMATTER, getStringValue()).plusMinutes(minutes);
return new DateTimeLiteral(d.getYear(), d.getMonthValue(), d.getDayOfMonth(),
d.getHour(), d.getMinute(), d.getSecond());
public Expression plusMinutes(int minutes) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER, getStringValue()).plusMinutes(minutes));
}
public DateTimeLiteral plusSeconds(int seconds) {
LocalDateTime d = DateUtils.getTime(DATE_TIME_FORMATTER, getStringValue()).plusSeconds(seconds);
return new DateTimeLiteral(d.getYear(), d.getMonthValue(), d.getDayOfMonth(),
d.getHour(), d.getMinute(), d.getSecond());
public Expression plusSeconds(long seconds) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER, getStringValue()).plusSeconds(seconds));
}
public long getHour() {
@ -331,4 +318,16 @@ public class DateTimeLiteral extends DateLiteral {
DateTimeLiteral other = (DateTimeLiteral) o;
return Objects.equals(getValue(), other.getValue());
}
public LocalDateTime toJavaDateType() {
return LocalDateTime.of(((int) getYear()), ((int) getMonth()), ((int) getDay()),
((int) getHour()), ((int) getMinute()), ((int) getSecond()));
}
public static Expression fromJavaDateType(LocalDateTime dateTime) {
return isDateOutOfRange(dateTime)
? new NullLiteral(DateTimeType.INSTANCE)
: new DateTimeLiteral(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth(),
dateTime.getHour(), dateTime.getMinute(), dateTime.getSecond());
}
}

View File

@ -19,6 +19,7 @@ package org.apache.doris.nereids.trees.expressions.literal;
import org.apache.doris.analysis.LiteralExpr;
import org.apache.doris.nereids.exceptions.UnboundException;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.util.DateUtils;
@ -38,6 +39,10 @@ public class DateTimeV2Literal extends DateTimeLiteral {
super(dateType, s);
}
public DateTimeV2Literal(long year, long month, long day, long hour, long minute, long second) {
super(DateTimeV2Type.SYSTEM_DEFAULT, year, month, day, hour, minute, second, 0);
}
public DateTimeV2Literal(long year, long month, long day, long hour, long minute, long second, long microSecond) {
super(DateTimeV2Type.SYSTEM_DEFAULT, year, month, day, hour, minute, second, microSecond);
}
@ -77,44 +82,59 @@ public class DateTimeV2Literal extends DateTimeLiteral {
}
@Override
public DateTimeV2Literal plusYears(int years) {
LocalDateTime d = DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue()).plusYears(years);
return new DateTimeV2Literal(this.getDataType(), d.getYear(), d.getMonthValue(), d.getDayOfMonth(),
d.getHour(), d.getMinute(), d.getSecond(), d.getNano() / 1000L);
public Expression plusYears(int years) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue())
.plusYears(years), getDataType().getScale());
}
@Override
public DateTimeV2Literal plusMonths(int months) {
LocalDateTime d = DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue()).plusMonths(months);
return new DateTimeV2Literal(this.getDataType(), d.getYear(), d.getMonthValue(), d.getDayOfMonth(),
d.getHour(), d.getMinute(), d.getSecond(), d.getNano() / 1000L);
public Expression plusMonths(int months) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue())
.plusMonths(months), getDataType().getScale());
}
@Override
public DateTimeV2Literal plusDays(int days) {
LocalDateTime d = DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue()).plusDays(days);
return new DateTimeV2Literal(this.getDataType(), d.getYear(), d.getMonthValue(), d.getDayOfMonth(),
d.getHour(), d.getMinute(), d.getSecond(), d.getNano() / 1000L);
public Expression plusDays(int days) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue())
.plusDays(days), getDataType().getScale());
}
@Override
public DateTimeV2Literal plusHours(int hours) {
LocalDateTime d = DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue()).plusHours(hours);
return new DateTimeV2Literal(this.getDataType(), d.getYear(), d.getMonthValue(), d.getDayOfMonth(),
d.getHour(), d.getMinute(), d.getSecond(), d.getNano() / 1000L);
public Expression plusHours(int hours) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue())
.plusHours(hours), getDataType().getScale());
}
@Override
public DateTimeV2Literal plusMinutes(int minutes) {
LocalDateTime d = DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue()).plusMinutes(minutes);
return new DateTimeV2Literal(this.getDataType(), d.getYear(), d.getMonthValue(), d.getDayOfMonth(),
d.getHour(), d.getMinute(), d.getSecond(), d.getNano() / 1000L);
public Expression plusMinutes(int minutes) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue())
.plusMinutes(minutes), getDataType().getScale());
}
@Override
public DateTimeV2Literal plusSeconds(int seconds) {
LocalDateTime d = DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue()).plusSeconds(seconds);
return new DateTimeV2Literal(this.getDataType(), d.getYear(), d.getMonthValue(), d.getDayOfMonth(),
d.getHour(), d.getMinute(), d.getSecond(), d.getNano() / 1000L);
public Expression plusSeconds(long seconds) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue())
.plusSeconds(seconds), getDataType().getScale());
}
public Expression plusMicroSeconds(int microSeconds) {
return fromJavaDateType(DateUtils.getTime(DATE_TIME_FORMATTER_TO_MICRO_SECOND, getStringValue())
.plusNanos(microSeconds * 1000L), getDataType().getScale());
}
public static Expression fromJavaDateType(LocalDateTime dateTime) {
return fromJavaDateType(dateTime, 0);
}
/**
* convert java LocalDateTime object to DateTimeV2Literal object.
*/
public static Expression fromJavaDateType(LocalDateTime dateTime, int precision) {
return isDateOutOfRange(dateTime)
? new NullLiteral(DateTimeV2Type.of(precision))
: new DateTimeV2Literal(DateTimeV2Type.of(precision),
dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth(),
dateTime.getHour(), dateTime.getMinute(), dateTime.getSecond(),
dateTime.getNano() / (long) Math.pow(10, 9 - precision));
}
}

View File

@ -20,6 +20,7 @@ package org.apache.doris.nereids.trees.expressions.literal;
import org.apache.doris.analysis.LiteralExpr;
import org.apache.doris.catalog.Type;
import org.apache.doris.nereids.exceptions.AnalysisException;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.visitor.ExpressionVisitor;
import org.apache.doris.nereids.types.DateV2Type;
import org.apache.doris.nereids.util.DateUtils;
@ -49,18 +50,21 @@ public class DateV2Literal extends DateLiteral {
return visitor.visitDateV2Literal(this, context);
}
public DateV2Literal plusDays(int days) {
LocalDateTime dateTime = DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusDays(days);
return new DateV2Literal(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth());
public Expression plusDays(int days) {
return fromJavaDateType(DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusDays(days));
}
public DateV2Literal plusMonths(int months) {
LocalDateTime dateTime = DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusMonths(months);
return new DateV2Literal(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth());
public Expression plusMonths(int months) {
return fromJavaDateType(DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusMonths(months));
}
public DateV2Literal plusYears(int years) {
LocalDateTime dateTime = DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusYears(years);
return new DateV2Literal(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth());
public Expression plusYears(int years) {
return fromJavaDateType(DateUtils.getTime(DATE_FORMATTER, getStringValue()).plusYears(years));
}
public static Expression fromJavaDateType(LocalDateTime dateTime) {
return isDateOutOfRange(dateTime)
? new NullLiteral(DateV2Type.INSTANCE)
: new DateV2Literal(dateTime.getYear(), dateTime.getMonthValue(), dateTime.getDayOfMonth());
}
}

View File

@ -180,7 +180,7 @@ public abstract class DataType implements AbstractDataType {
case "null_type": // ScalarType.NULL.toSql() return "null_type", so support it
return NullType.INSTANCE;
case "date":
return fromCatalogType(ScalarType.createDateType());
return DateType.INSTANCE;
case "datev2":
return DateV2Type.INSTANCE;
case "time":

View File

@ -59,6 +59,7 @@ import org.apache.doris.nereids.trees.expressions.literal.FloatLiteral;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.expressions.literal.LargeIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.trees.expressions.literal.NullLiteral;
import org.apache.doris.nereids.trees.expressions.literal.SmallIntLiteral;
import org.apache.doris.nereids.trees.expressions.literal.StringLikeLiteral;
import org.apache.doris.nereids.trees.expressions.literal.StringLiteral;
@ -227,7 +228,9 @@ public class TypeCoercionUtils {
* cast input type if input's datatype is not same with dateType.
*/
public static Expression castIfNotSameType(Expression input, DataType targetType) {
if (input.getDataType().equals(targetType) || isSubqueryAndDataTypeIsBitmap(input)
if (input.isNullLiteral()) {
return new NullLiteral(targetType);
} else if (input.getDataType().equals(targetType) || isSubqueryAndDataTypeIsBitmap(input)
|| (isVarCharOrStringType(input.getDataType())
&& isVarCharOrStringType(targetType))) {
return input;
@ -1011,7 +1014,7 @@ public class TypeCoercionUtils {
}
/**
* two types' common type, see {@link TypeCoercionUtilsTest#testFindPrimitiveCommonType()}
* two types' common type, see TypeCoercionUtilsTest#testFindCommonPrimitiveTypeForCaseWhen()
*/
@VisibleForTesting
protected static Optional<DataType> findCommonPrimitiveTypeForCaseWhen(DataType t1, DataType t2) {

View File

@ -412,7 +412,7 @@ public class CreateTableAsSelectStmtTest extends TestWithFeService {
ShowResultSet showResultSet = showCreateTableByName("test_default_timestamp");
Assertions.assertEquals("CREATE TABLE `test_default_timestamp` (\n"
+ " `userId` varchar(65533) NOT NULL,\n"
+ " `date` " + (Config.enable_date_conversion ? "datetimev2(0)" : "datetime")
+ " `date` datetime"
+ " NULL DEFAULT CURRENT_TIMESTAMP\n"
+ ") ENGINE=OLAP\n"
+ "DUPLICATE KEY(`userId`)\n"

View File

@ -18,21 +18,33 @@
package org.apache.doris.nereids.rules.expression;
import org.apache.doris.analysis.ArithmeticExpr.Operator;
import org.apache.doris.common.Config;
import org.apache.doris.nereids.analyzer.UnboundRelation;
import org.apache.doris.nereids.parser.NereidsParser;
import org.apache.doris.nereids.rules.expression.rules.FoldConstantRuleOnFE;
import org.apache.doris.nereids.rules.expression.rules.FunctionBinder;
import org.apache.doris.nereids.trees.expressions.Cast;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.GreaterThan;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.expressions.TimestampArithmetic;
import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeArithmetic;
import org.apache.doris.nereids.trees.expressions.functions.executable.DateTimeExtractAndTransform;
import org.apache.doris.nereids.trees.expressions.literal.DateLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeLiteral;
import org.apache.doris.nereids.trees.expressions.literal.DateTimeV2Literal;
import org.apache.doris.nereids.trees.expressions.literal.DateV2Literal;
import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
import org.apache.doris.nereids.trees.expressions.literal.Interval.TimeUnit;
import org.apache.doris.nereids.trees.expressions.literal.Literal;
import org.apache.doris.nereids.types.DateTimeType;
import org.apache.doris.nereids.trees.expressions.literal.VarcharLiteral;
import org.apache.doris.nereids.trees.plans.ObjectId;
import org.apache.doris.nereids.types.DateTimeV2Type;
import org.apache.doris.nereids.types.DoubleType;
import org.apache.doris.nereids.types.IntegerType;
import org.apache.doris.nereids.types.TinyIntType;
import org.apache.doris.nereids.util.MemoTestUtils;
import com.google.common.collect.ImmutableList;
import org.junit.jupiter.api.Assertions;
@ -64,12 +76,12 @@ public class FoldConstantTest extends ExpressionRewriteTestHelper {
executor = new ExpressionRuleExecutor(ImmutableList.of(FoldConstantRuleOnFE.INSTANCE));
assertRewriteAfterTypeCoercion("1 in (1,2,3,4)", "true");
// Type Coercion trans all to string.
assertRewriteAfterTypeCoercion("3 in ('1',2 + 8 / 2,3,4)", "true");
assertRewriteAfterTypeCoercion("4 / 2 * 1 - (5/2) in ('1',2 + 8 / 2,3,4)", "false");
assertRewriteAfterTypeCoercion("null in ('1',2 + 8 / 2,3,4)", "null");
assertRewriteAfterTypeCoercion("3 in ('1',null,3,4)", "true");
assertRewriteAfterTypeCoercion("TA in (1,null,3,4)", "TA in (1, null, 3, 4)");
assertRewriteAfterTypeCoercion("IA in (IB,IC,null)", "IA in (IB,IC,null)");
assertRewriteAfterTypeCoercion("3 in ('1', 2 + 8 / 2, 3, 4)", "true");
assertRewriteAfterTypeCoercion("4 / 2 * 1 - (5 / 2) in ('1', 2 + 8 / 2, 3, 4)", "false");
assertRewriteAfterTypeCoercion("null in ('1', 2 + 8 / 2, 3, 4)", "null");
assertRewriteAfterTypeCoercion("3 in ('1', null, 3, 4)", "true");
assertRewriteAfterTypeCoercion("TA in (1, null, 3, 4)", "TA in (1, null, 3, 4)");
assertRewriteAfterTypeCoercion("IA in (IB, IC, null)", "IA in (IB, IC, null)");
}
@Test
@ -191,17 +203,23 @@ public class FoldConstantTest extends ExpressionRewriteTestHelper {
executor = new ExpressionRuleExecutor(ImmutableList.of(FoldConstantRuleOnFE.INSTANCE));
String interval = "'1991-05-01' - interval 1 day";
Expression e7 = process((TimestampArithmetic) PARSER.parseExpression(interval));
Expression e8 = new DateTimeLiteral(1991, 4, 30, 0, 0, 0);
Expression e8 = Config.enable_date_conversion
? new DateTimeV2Literal(1991, 4, 30, 0, 0, 0)
: new DateTimeLiteral(1991, 4, 30, 0, 0, 0);
assertRewrite(e7, e8);
interval = "'1991-05-01' + interval '1' day";
e7 = process((TimestampArithmetic) PARSER.parseExpression(interval));
e8 = new DateTimeLiteral(1991, 5, 2, 0, 0, 0);
e8 = Config.enable_date_conversion
? new DateTimeV2Literal(1991, 5, 2, 0, 0, 0)
: new DateTimeLiteral(1991, 5, 2, 0, 0, 0);
assertRewrite(e7, e8);
interval = "'1991-05-01' + interval 1+1 day";
e7 = process((TimestampArithmetic) PARSER.parseExpression(interval));
e8 = new DateTimeLiteral(1991, 5, 3, 0, 0, 0);
e8 = Config.enable_date_conversion
? new DateTimeV2Literal(1991, 5, 3, 0, 0, 0)
: new DateTimeLiteral(1991, 5, 3, 0, 0, 0);
assertRewrite(e7, e8);
interval = "date '1991-05-01' + interval 10 / 2 + 1 day";
@ -211,41 +229,55 @@ public class FoldConstantTest extends ExpressionRewriteTestHelper {
interval = "interval '1' day + '1991-05-01'";
e7 = process((TimestampArithmetic) PARSER.parseExpression(interval));
e8 = new DateTimeLiteral(1991, 5, 2, 0, 0, 0);
e8 = Config.enable_date_conversion
? new DateTimeV2Literal(1991, 5, 2, 0, 0, 0)
: new DateTimeLiteral(1991, 5, 2, 0, 0, 0);
assertRewrite(e7, e8);
interval = "interval '3' month + '1991-05-01'";
e7 = process((TimestampArithmetic) PARSER.parseExpression(interval));
e8 = new DateTimeLiteral(1991, 8, 1, 0, 0, 0);
e8 = Config.enable_date_conversion
? new DateTimeV2Literal(1991, 8, 1, 0, 0, 0)
: new DateTimeLiteral(1991, 8, 1, 0, 0, 0);
assertRewrite(e7, e8);
interval = "interval 3 + 1 month + '1991-05-01'";
e7 = process((TimestampArithmetic) PARSER.parseExpression(interval));
e8 = new DateTimeLiteral(1991, 9, 1, 0, 0, 0);
e8 = Config.enable_date_conversion
? new DateTimeV2Literal(1991, 9, 1, 0, 0, 0)
: new DateTimeLiteral(1991, 9, 1, 0, 0, 0);
assertRewrite(e7, e8);
interval = "interval 3 + 1 year + '1991-05-01'";
e7 = process((TimestampArithmetic) PARSER.parseExpression(interval));
e8 = new DateTimeLiteral(1995, 5, 1, 0, 0, 0);
e8 = Config.enable_date_conversion
? new DateTimeV2Literal(1995, 5, 1, 0, 0, 0)
: new DateTimeLiteral(1995, 5, 1, 0, 0, 0);
assertRewrite(e7, e8);
interval = "interval 3 + 3 / 2 hour + '1991-05-01 10:00:00'";
e7 = process((TimestampArithmetic) PARSER.parseExpression(interval));
e8 = new DateTimeLiteral(1991, 5, 1, 14, 0, 0);
e8 = Config.enable_date_conversion
? new DateTimeV2Literal(1991, 5, 1, 14, 0, 0)
: new DateTimeLiteral(1991, 5, 1, 14, 0, 0);
assertRewrite(e7, e8);
interval = "interval 3 * 2 / 3 minute + '1991-05-01 10:00:00'";
e7 = process((TimestampArithmetic) PARSER.parseExpression(interval));
e8 = new DateTimeLiteral(1991, 5, 1, 10, 2, 0);
e8 = Config.enable_date_conversion
? new DateTimeV2Literal(1991, 5, 1, 10, 2, 0)
: new DateTimeLiteral(1991, 5, 1, 10, 2, 0);
assertRewrite(e7, e8);
interval = "interval 3 / 2 + 1 second + '1991-05-01 10:00:00'";
e7 = process((TimestampArithmetic) PARSER.parseExpression(interval));
e8 = new DateTimeLiteral(1991, 5, 1, 10, 0, 2);
e8 = Config.enable_date_conversion
? new DateTimeV2Literal(1991, 5, 1, 10, 0, 2)
: new DateTimeLiteral(1991, 5, 1, 10, 0, 2);
assertRewrite(e7, e8);
// a + interval 1 day
Slot a = SlotReference.of("a", DateTimeType.INSTANCE);
Slot a = SlotReference.of("a", DateTimeV2Type.SYSTEM_DEFAULT);
TimestampArithmetic arithmetic = new TimestampArithmetic(Operator.ADD, a, Literal.of(1), TimeUnit.DAY, false);
Expression process = process(arithmetic);
assertRewrite(process, process);
@ -261,4 +293,309 @@ public class FoldConstantTest extends ExpressionRewriteTestHelper {
}
return arithmetic.withFuncName(funcOpName.toLowerCase(Locale.ROOT));
}
@Test
public void testDateTypeDateTimeArithmeticFunctions() {
DateLiteral dateLiteral = new DateLiteral("1999-12-31");
IntegerLiteral integerLiteral = new IntegerLiteral(30);
VarcharLiteral format = new VarcharLiteral("%Y-%m-%d");
String[] answer = {
"2000-01-30", "1999-12-01", "2029-12-31", "1969-12-31",
"2002-06-30", "1997-06-30", "2000-01-30", "1999-12-01",
"1999", "4", "12", "6", "31", "365", "31",
"'1999-12-31'", "1999-12-27", "1999-12-31"
};
int answerIdx = 0;
Assertions.assertEquals(DateTimeArithmetic.dateAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.dateSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.yearsAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.yearsSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.monthsAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.monthsSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.daysAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.daysSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.year(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.quarter(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.month(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dayOfWeek(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dayOfMonth(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dayOfYear(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.day(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dateFormat(dateLiteral, format).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.toMonday(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.lastDay(dateLiteral).toSql(), answer[answerIdx]);
}
@Test
public void testDateTimeTypeDateTimeArithmeticFunctions() {
DateTimeLiteral dateLiteral = new DateTimeLiteral("1999-12-31 23:59:59");
IntegerLiteral integerLiteral = new IntegerLiteral(30);
VarcharLiteral format = new VarcharLiteral("%Y-%m-%d");
String[] answer = {
"2000-01-30 23:59:59", "1999-12-01 23:59:59", "2029-12-31 23:59:59", "1969-12-31 23:59:59",
"2002-06-30 23:59:59", "1997-06-30 23:59:59", "2000-01-30 23:59:59", "1999-12-01 23:59:59",
"2000-01-02 05:59:59", "1999-12-30 17:59:59", "2000-01-01 00:29:59",
"1999-12-31 23:29:59", "2000-01-01 00:00:29", "1999-12-31 23:59:29",
"1999", "4", "12", "6", "31", "365", "31", "23", "59", "59",
"'1999-12-31'", "1999-12-27", "1999-12-31", "1999-12-31", "730484", "1999-12-31"
};
int answerIdx = 0;
Assertions.assertEquals(DateTimeArithmetic.dateAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.dateSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.yearsAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.yearsSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.monthsAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.monthsSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.daysAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.daysSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.hoursAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.hoursSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.minutesAdd(dateLiteral, integerLiteral).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.minutesSub(dateLiteral, integerLiteral).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.secondsAdd(dateLiteral, integerLiteral).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.secondsSub(dateLiteral, integerLiteral).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.year(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.quarter(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.month(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dayOfWeek(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dayOfMonth(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dayOfYear(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.day(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.hour(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.minute(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.second(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dateFormat(dateLiteral, format).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.toMonday(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.lastDay(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.toDate(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.toDays(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.date(dateLiteral).toSql(), answer[answerIdx]);
}
@Test
public void testDateV2TypeDateTimeArithmeticFunctions() {
DateV2Literal dateLiteral = new DateV2Literal("1999-12-31");
IntegerLiteral integerLiteral = new IntegerLiteral(30);
VarcharLiteral format = new VarcharLiteral("%Y-%m-%d");
String[] answer = {
"2000-01-30", "1999-12-01", "2029-12-31", "1969-12-31",
"2002-06-30", "1997-06-30", "2000-01-30", "1999-12-01",
"1999", "4", "12", "6", "31", "365", "31",
"'1999-12-31'", "1999-12-27", "1999-12-31"
};
int answerIdx = 0;
Assertions.assertEquals(DateTimeArithmetic.dateAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.dateSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.yearsAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.yearsSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.monthsAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.monthsSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.daysAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.daysSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.year(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.quarter(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.month(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dayOfWeek(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dayOfMonth(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dayOfYear(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.day(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dateFormat(dateLiteral, format).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.toMonday(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.lastDay(dateLiteral).toSql(), answer[answerIdx]);
}
@Test
public void testDateTimeV2TypeDateTimeArithmeticFunctions() {
DateTimeV2Literal dateLiteral = new DateTimeV2Literal(DateTimeV2Type.SYSTEM_DEFAULT, "1999-12-31 23:59:59");
IntegerLiteral integerLiteral = new IntegerLiteral(30);
VarcharLiteral format = new VarcharLiteral("%Y-%m-%d");
String[] answer = {
"2000-01-30 23:59:59", "1999-12-01 23:59:59", "2029-12-31 23:59:59", "1969-12-31 23:59:59",
"2002-06-30 23:59:59", "1997-06-30 23:59:59", "2000-01-30 23:59:59", "1999-12-01 23:59:59",
"2000-01-02 05:59:59", "1999-12-30 17:59:59", "2000-01-01 00:29:59",
"1999-12-31 23:29:59", "2000-01-01 00:00:29", "1999-12-31 23:59:29", "1999-12-31 23:59:59",
"1999", "4", "12", "6", "31", "365", "31", "23", "59", "59",
"'1999-12-31'", "1999-12-27", "1999-12-31", "1999-12-31", "730484", "1999-12-31", "1999-12-31"
};
int answerIdx = 0;
Assertions.assertEquals(DateTimeArithmetic.dateAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.dateSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.yearsAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.yearsSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.monthsAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.monthsSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.daysAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.daysSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.hoursAdd(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.hoursSub(dateLiteral, integerLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.minutesAdd(dateLiteral, integerLiteral).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.minutesSub(dateLiteral, integerLiteral).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.secondsAdd(dateLiteral, integerLiteral).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.secondsSub(dateLiteral, integerLiteral).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeArithmetic.microSecondsAdd(dateLiteral, integerLiteral).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.year(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.quarter(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.month(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dayOfWeek(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dayOfMonth(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dayOfYear(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.day(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.hour(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.minute(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.second(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dateFormat(dateLiteral, format).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.toMonday(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.lastDay(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.toDate(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.toDays(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.date(dateLiteral).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dateV2(dateLiteral).toSql(), answer[answerIdx]);
}
@Test
public void testDateDiff() {
DateTimeLiteral dateTimeLiteral = new DateTimeLiteral("2001-12-31 00:00:01");
DateV2Literal dateV2Literal = new DateV2Literal("2001-12-31");
DateTimeV2Literal dateTimeV2Literal = new DateTimeV2Literal("2001-12-31 00:00:01");
DateTimeLiteral dateTimeLiteral1 = new DateTimeLiteral("2006-12-31 00:00:01");
DateV2Literal dateV2Literal1 = new DateV2Literal("2006-12-31");
DateTimeV2Literal dateTimeV2Literal1 = new DateTimeV2Literal("2006-12-31 01:00:01");
Assertions.assertEquals(DateTimeArithmetic.dateDiff(dateTimeLiteral, dateTimeLiteral1).toSql(), "-1826");
Assertions.assertEquals(DateTimeArithmetic.dateDiff(dateTimeLiteral1, dateTimeLiteral).toSql(), "1826");
Assertions.assertEquals(DateTimeArithmetic.dateDiff(dateV2Literal, dateV2Literal1).toSql(), "-1826");
Assertions.assertEquals(DateTimeArithmetic.dateDiff(dateV2Literal1, dateV2Literal).toSql(), "1826");
Assertions.assertEquals(DateTimeArithmetic.dateDiff(dateV2Literal, dateTimeV2Literal1).toSql(), "-1826");
Assertions.assertEquals(DateTimeArithmetic.dateDiff(dateTimeV2Literal1, dateV2Literal).toSql(), "1826");
Assertions.assertEquals(DateTimeArithmetic.dateDiff(dateTimeV2Literal, dateV2Literal1).toSql(), "-1826");
Assertions.assertEquals(DateTimeArithmetic.dateDiff(dateV2Literal1, dateTimeV2Literal).toSql(), "1826");
Assertions.assertEquals(DateTimeArithmetic.dateDiff(dateTimeV2Literal, dateTimeV2Literal1).toSql(), "-1826");
Assertions.assertEquals(DateTimeArithmetic.dateDiff(dateTimeV2Literal1, dateTimeV2Literal).toSql(), "1826");
}
@Test
public void testDateTrunc() {
DateTimeLiteral dateTimeLiteral = new DateTimeLiteral("2001-12-31 01:01:01");
DateTimeV2Literal dateTimeV2Literal = new DateTimeV2Literal("2001-12-31 01:01:01");
String[] tags = {"year", "month", "day", "hour", "minute", "second"};
String[] answer = {
"2001-01-01 00:00:00", "2001-01-01 00:00:00", "2001-12-01 00:00:00", "2001-12-01 00:00:00",
"2001-12-31 00:00:00", "2001-12-31 00:00:00", "2001-12-31 01:00:00", "2001-12-31 01:00:00",
"2001-12-31 01:01:00", "2001-12-31 01:01:00", "2001-12-31 01:01:01", "2001-12-31 01:01:01",
"2001-01-01 00:00:00", "2001-01-01 00:00:00", "2001-01-01 00:00:00",
"2001-04-01 00:00:00", "2001-04-01 00:00:00", "2001-04-01 00:00:00",
"2001-07-01 00:00:00", "2001-07-01 00:00:00", "2001-07-01 00:00:00",
"2001-10-01 00:00:00", "2001-10-01 00:00:00", "2001-10-01 00:00:00",
"2001-01-15 00:00:00", "2001-02-12 00:00:00", "2001-03-12 00:00:00",
};
int answerIdx = 0;
for (String tag : tags) {
Assertions.assertEquals(DateTimeExtractAndTransform.dateTrunc(dateTimeLiteral, new VarcharLiteral(tag)).toSql(),
answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.dateTrunc(dateTimeV2Literal, new VarcharLiteral(tag)).toSql(),
answer[answerIdx++]);
}
VarcharLiteral quarter = new VarcharLiteral("quarter");
for (int i = 1; i != 13; ++i) {
Assertions.assertEquals(DateTimeExtractAndTransform.dateTrunc(
new DateTimeLiteral(2001, i, 15, 0, 0, 0), quarter).toSql(), answer[answerIdx++]);
}
VarcharLiteral week = new VarcharLiteral("week");
for (int i = 1; i != 4; ++i) {
Assertions.assertEquals(DateTimeExtractAndTransform.dateTrunc(
new DateTimeLiteral(2001, i, 15, 0, 0, 0), week).toSql(), answer[answerIdx++]);
}
}
@Test
public void testDateConstructFunction() {
String[] answer = {
"2001-07-19", "6411-08-17", "0000-01-01", "'1977-06-03 17:57:24'",
"'1977-06-03'", "1008909293", "1008864000"
};
int answerIdx = 0;
Assertions.assertEquals(DateTimeExtractAndTransform.makeDate(
new IntegerLiteral(2001),
new IntegerLiteral(200)
).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.fromDays(
new IntegerLiteral(2341798)
).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.fromDays(
new IntegerLiteral(1)
).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.fromUnixTime(
new IntegerLiteral(234179844)
).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.fromUnixTime(
new IntegerLiteral(234179844),
new VarcharLiteral("%Y-%m-%d")
).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.unixTimestamp(
new DateTimeLiteral("2001-12-21 12:34:53")
).toSql(), answer[answerIdx++]);
Assertions.assertEquals(DateTimeExtractAndTransform.unixTimestamp(
new VarcharLiteral("2001-12-21"),
new VarcharLiteral("%Y-%m-%d")
).toSql(), answer[answerIdx]);
}
@Test
public void testFoldNestedExpression() {
assertRewriteExpression("makedate(year('2010-04-10'), dayofyear('2010-04-11'))", "2010-04-11");
assertRewriteExpression("null in ('d', null)", "NULL");
assertRewriteExpression("null not in ('d', null)", "NULL");
assertRewriteExpression("'a' in ('d', null)", "NULL");
assertRewriteExpression("'a' not in ('d', null)", "NULL");
assertRewriteExpression("'a' in ('d', 'c')", "FALSE");
assertRewriteExpression("'a' not in ('d', 'c')", "TRUE");
assertRewriteExpression("'d' in ('d', 'c')", "TRUE");
assertRewriteExpression("'d' not in ('d', 'c')", "FALSE");
assertRewriteExpression("1 in (2, NULL, 3)", "NULL");
}
private void assertRewriteExpression(String actualExpression, String expectedExpression) {
ExpressionRewriteContext context = new ExpressionRewriteContext(
MemoTestUtils.createCascadesContext(new UnboundRelation(new ObjectId(1), ImmutableList.of("test_table"))));
NereidsParser parser = new NereidsParser();
Expression e1 = parser.parseExpression(actualExpression);
e1 = new ExpressionNormalization().rewrite(FunctionBinder.INSTANCE.rewrite(e1, context), context);
Assertions.assertEquals(e1.toSql(), expectedExpression);
}
}

View File

@ -98,8 +98,7 @@ public class DataTypeTest {
Assertions.assertEquals(NullType.INSTANCE, DataType.convertFromString("null"));
Assertions.assertEquals(NullType.INSTANCE, DataType.convertFromString("null_type"));
// date
Assertions.assertEquals(Config.enable_date_conversion ? DateV2Type.INSTANCE : DateType.INSTANCE,
DataType.convertFromString("date"));
Assertions.assertEquals(DateType.INSTANCE, DataType.convertFromString("date"));
// datev2
Assertions.assertEquals(DateV2Type.INSTANCE, DataType.convertFromString("datev2"));
// time

View File

@ -1685,7 +1685,7 @@ public class QueryPlanTest extends TestWithFeService {
sql = "select day from tbl_int_date where day = '2020-10-30 10:00:01.111111'";
explainString = getSQLPlanOrErrorMsg("EXPLAIN " + sql);
Assert.assertTrue(explainString.contains(Config.enable_date_conversion
? "PREDICATES: `day` = '2020-10-30 10:00:01.111111'"
? "VEMPTYSET"
: "PREDICATES: `day` = '2020-10-30 10:00:01'"));
//invalid date
@ -1861,7 +1861,7 @@ public class QueryPlanTest extends TestWithFeService {
+ " \"max_file_size\" = \"500MB\" );";
String explainStr = getSQLPlanOrErrorMsg("EXPLAIN " + sql);
if (Config.enable_date_conversion) {
Assert.assertTrue(explainStr.contains("PREDICATES: `date` >= '2021-10-07',"
Assert.assertTrue(explainStr.contains("PREDICATES: `date` >= '2021-10-07' AND"
+ " `date` <= '2021-10-11'"));
} else {
Assert.assertTrue(explainStr.contains("PREDICATES: `date` >= '2021-10-07 00:00:00' AND"

View File

@ -1,49 +1,49 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !point_select --
1 2017-10-01 2017-10-01 2017-10-01 11:11:11.021 2017-10-01 11:11:11.011000 Beijing 10 1 2020-01-01T00:00 2020-01-01T00:00 2017-10-01 11:11:11.170 2017-10-01 11:11:11.110111 2020-01-01T00:00 1 30 20
1 2017-10-01 2017-10-01 2017-10-01 11:11:11.021 2017-10-01 11:11:11.011000 Beijing 10 1 2020-01-01 00:00:00 2020-01-01 00:00:00 2017-10-01 11:11:11.170 2017-10-01 11:11:11.110111 2020-01-01 00:00:00 1 30 20
-- !point_select --
1 2017-10-01 2017-10-01 2017-10-01 11:11:11.022 2017-10-01 11:11:11.012000 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2017-10-01 11:11:11.160 2017-10-01 11:11:11.100111 2020-01-02T00:00 1 31 19
1 2017-10-01 2017-10-01 2017-10-01 11:11:11.022 2017-10-01 11:11:11.012000 Beijing 10 1 2020-01-02 00:00:00 2020-01-02 00:00:00 2017-10-01 11:11:11.160 2017-10-01 11:11:11.100111 2020-01-02 00:00:00 1 31 19
-- !point_select --
2 2017-10-01 2017-10-01 2017-10-01 11:11:11.023 2017-10-01 11:11:11.013000 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2017-10-01 11:11:11.150 2017-10-01 11:11:11.130111 2020-01-02T00:00 1 31 21
2 2017-10-01 2017-10-01 2017-10-01 11:11:11.023 2017-10-01 11:11:11.013000 Beijing 10 1 2020-01-02 00:00:00 2020-01-02 00:00:00 2017-10-01 11:11:11.150 2017-10-01 11:11:11.130111 2020-01-02 00:00:00 1 31 21
-- !point_select --
2 2017-10-01 2017-10-01 2017-10-01 11:11:11.024 2017-10-01 11:11:11.014000 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2017-10-01 11:11:11.140 2017-10-01 11:11:11.120111 2020-01-03T00:00 1 32 20
2 2017-10-01 2017-10-01 2017-10-01 11:11:11.024 2017-10-01 11:11:11.014000 Beijing 10 1 2020-01-03 00:00:00 2020-01-03 00:00:00 2017-10-01 11:11:11.140 2017-10-01 11:11:11.120111 2020-01-03 00:00:00 1 32 20
-- !point_select --
3 2017-10-01 2017-10-01 2017-10-01 11:11:11.025 2017-10-01 11:11:11.015000 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2017-10-01 11:11:11.100 2017-10-01 11:11:11.140111 2020-01-03T00:00 1 32 22
3 2017-10-01 2017-10-01 2017-10-01 11:11:11.025 2017-10-01 11:11:11.015000 Beijing 10 1 2020-01-03 00:00:00 2020-01-03 00:00:00 2017-10-01 11:11:11.100 2017-10-01 11:11:11.140111 2020-01-03 00:00:00 1 32 22
-- !point_select --
3 2017-10-01 2017-10-01 2017-10-01 11:11:11.026 2017-10-01 11:11:11.016000 Beijing 10 1 2020-01-04T00:00 2020-01-04T00:00 2017-10-01 11:11:11.110 2017-10-01 11:11:11.150111 2020-01-04T00:00 1 33 21
3 2017-10-01 2017-10-01 2017-10-01 11:11:11.026 2017-10-01 11:11:11.016000 Beijing 10 1 2020-01-04 00:00:00 2020-01-04 00:00:00 2017-10-01 11:11:11.110 2017-10-01 11:11:11.150111 2020-01-04 00:00:00 1 33 21
-- !point_select --
3 2017-10-01 2017-10-01 2017-10-01 11:11:11.027 2017-10-01 11:11:11.017000 Beijing 10 1 \N \N \N \N 2020-01-05T00:00 1 34 20
3 2017-10-01 2017-10-01 2017-10-01 11:11:11.027 2017-10-01 11:11:11.017000 Beijing 10 1 \N \N \N \N 2020-01-05 00:00:00 1 34 20
-- !point_select --
4 2017-10-01 2017-10-01 2017-10-01 11:11:11.028 2017-10-01 11:11:11.018000 Beijing 10 1 \N \N \N \N 2020-01-05T00:00 1 34 20
4 2017-10-01 2017-10-01 2017-10-01 11:11:11.028 2017-10-01 11:11:11.018000 Beijing 10 1 \N \N \N \N 2020-01-05 00:00:00 1 34 20
-- !point_select --
1 2017-10-01 2017-10-01 2017-10-01 11:11:11.021 2017-10-01 11:11:11.011000 Beijing 10 1 2020-01-01T00:00 2020-01-01T00:00 2017-10-01 11:11:11.170 2017-10-01 11:11:11.110111 2020-01-01T00:00 1 30 20
1 2017-10-01 2017-10-01 2017-10-01 11:11:11.021 2017-10-01 11:11:11.011000 Beijing 10 1 2020-01-01 00:00:00 2020-01-01 00:00:00 2017-10-01 11:11:11.170 2017-10-01 11:11:11.110111 2020-01-01 00:00:00 1 30 20
-- !point_select --
1 2017-10-01 2017-10-01 2017-10-01 11:11:11.022 2017-10-01 11:11:11.012000 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2017-10-01 11:11:11.160 2017-10-01 11:11:11.100111 2020-01-02T00:00 1 31 19
1 2017-10-01 2017-10-01 2017-10-01 11:11:11.022 2017-10-01 11:11:11.012000 Beijing 10 1 2020-01-02 00:00:00 2020-01-02 00:00:00 2017-10-01 11:11:11.160 2017-10-01 11:11:11.100111 2020-01-02 00:00:00 1 31 19
-- !point_select --
2 2017-10-01 2017-10-01 2017-10-01 11:11:11.023 2017-10-01 11:11:11.013000 Beijing 10 1 2020-01-02T00:00 2020-01-02T00:00 2017-10-01 11:11:11.150 2017-10-01 11:11:11.130111 2020-01-02T00:00 1 31 21
2 2017-10-01 2017-10-01 2017-10-01 11:11:11.023 2017-10-01 11:11:11.013000 Beijing 10 1 2020-01-02 00:00:00 2020-01-02 00:00:00 2017-10-01 11:11:11.150 2017-10-01 11:11:11.130111 2020-01-02 00:00:00 1 31 21
-- !point_select --
2 2017-10-01 2017-10-01 2017-10-01 11:11:11.024 2017-10-01 11:11:11.014000 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2017-10-01 11:11:11.140 2017-10-01 11:11:11.120111 2020-01-03T00:00 1 32 20
2 2017-10-01 2017-10-01 2017-10-01 11:11:11.024 2017-10-01 11:11:11.014000 Beijing 10 1 2020-01-03 00:00:00 2020-01-03 00:00:00 2017-10-01 11:11:11.140 2017-10-01 11:11:11.120111 2020-01-03 00:00:00 1 32 20
-- !point_select --
3 2017-10-01 2017-10-01 2017-10-01 11:11:11.025 2017-10-01 11:11:11.015000 Beijing 10 1 2020-01-03T00:00 2020-01-03T00:00 2017-10-01 11:11:11.100 2017-10-01 11:11:11.140111 2020-01-03T00:00 1 32 22
3 2017-10-01 2017-10-01 2017-10-01 11:11:11.025 2017-10-01 11:11:11.015000 Beijing 10 1 2020-01-03 00:00:00 2020-01-03 00:00:00 2017-10-01 11:11:11.100 2017-10-01 11:11:11.140111 2020-01-03 00:00:00 1 32 22
-- !point_select --
3 2017-10-01 2017-10-01 2017-10-01 11:11:11.026 2017-10-01 11:11:11.016000 Beijing 10 1 2020-01-04T00:00 2020-01-04T00:00 2017-10-01 11:11:11.110 2017-10-01 11:11:11.150111 2020-01-04T00:00 1 33 21
3 2017-10-01 2017-10-01 2017-10-01 11:11:11.026 2017-10-01 11:11:11.016000 Beijing 10 1 2020-01-04 00:00:00 2020-01-04 00:00:00 2017-10-01 11:11:11.110 2017-10-01 11:11:11.150111 2020-01-04 00:00:00 1 33 21
-- !point_select --
3 2017-10-01 2017-10-01 2017-10-01 11:11:11.027 2017-10-01 11:11:11.017000 Beijing 10 1 \N \N \N \N 2020-01-05T00:00 1 34 20
3 2017-10-01 2017-10-01 2017-10-01 11:11:11.027 2017-10-01 11:11:11.017000 Beijing 10 1 \N \N \N \N 2020-01-05 00:00:00 1 34 20
-- !point_select --
4 2017-10-01 2017-10-01 2017-10-01 11:11:11.028 2017-10-01 11:11:11.018000 Beijing 10 1 \N \N \N \N 2020-01-05T00:00 1 34 20
4 2017-10-01 2017-10-01 2017-10-01 11:11:11.028 2017-10-01 11:11:11.018000 Beijing 10 1 \N \N \N \N 2020-01-05 00:00:00 1 34 20

View File

@ -12,9 +12,9 @@ internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_double
internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_decimal 10 \N YES decimal \N \N 20 3 \N \N \N decimal(20, 3) 20 3 \N \N
internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_decimalv3 11 \N YES decimal \N \N 20 3 \N \N \N decimalv3(20, 3) 20 3 \N \N
internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_date 12 \N YES date \N \N \N \N \N \N \N date \N \N \N \N
internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_datetime 13 \N YES datetime \N \N \N \N \N \N \N datetime \N \N \N \N
internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_datev2 14 \N YES date \N \N \N \N \N \N \N datev2 \N \N \N \N
internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_datetimev2 15 \N YES datetime \N \N 18 0 \N \N \N datetimev2(0) \N 0 \N \N
internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_datetime 13 \N YES datetime \N \N 18 0 \N \N \N datetime \N 0 \N \N
internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_datev2 14 \N YES date \N \N \N \N \N \N \N date \N \N \N \N
internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_datetimev2 15 \N YES datetime \N \N 18 0 \N \N \N datetime \N 0 \N \N
internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_char 16 \N YES char 15 60 \N \N \N \N \N char(15) 15 \N \N \N
internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_varchar 17 \N YES varchar 100 400 \N \N \N \N \N varchar(100) 100 \N \N \N
internal regression_test_datatype_p0_scalar_types tbl_scalar_types_dup c_string 18 \N YES varchar 2147483643 8589934572 \N \N \N \N \N string 2147483643 \N \N \N

View File

@ -1,57 +1,56 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !q04 --
[2008-09-19 06:15:41, 2008-09-19 06:28:51, 2008-09-19 06:29:53, 2008-09-19 07:25:27, 2008-09-19 10:10:05, 2009-02-27 00:27:14] ['Misplaced (13710)', 'Justin Bozonier (9401)', 'Petr Macek (15045)', 'n1x0nad', 'Mladen Mihajlovic (11421)', 'Saem (68131)']
[2008-09-19 06:26:10, 2008-09-19 06:32:58, 2008-09-19 06:45:40, 2008-09-19 07:01:58, 2014-02-24 21:20:49, 2015-08-10 23:28:09, 2016-03-01 19:48:34, 2011-06-21 16:30:26, 2011-07-05 11:29:50, 2011-08-08 19:35:40] ['Jerub (14648)', 'Matthias Kestenholz (317346)', 'Antti Rasinen (8570)', 'Thomas Wouters (17624)', 'Craig (1489354)', 'Aaron Hall (541136)', 'Ethan Furman (208880)', 'kindall (416467)', 'e-satis (9951)', 'espeed (161085)']
[2009-06-16 07:49:19, 2009-06-16 07:49:57, 2009-06-16 08:02:48, 2009-06-16 08:10:20, 2009-06-16 08:20:10, 2009-06-16 08:30:09, 2009-06-16 08:30:33, 2009-06-16 08:40:07, 2009-06-16 08:50:31, 2009-06-16 09:39:52] ['paxdiablo (14860)', 'Dutow (73657)', 'DShook (370)', 'Roddy (1737)', 'bill (121958)', 'henrikpp (1442)', 'Martin Schuhfuß (123219)', 'finnw (12048)', 'Christoffer (15514)', 'Skizz (1898)']
[2009-06-16 08:04:28, 2013-04-19 14:38:22, 2013-05-30 15:05:21, 2013-08-16 03:59:06, 2015-02-13 16:10:42, 2015-05-26 14:34:08, 2015-10-20 09:39:29, 2010-08-10 09:36:43, 2010-08-20 21:43:03, 2011-02-04 14:15:19, 2011-02-25 14:29:47, 2011-06-13 04:48:04, 2011-07-12 01:38:48, 2011-07-20 20:27:34, 2011-08-22 22:23:33] ['Thomas Levesque (98713)', 'karma (2299633)', 'Paul Solomenchuk (1934361)', 'Evgeny Bechkalo (419292)', 'Fahad Owais (4564116)', 'JustinMichel (1469095)', 'Chaitanya Kadamati (4402011)', 'nabeelfarid (288746)', 'Delta (327104)', 'bstoney (70716)', 'Steve Greatrex (261782)', 'Wes (539993)', 'Arthur Nunes (702828)', 'Devgig (331850)', 'Bas (668272)']
[2009-06-16 08:22:28, 2009-06-16 11:27:20, 2009-06-17 06:08:22, 2013-08-27 22:22:34] ['jitter (122428)', 'tim (2986)', 'rik.the.vik (45570)', 'neowulf33 (1216965)']
[2009-06-16 07:45:58, 2009-06-16 07:59:15, 2009-06-16 08:07:41, 2009-06-16 08:08:14, 2014-03-04 19:32:41] ['Pondidum (1500)', 'Jason Punyon (6212)', 'Igal Tabachnik (8205)', 'Dun3 (66466)', 'user922020 (922020)']
[2009-06-16 07:52:30, 2009-06-16 07:52:40, 2009-06-16 07:53:12, 2009-06-16 07:54:24, 2009-06-16 07:59:59, 2009-06-16 08:00:54, 2009-06-16 08:11:29, 2009-06-16 08:20:49, 2011-11-22 16:53:05] ['Marco van de Voort (99354)', 'unwind (28169)', 'Sev (83819)', 'LeopardSkinPillBoxHat (22489)', 'Degvik (26276)', 'Aditya Sehgal (95321)', 'knittl (112968)', 'pmr (105672)', 'ALOK KUMAR mca sathyabama univ (1060252)']
[2009-06-16 08:01:45, 2009-06-16 08:06:39, 2009-06-16 11:01:03, 2012-07-03 10:27:52, 2012-09-14 17:11:23, 2010-05-07 15:27:46, 2010-05-07 15:40:31] ['Mischa Kroon (30600)', 'Michał Chaniewski (119800)', 'Richard (67392)', 'bresleveloper (1369989)', 'Mohammad Shahnawaz (1672032)', 'kacalapy (352157)', 'Lance May (312294)']
[2009-06-16 08:12:50, 2009-06-16 08:17:17, 2009-06-16 09:15:53, 2009-06-16 12:23:04, 2009-06-16 22:56:34, 2009-06-17 02:10:19, 2009-06-17 03:06:53] ['PaulJWilliams (71399)', 'Anurag Uniyal (6946)', 'brian d foy (2766176)', 'Jared (14744)', 'ymir (96448)', 'vulcan_hacker (121659)', 'spiffyman (102467)']
[2009-06-16 08:30:25, 2009-06-16 09:00:16, 2014-07-21 12:39:38, 2010-05-14 16:18:03] ['ShiDoiSi (60462)', 'Jonas (24946)', 'The Dude (1171465)', 'BMeph (140483)']
[2008-09-19 06:15:41, 2008-09-19 06:28:51, 2008-09-19 06:29:53, 2008-09-19 07:25:28, 2008-09-19 10:10:05, 2009-02-27 00:27:14] ['Misplaced (13710)', 'Justin Bozonier (9401)', 'Petr Macek (15045)', 'n1x0nad', 'Mladen Mihajlovic (11421)', 'Saem (68131)']
[2008-09-19 06:26:11, 2008-09-19 06:32:58, 2008-09-19 06:45:40, 2008-09-19 07:01:59, 2014-02-24 21:20:49, 2015-08-10 23:28:09, 2016-03-01 19:48:35, 2011-06-21 16:30:27, 2011-07-05 11:29:51, 2011-08-08 19:35:41] ['Jerub (14648)', 'Matthias Kestenholz (317346)', 'Antti Rasinen (8570)', 'Thomas Wouters (17624)', 'Craig (1489354)', 'Aaron Hall (541136)', 'Ethan Furman (208880)', 'kindall (416467)', 'e-satis (9951)', 'espeed (161085)']
[2009-06-16 07:49:19, 2009-06-16 07:49:57, 2009-06-16 08:02:49, 2009-06-16 08:10:21, 2009-06-16 08:20:10, 2009-06-16 08:30:10, 2009-06-16 08:30:34, 2009-06-16 08:40:07, 2009-06-16 08:50:32, 2009-06-16 09:39:52] ['paxdiablo (14860)', 'Dutow (73657)', 'DShook (370)', 'Roddy (1737)', 'bill (121958)', 'henrikpp (1442)', 'Martin Schuhfuß (123219)', 'finnw (12048)', 'Christoffer (15514)', 'Skizz (1898)']
[2009-06-16 08:04:28, 2013-04-19 14:38:22, 2013-05-30 15:05:22, 2013-08-16 03:59:06, 2015-02-13 16:10:43, 2015-05-26 14:34:08, 2015-10-20 09:39:30, 2010-08-10 09:36:43, 2010-08-20 21:43:04, 2011-02-04 14:15:19, 2011-02-25 14:29:48, 2011-06-13 04:48:04, 2011-07-12 01:38:49, 2011-07-20 20:27:34, 2011-08-22 22:23:34] ['Thomas Levesque (98713)', 'karma (2299633)', 'Paul Solomenchuk (1934361)', 'Evgeny Bechkalo (419292)', 'Fahad Owais (4564116)', 'JustinMichel (1469095)', 'Chaitanya Kadamati (4402011)', 'nabeelfarid (288746)', 'Delta (327104)', 'bstoney (70716)', 'Steve Greatrex (261782)', 'Wes (539993)', 'Arthur Nunes (702828)', 'Devgig (331850)', 'Bas (668272)']
[2009-06-16 08:22:29, 2009-06-16 11:27:20, 2009-06-17 06:08:22, 2013-08-27 22:22:35] ['jitter (122428)', 'tim (2986)', 'rik.the.vik (45570)', 'neowulf33 (1216965)']
[2009-06-16 07:45:59, 2009-06-16 07:59:15, 2009-06-16 08:07:41, 2009-06-16 08:08:14, 2014-03-04 19:32:41] ['Pondidum (1500)', 'Jason Punyon (6212)', 'Igal Tabachnik (8205)', 'Dun3 (66466)', 'user922020 (922020)']
[2009-06-16 07:52:31, 2009-06-16 07:52:40, 2009-06-16 07:53:12, 2009-06-16 07:54:24, 2009-06-16 08:00:00, 2009-06-16 08:00:55, 2009-06-16 08:11:29, 2009-06-16 08:20:50, 2011-11-22 16:53:06] ['Marco van de Voort (99354)', 'unwind (28169)', 'Sev (83819)', 'LeopardSkinPillBoxHat (22489)', 'Degvik (26276)', 'Aditya Sehgal (95321)', 'knittl (112968)', 'pmr (105672)', 'ALOK KUMAR mca sathyabama univ (1060252)']
[2009-06-16 08:01:45, 2009-06-16 08:06:40, 2009-06-16 11:01:03, 2012-07-03 10:27:52, 2012-09-14 17:11:24, 2010-05-07 15:27:47, 2010-05-07 15:40:32] ['Mischa Kroon (30600)', 'Michał Chaniewski (119800)', 'Richard (67392)', 'bresleveloper (1369989)', 'Mohammad Shahnawaz (1672032)', 'kacalapy (352157)', 'Lance May (312294)']
[2009-06-16 08:12:51, 2009-06-16 08:17:18, 2009-06-16 09:15:53, 2009-06-16 12:23:04, 2009-06-16 22:56:35, 2009-06-17 02:10:19, 2009-06-17 03:06:53] ['PaulJWilliams (71399)', 'Anurag Uniyal (6946)', 'brian d foy (2766176)', 'Jared (14744)', 'ymir (96448)', 'vulcan_hacker (121659)', 'spiffyman (102467)']
[2009-06-16 08:30:25, 2009-06-16 09:00:17, 2014-07-21 12:39:38, 2010-05-14 16:18:04] ['ShiDoiSi (60462)', 'Jonas (24946)', 'The Dude (1171465)', 'BMeph (140483)']
-- !q04_2 --
2012-04-06T16:26:51 10014510 PHP Unique Situation. Remove Duplicates From Array Before Sent to Function Inside Loop
-- !q04_3 --
10000069 Extending javascript function scope
-- !q04_4 --
[2008-09-19 06:15:41, 2008-09-19 06:28:51, 2008-09-19 06:29:53, 2008-09-19 07:25:27, 2008-09-19 10:10:05, 2009-02-27 00:27:14]
[2008-09-19 06:26:10, 2008-09-19 06:32:58, 2008-09-19 06:45:40, 2008-09-19 07:01:58, 2014-02-24 21:20:49, 2015-08-10 23:28:09, 2016-03-01 19:48:34, 2011-06-21 16:30:26, 2011-07-05 11:29:50, 2011-08-08 19:35:40]
[2008-09-19 06:38:11, 2008-09-19 10:24:25]
[2009-06-16 07:33:12, 2015-01-23 18:36:18]
[2009-06-16 07:39:12, 2009-06-16 07:50:54, 2009-08-04 12:54:42]
[2009-06-16 07:41:07, 2009-06-16 07:59:14, 2009-06-16 08:16:33]
[2009-06-16 07:42:52, 2009-06-16 07:43:51, 2009-06-16 07:43:54]
[2008-09-19 06:15:41, 2008-09-19 06:28:51, 2008-09-19 06:29:53, 2008-09-19 07:25:28, 2008-09-19 10:10:05, 2009-02-27 00:27:14]
[2008-09-19 06:26:11, 2008-09-19 06:32:58, 2008-09-19 06:45:40, 2008-09-19 07:01:59, 2014-02-24 21:20:49, 2015-08-10 23:28:09, 2016-03-01 19:48:35, 2011-06-21 16:30:27, 2011-07-05 11:29:51, 2011-08-08 19:35:41]
[2008-09-19 06:38:12, 2008-09-19 10:24:25]
[2009-06-16 07:33:13, 2015-01-23 18:36:18]
[2009-06-16 07:39:12, 2009-06-16 07:50:54, 2009-08-04 12:54:43]
[2009-06-16 07:41:07, 2009-06-16 07:59:15, 2009-06-16 08:16:34]
[2009-06-16 07:42:53, 2009-06-16 07:43:52, 2009-06-16 07:43:54]
[2009-06-16 07:45:12, 2009-06-16 07:50:55, 2012-08-02 04:59:35]
[2009-06-16 07:45:58, 2009-06-16 07:59:15, 2009-06-16 08:07:41, 2009-06-16 08:08:14, 2014-03-04 19:32:41]
[2009-06-16 07:49:19, 2009-06-16 07:49:57, 2009-06-16 08:02:48, 2009-06-16 08:10:20, 2009-06-16 08:20:10, 2009-06-16 08:30:09, 2009-06-16 08:30:33, 2009-06-16 08:40:07, 2009-06-16 08:50:31, 2009-06-16 09:39:52]
[2009-06-16 07:45:59, 2009-06-16 07:59:15, 2009-06-16 08:07:41, 2009-06-16 08:08:14, 2014-03-04 19:32:41]
[2009-06-16 07:49:19, 2009-06-16 07:49:57, 2009-06-16 08:02:49, 2009-06-16 08:10:21, 2009-06-16 08:20:10, 2009-06-16 08:30:10, 2009-06-16 08:30:34, 2009-06-16 08:40:07, 2009-06-16 08:50:32, 2009-06-16 09:39:52]
-- !q04_5 --
1000262 [2009-06-16 08:55:20, 2009-06-16 09:04:41] Steven (91612)
10000065 [2012-04-04 11:23:51, 2013-06-12 05:37:24, 2015-12-10 18:50:07] po5i (1303826)
10000070 [2012-04-03 19:35:38, 2012-04-03 19:54:31, 2012-04-03 20:00:10] 6502 (320726)
10000150 [2012-04-03 19:42:17, 2012-04-03 19:44:00, 2012-04-03 19:51:16, 2012-04-03 20:02:21, 2012-04-04 18:05:13, 2012-08-18 12:43:08] Martin Prakash (1311203)
10000297 [2012-04-03 19:55:43, 2012-04-03 20:11:34] bachurim09 (438728)
1000262 [2009-06-16 08:55:21, 2009-06-16 09:04:42] Steven (91612)
10000065 [2012-04-04 11:23:51, 2013-06-12 05:37:25, 2015-12-10 18:50:08] po5i (1303826)
10000070 [2012-04-03 19:35:39, 2012-04-03 19:54:31, 2012-04-03 20:00:11] 6502 (320726)
10000150 [2012-04-03 19:42:17, 2012-04-03 19:44:01, 2012-04-03 19:51:16, 2012-04-03 20:02:21, 2012-04-04 18:05:13, 2012-08-18 12:43:09] Martin Prakash (1311203)
10000297 [2012-04-03 19:55:44, 2012-04-03 20:11:35] bachurim09 (438728)
10000500 [] Ricardo Garza V. (1217187)
10000527 [2012-04-03 23:06:24] Smudger (940173)
10000527 [2012-04-03 23:06:25] Smudger (940173)
10000529 [2012-04-03 20:06:10] qwertymk (465546)
10000776 [2012-04-03 20:32:45, 2012-04-03 20:36:09] Perex19 (684608)
10000889 [2012-04-03 20:29:28, 2012-04-03 20:49:49] HaniAA (1311352)
10000776 [2012-04-03 20:32:46, 2012-04-03 20:36:09] Perex19 (684608)
10000889 [2012-04-03 20:29:29, 2012-04-03 20:49:50] HaniAA (1311352)
-- !q04_6 --
1000261 2009-06-16T08:48:45 [2009-06-16 08:55:20, 2009-06-16 09:04:41] How to avoid javascript retrieving values from non-existing elements ['Artem Barger (104014)', 'Dan F (11569)'] ['javascript', 'wordpress', 'cookies'] Steven (91612)
10000064 2012-04-03T19:30:55 [2012-04-04 11:23:51, 2013-06-12 05:37:24, 2015-12-10 18:50:07] Is there a java library to bind XML (LOM) to XML+RDF? ['William Greenly (611714)', 'po5i (1303826)', 'Enayat (2500344)'] ['java', 'xml', 'xslt', 'rdf'] po5i (1303826)
10000069 2012-04-03T19:31:17 [2012-04-03 19:35:38, 2012-04-03 19:54:31, 2012-04-03 20:00:10] Extending javascript function scope ['Kevin Bowersox (714969)', 'Adam Shiemke (302132)', 'Juan Mendes (227299)'] ['javascript', 'dynamic', 'scope'] 6502 (320726)
10000149 2012-04-03T19:38:03 [2012-04-03 19:42:17, 2012-04-03 19:44:00, 2012-04-03 19:51:16, 2012-04-03 20:02:21, 2012-04-04 18:05:13, 2012-08-18 12:43:08] Example of MVC in java/jdk ['hvgotcodes (305644)', 'tenorsax (1048330)', 'Ulises Layera (1056488)', 'user282172 (282172)', 'Alonso Dominguez (748883)', 'padman (1032875)'] ['java', 'model-view-controller'] Martin Prakash (1311203)
10000296 2012-04-03T19:49:51 [2012-04-03 19:55:43, 2012-04-03 20:11:34] WriteInt-RandomAccessFile - java ['ControlAltDel (1291492)', 'Eugene Retunsky (871953)'] ['java', 'random-access'] bachurim09 (438728)
1000261 2009-06-16T08:48:45 [2009-06-16 08:55:21, 2009-06-16 09:04:42] How to avoid javascript retrieving values from non-existing elements ['Artem Barger (104014)', 'Dan F (11569)'] ['javascript', 'wordpress', 'cookies'] Steven (91612)
10000064 2012-04-03T19:30:55 [2012-04-04 11:23:51, 2013-06-12 05:37:25, 2015-12-10 18:50:08] Is there a java library to bind XML (LOM) to XML+RDF? ['William Greenly (611714)', 'po5i (1303826)', 'Enayat (2500344)'] ['java', 'xml', 'xslt', 'rdf'] po5i (1303826)
10000069 2012-04-03T19:31:17 [2012-04-03 19:35:39, 2012-04-03 19:54:31, 2012-04-03 20:00:11] Extending javascript function scope ['Kevin Bowersox (714969)', 'Adam Shiemke (302132)', 'Juan Mendes (227299)'] ['javascript', 'dynamic', 'scope'] 6502 (320726)
10000149 2012-04-03T19:38:03 [2012-04-03 19:42:17, 2012-04-03 19:44:01, 2012-04-03 19:51:16, 2012-04-03 20:02:21, 2012-04-04 18:05:13, 2012-08-18 12:43:09] Example of MVC in java/jdk ['hvgotcodes (305644)', 'tenorsax (1048330)', 'Ulises Layera (1056488)', 'user282172 (282172)', 'Alonso Dominguez (748883)', 'padman (1032875)'] ['java', 'model-view-controller'] Martin Prakash (1311203)
10000296 2012-04-03T19:49:51 [2012-04-03 19:55:44, 2012-04-03 20:11:35] WriteInt-RandomAccessFile - java ['ControlAltDel (1291492)', 'Eugene Retunsky (871953)'] ['java', 'random-access'] bachurim09 (438728)
10000499 2012-04-03T20:03:29 [] process hanging on java process builder start [] ['java'] Ricardo Garza V. (1217187)
10000526 2012-04-03T20:04:39 [2012-04-03 23:06:24] javascript - fetch additional fields from mysql and display in table ['cha55son (595130)'] ['php', 'javascript', 'mysql', 'forms'] Smudger (940173)
10000528 2012-04-03T20:04:45 [2012-04-03 20:06:10] Do I need to escape text/plain or text/javascript? ['Matthew Flaschen (47773)'] ['php', 'javascript', 'security', 'xss'] qwertymk (465546)
10000775 2012-04-03T20:20:54 [2012-04-03 20:32:45, 2012-04-03 20:36:09] javascript mouse event compatibility issue between browsers ['Jack M (815612)', 'Simon Forsberg (1310566)'] ['javascript', 'html5', 'mouseevent', 'cross-browser'] Perex19 (684608)
10000888 2012-04-03T20:28:20 [2012-04-03 20:29:28, 2012-04-03 20:49:49] Check if char exists in java ['biziclop (574479)', 'Cratylus (384706)'] ['java'] HaniAA (1311352)
10000526 2012-04-03T20:04:40 [2012-04-03 23:06:25] javascript - fetch additional fields from mysql and display in table ['cha55son (595130)'] ['php', 'javascript', 'mysql', 'forms'] Smudger (940173)
10000528 2012-04-03T20:04:46 [2012-04-03 20:06:10] Do I need to escape text/plain or text/javascript? ['Matthew Flaschen (47773)'] ['php', 'javascript', 'security', 'xss'] qwertymk (465546)
10000775 2012-04-03T20:20:55 [2012-04-03 20:32:46, 2012-04-03 20:36:09] javascript mouse event compatibility issue between browsers ['Jack M (815612)', 'Simon Forsberg (1310566)'] ['javascript', 'html5', 'mouseevent', 'cross-browser'] Perex19 (684608)
10000888 2012-04-03T20:28:20 [2012-04-03 20:29:29, 2012-04-03 20:49:50] Check if char exists in java ['biziclop (574479)', 'Cratylus (384706)'] ['java'] HaniAA (1311352)
-- !q04_7 --
2009-06-16T08:48:45 How to avoid javascript retrieving values from non-existing elements ['javascript', 'wordpress', 'cookies']
@ -60,33 +59,33 @@
2012-04-03T19:38:03 Example of MVC in java/jdk ['java', 'model-view-controller']
2012-04-03T19:49:51 WriteInt-RandomAccessFile - java ['java', 'random-access']
2012-04-03T20:03:29 process hanging on java process builder start ['java']
2012-04-03T20:04:39 javascript - fetch additional fields from mysql and display in table ['php', 'javascript', 'mysql', 'forms']
2012-04-03T20:04:45 Do I need to escape text/plain or text/javascript? ['php', 'javascript', 'security', 'xss']
2012-04-03T20:20:54 javascript mouse event compatibility issue between browsers ['javascript', 'html5', 'mouseevent', 'cross-browser']
2012-04-03T20:04:40 javascript - fetch additional fields from mysql and display in table ['php', 'javascript', 'mysql', 'forms']
2012-04-03T20:04:46 Do I need to escape text/plain or text/javascript? ['php', 'javascript', 'security', 'xss']
2012-04-03T20:20:55 javascript mouse event compatibility issue between browsers ['javascript', 'html5', 'mouseevent', 'cross-browser']
2012-04-03T20:28:20 Check if char exists in java ['java']
-- !q04_8 --
['Misplaced (13710)', 'Justin Bozonier (9401)', 'Petr Macek (15045)', 'n1x0nad', 'Mladen Mihajlovic (11421)', 'Saem (68131)'] 2008-09-19T06:10:16 ['web-frameworks'] 100001
['Jerub (14648)', 'Matthias Kestenholz (317346)', 'Antti Rasinen (8570)', 'Thomas Wouters (17624)', 'Craig (1489354)', 'Aaron Hall (541136)', 'Ethan Furman (208880)', 'kindall (416467)', 'e-satis (9951)', 'espeed (161085)'] 2008-09-19T06:10:46 ['python', 'oop', 'metaclass', 'python-datamodel'] 100003
['Tom Carr (14954)', 'lotsoffreetime (18248)'] 2008-09-19T06:12:37 ['c#', 'logging', 'enterprise-library', 'application-blocks'] 100007
['Michał Niklas (22595)', 'Jack Njiri (77153)'] 2009-06-16T07:28:42 ['vb6', 'progress-bar'] 1000000
['Jerub (14648)', 'Matthias Kestenholz (317346)', 'Antti Rasinen (8570)', 'Thomas Wouters (17624)', 'Craig (1489354)', 'Aaron Hall (541136)', 'Ethan Furman (208880)', 'kindall (416467)', 'e-satis (9951)', 'espeed (161085)'] 2008-09-19T06:10:47 ['python', 'oop', 'metaclass', 'python-datamodel'] 100003
['Tom Carr (14954)', 'lotsoffreetime (18248)'] 2008-09-19T06:12:38 ['c#', 'logging', 'enterprise-library', 'application-blocks'] 100007
['Michał Niklas (22595)', 'Jack Njiri (77153)'] 2009-06-16T07:28:43 ['vb6', 'progress-bar'] 1000000
['laalto (101361)', 'anon', 'frankster (147813)'] 2009-06-16T07:28:52 ['c++', 'symbian'] 1000001
['Dmitriy Matveev (53481)'] 2009-06-16T07:30:22 ['java', '.net', 'serialization', 'ikvm'] 1000004
['Dmitriy Matveev (53481)'] 2009-06-16T07:30:23 ['java', '.net', 'serialization', 'ikvm'] 1000004
['Sev (83819)', 'AlexDrenea (39624)', 'blowdart (2525)'] 2009-06-16T07:36:09 ['c#', 'windows', 'winforms', 'windows-services'] 1000023
['Canavar (55351)', 'Thevs (8559)', 'Alsciende (119195)'] 2009-06-16T07:38:33 ['javascript', 'internet-explorer'] 1000028
['paxdiablo (14860)', 'Dutow (73657)', 'DShook (370)', 'Roddy (1737)', 'bill (121958)', 'henrikpp (1442)', 'Martin Schuhfuß (123219)', 'finnw (12048)', 'Christoffer (15514)', 'Skizz (1898)'] 2009-06-16T07:40:16 ['c', 'algorithm', 'sorting', 'word'] 1000036
['Canavar (55351)', 'Thevs (8559)', 'Alsciende (119195)'] 2009-06-16T07:38:34 ['javascript', 'internet-explorer'] 1000028
['paxdiablo (14860)', 'Dutow (73657)', 'DShook (370)', 'Roddy (1737)', 'bill (121958)', 'henrikpp (1442)', 'Martin Schuhfuß (123219)', 'finnw (12048)', 'Christoffer (15514)', 'Skizz (1898)'] 2009-06-16T07:40:17 ['c', 'algorithm', 'sorting', 'word'] 1000036
['Dutow (73657)', 'PaulJWilliams (71399)', 'friendlyautomaton (1570376)'] 2009-06-16T07:40:56 ['big-o'] 1000038
-- !q04_9 --
['Misplaced (13710)', 'Justin Bozonier (9401)', 'Petr Macek (15045)', 'n1x0nad', 'Mladen Mihajlovic (11421)', 'Saem (68131)'] 2008-09-19T06:10:16 ['web-frameworks'] 100001 MVC or event-driven component-oriented web frameworks?
['Jerub (14648)', 'Matthias Kestenholz (317346)', 'Antti Rasinen (8570)', 'Thomas Wouters (17624)', 'Craig (1489354)', 'Aaron Hall (541136)', 'Ethan Furman (208880)', 'kindall (416467)', 'e-satis (9951)', 'espeed (161085)'] 2008-09-19T06:10:46 ['python', 'oop', 'metaclass', 'python-datamodel'] 100003 What is a metaclass in Python?
['Tom Carr (14954)', 'lotsoffreetime (18248)'] 2008-09-19T06:12:37 ['c#', 'logging', 'enterprise-library', 'application-blocks'] 100007 Logging Application Block - Logging the caller
['Michał Niklas (22595)', 'Jack Njiri (77153)'] 2009-06-16T07:28:42 ['vb6', 'progress-bar'] 1000000 Display Progress Bar at the Time of Processing
['Jerub (14648)', 'Matthias Kestenholz (317346)', 'Antti Rasinen (8570)', 'Thomas Wouters (17624)', 'Craig (1489354)', 'Aaron Hall (541136)', 'Ethan Furman (208880)', 'kindall (416467)', 'e-satis (9951)', 'espeed (161085)'] 2008-09-19T06:10:47 ['python', 'oop', 'metaclass', 'python-datamodel'] 100003 What is a metaclass in Python?
['Tom Carr (14954)', 'lotsoffreetime (18248)'] 2008-09-19T06:12:38 ['c#', 'logging', 'enterprise-library', 'application-blocks'] 100007 Logging Application Block - Logging the caller
['Michał Niklas (22595)', 'Jack Njiri (77153)'] 2009-06-16T07:28:43 ['vb6', 'progress-bar'] 1000000 Display Progress Bar at the Time of Processing
['laalto (101361)', 'anon', 'frankster (147813)'] 2009-06-16T07:28:52 ['c++', 'symbian'] 1000001 Descriptor conversion problem
['Dmitriy Matveev (53481)'] 2009-06-16T07:30:22 ['java', '.net', 'serialization', 'ikvm'] 1000004 Problems with class loading during deserialization of type from another assembly
['Dmitriy Matveev (53481)'] 2009-06-16T07:30:23 ['java', '.net', 'serialization', 'ikvm'] 1000004 Problems with class loading during deserialization of type from another assembly
['Sev (83819)', 'AlexDrenea (39624)', 'blowdart (2525)'] 2009-06-16T07:36:09 ['c#', 'windows', 'winforms', 'windows-services'] 1000023 Windows Service vs Windows Application - Best Practice
['Canavar (55351)', 'Thevs (8559)', 'Alsciende (119195)'] 2009-06-16T07:38:33 ['javascript', 'internet-explorer'] 1000028 How to focus radio control using Javascript in IE?
['paxdiablo (14860)', 'Dutow (73657)', 'DShook (370)', 'Roddy (1737)', 'bill (121958)', 'henrikpp (1442)', 'Martin Schuhfuß (123219)', 'finnw (12048)', 'Christoffer (15514)', 'Skizz (1898)'] 2009-06-16T07:40:16 ['c', 'algorithm', 'sorting', 'word'] 1000036 What sorting technique will you use?
['Canavar (55351)', 'Thevs (8559)', 'Alsciende (119195)'] 2009-06-16T07:38:34 ['javascript', 'internet-explorer'] 1000028 How to focus radio control using Javascript in IE?
['paxdiablo (14860)', 'Dutow (73657)', 'DShook (370)', 'Roddy (1737)', 'bill (121958)', 'henrikpp (1442)', 'Martin Schuhfuß (123219)', 'finnw (12048)', 'Christoffer (15514)', 'Skizz (1898)'] 2009-06-16T07:40:17 ['c', 'algorithm', 'sorting', 'word'] 1000036 What sorting technique will you use?
['Dutow (73657)', 'PaulJWilliams (71399)', 'friendlyautomaton (1570376)'] 2009-06-16T07:40:56 ['big-o'] 1000038 Whats the least upper bound of the growth rate using big-Oh notation of these two functions
-- !q04_10 --
@ -118,22 +117,22 @@
10000005 2012-04-03T19:25:46 [2012-04-03 19:28:39] PHP Sort array by field? ['meagar (229044)'] ['php', 'arrays', 'sorting'] Michael Ecklund (804104)
10000007 2012-04-03T19:26:05 [2012-04-03 19:34:49, 2012-04-03 19:36:06] Arrays in PHP seems to drop elements ['Jarosław Gomułka (1256609)', 'RyanS (1310604)'] ['php', 'arrays'] farley (1311218)
10000008 2012-04-03T19:26:09 [2012-04-03 19:44:28] RESTful servlet URLs - servlet-mapping in web.xml ['matsev (303598)'] ['java', 'rest', 'servlets', 'spring-mvc', 'url-pattern'] John Strickler (292614)
10000014 2012-04-03T19:26:28 [2012-04-11 06:02:38] How to De-Authenticate a Windows Auth user with PHP ['Rob Allen (23060)'] ['php', 'windows', 'iis-7', 'windows-authentication'] Neal (561731)
10000019 2012-04-03T19:26:50 [2012-04-03 19:30:25] Are arrays in MongoDB documents always kept in order? ['Blacksad (820664)'] ['mongodb'] Adam Monsen (156060)
10000014 2012-04-03T19:26:29 [2012-04-11 06:02:39] How to De-Authenticate a Windows Auth user with PHP ['Rob Allen (23060)'] ['php', 'windows', 'iis-7', 'windows-authentication'] Neal (561731)
10000019 2012-04-03T19:26:51 [2012-04-03 19:30:25] Are arrays in MongoDB documents always kept in order? ['Blacksad (820664)'] ['mongodb'] Adam Monsen (156060)
10000020 2012-04-03T19:26:51 [2012-04-04 16:00:38, 2014-07-06 09:00:37] AJAX post to google spreadsheet ['Stuart Nelson (1227292)', 'mhawksey (1027723)'] ['jquery', 'google-apps-script'] Stuart Nelson (1227292)
10000023 2012-04-03T19:26:57 [2012-04-04 12:56:34] Are these LAMP permissions secure? ['larsks (147356)'] ['linux', 'apache', 'security', 'ubuntu', 'permissions'] Trent Scott (600873)
10000024 2012-04-03T19:26:57 [2012-04-11 09:33:37] Handlebars EACH iterator error ['joevallender (426171)'] ['javascript', 'handlebars.js'] CoryDorning (322551)
10000024 2012-04-03T19:26:58 [2012-04-11 09:33:38] Handlebars EACH iterator error ['joevallender (426171)'] ['javascript', 'handlebars.js'] CoryDorning (322551)
10000030 2012-04-03T19:27:30 [] Is there a way to set a MKMapView map to an alpha lower to 1 and its markers to 1? [] ['ios', 'mkmapview', 'mkannotationview'] annie (591510)
-- !q04_13 --
10000064 2012-04-03T19:30:55 [2012-04-04 11:23:51, 2013-06-12 05:37:24, 2015-12-10 18:50:07] Is there a java library to bind XML (LOM) to XML+RDF? ['William Greenly (611714)', 'po5i (1303826)', 'Enayat (2500344)'] ['java', 'xml', 'xslt', 'rdf'] po5i (1303826)
10000064 2012-04-03T19:30:55 [2012-04-04 11:23:51, 2013-06-12 05:37:25, 2015-12-10 18:50:08] Is there a java library to bind XML (LOM) to XML+RDF? ['William Greenly (611714)', 'po5i (1303826)', 'Enayat (2500344)'] ['java', 'xml', 'xslt', 'rdf'] po5i (1303826)
10000126 2012-04-03T19:35:51 [2012-04-03 20:23:36] Re-using Java generic collections in Scala without trait Object ['Didier Dupont (754787)'] ['java', 'scala', 'generics', 'collections', 'trait'] Nikolaos (195489)
10000149 2012-04-03T19:38:03 [2012-04-03 19:42:17, 2012-04-03 19:44:00, 2012-04-03 19:51:16, 2012-04-03 20:02:21, 2012-04-04 18:05:13, 2012-08-18 12:43:08] Example of MVC in java/jdk ['hvgotcodes (305644)', 'tenorsax (1048330)', 'Ulises Layera (1056488)', 'user282172 (282172)', 'Alonso Dominguez (748883)', 'padman (1032875)'] ['java', 'model-view-controller'] Martin Prakash (1311203)
10000296 2012-04-03T19:49:51 [2012-04-03 19:55:43, 2012-04-03 20:11:34] WriteInt-RandomAccessFile - java ['ControlAltDel (1291492)', 'Eugene Retunsky (871953)'] ['java', 'random-access'] bachurim09 (438728)
10000361 2012-04-03T19:53:59 [2012-04-03 19:58:43] Java - TCP Server can't read from TCP Client ['Tudor (808486)'] ['java', 'tcp'] newtonrd (1311275)
10000365 2012-04-03T19:54:15 [2012-04-03 20:04:57, 2012-04-03 20:13:26, 2012-04-03 22:02:44, 2012-04-03 22:13:49] Java android client communication with C# server ['Matthew (507793)', 'JMarsch (67038)', 'TommyN (636509)', 'Jon O (429108)'] ['c#', 'android', 'client'] Ahmed (1185422)
10000423 2012-04-03T19:58:26 [2012-04-03 20:38:59] Console scripts execution from Java program ['Luca (1252169)'] ['java', 'linux', 'bash'] glaz666 (59692)
10000149 2012-04-03T19:38:03 [2012-04-03 19:42:17, 2012-04-03 19:44:01, 2012-04-03 19:51:16, 2012-04-03 20:02:21, 2012-04-04 18:05:13, 2012-08-18 12:43:09] Example of MVC in java/jdk ['hvgotcodes (305644)', 'tenorsax (1048330)', 'Ulises Layera (1056488)', 'user282172 (282172)', 'Alonso Dominguez (748883)', 'padman (1032875)'] ['java', 'model-view-controller'] Martin Prakash (1311203)
10000296 2012-04-03T19:49:51 [2012-04-03 19:55:44, 2012-04-03 20:11:35] WriteInt-RandomAccessFile - java ['ControlAltDel (1291492)', 'Eugene Retunsky (871953)'] ['java', 'random-access'] bachurim09 (438728)
10000361 2012-04-03T19:53:59 [2012-04-03 19:58:44] Java - TCP Server can't read from TCP Client ['Tudor (808486)'] ['java', 'tcp'] newtonrd (1311275)
10000365 2012-04-03T19:54:15 [2012-04-03 20:04:57, 2012-04-03 20:13:27, 2012-04-03 22:02:45, 2012-04-03 22:13:50] Java android client communication with C# server ['Matthew (507793)', 'JMarsch (67038)', 'TommyN (636509)', 'Jon O (429108)'] ['c#', 'android', 'client'] Ahmed (1185422)
10000423 2012-04-03T19:58:27 [2012-04-03 20:39:00] Console scripts execution from Java program ['Luca (1252169)'] ['java', 'linux', 'bash'] glaz666 (59692)
10000499 2012-04-03T20:03:29 [] process hanging on java process builder start [] ['java'] Ricardo Garza V. (1217187)
10000501 2012-04-03T20:03:34 [2012-04-03 20:09:09] Java - Connect to RDP server in Windows ['kevingreen (288915)'] ['java', 'windows', 'remote-desktop', 'rdp', 'mstsc'] eoinzy (652410)
10000850 2012-04-03T20:25:56 [2012-04-03 20:27:33, 2012-04-03 20:28:08, 2012-04-03 20:29:25, 2012-04-03 20:30:01, 2013-09-23 05:49:15] Appending file results in overwrite (Java) ['ulmangt (1212363)', 'Jack Edmonds (61663)', 'Angelo Fuchs (881272)', 'ControlAltDel (1291492)', 'Prasad (2041986)'] ['java', 'file', 'new-operator'] yawnobleix (1308355)
10000501 2012-04-03T20:03:35 [2012-04-03 20:09:09] Java - Connect to RDP server in Windows ['kevingreen (288915)'] ['java', 'windows', 'remote-desktop', 'rdp', 'mstsc'] eoinzy (652410)
10000850 2012-04-03T20:25:56 [2012-04-03 20:27:34, 2012-04-03 20:28:08, 2012-04-03 20:29:26, 2012-04-03 20:30:02, 2013-09-23 05:49:15] Appending file results in overwrite (Java) ['ulmangt (1212363)', 'Jack Edmonds (61663)', 'Angelo Fuchs (881272)', 'ControlAltDel (1291492)', 'Prasad (2041986)'] ['java', 'file', 'new-operator'] yawnobleix (1308355)

View File

@ -15,7 +15,7 @@
1 2023-04-20 2023-04-20 2023-04-20T00:00 2023-04-20T00:00 2023-04-20T00:00 2023-04-20T00:00 Beijing Haidian 1 1 true 1 1 1 1.1 1.1 char1 1 1 1 0.1 1.00000000 1.0000000000 1 1.0000000000000000000000000000000000000 0.10000000000000000000000000000000000000
2 9999-12-31 9999-12-31 9999-12-31T23:59:59 9999-12-31T23:59:59 2023-04-20T00:00:00.120 2023-04-20T00:00:00.334400 Haidian -32768 -128 true -2147483648 -9223372036854775808 -170141183460469231731687303715884105728 1.4E-45 4.9E-324 char2 100000000 100000000 4 0.1 0.99999999 9999999999.9999999999 99999999999999999999999999999999999999 9.9999999999999999999999999999999999999 0.99999999999999999999999999999999999999
3 2023-04-21 2023-04-21 2023-04-20T12:34:56 2023-04-20T00:00 2023-04-20T00:00:00.123 2023-04-20T00:00:00.123456 Beijing 32767 127 true 2147483647 9223372036854775807 170141183460469231731687303715884105727 3.4028235e+38 1.7976931348623157E308 char3 999999999 999999999 9 0.9 9.99999999 1234567890.0123456789 12345678901234567890123456789012345678 1.2345678901234567890123456789012345678 0.12345678901234567890123456789012345678
4 0000-01-02 0000-01-01 2023-04-20T00:00 2023-04-20T00:00 2023-04-20T00:00 2023-04-20T00:00 Beijing Haidian 4 4 true 4 4 4 4.4 4.4 char4 4 4 4 0.4 4.00000000 4.0000000000 4 4.0000000000000000000000000000000000000 0.40000000000000000000000000000000000000
4 0000-01-01 0000-01-01 2023-04-20T00:00 2023-04-20T00:00 2023-04-20T00:00 2023-04-20T00:00 Beijing Haidian 4 4 true 4 4 4 4.4 4.4 char4 4 4 4 0.4 4.00000000 4.0000000000 4 4.0000000000000000000000000000000000000 0.40000000000000000000000000000000000000
-- !select_load3 --
1 2023-04-20 2023-04-20 2023-04-20T00:00 2023-04-20T00:00 2023-04-20T00:00 2023-04-20T00:00 Beijing Haidian 1 1 true 1 1 1 1.1 1.1 char1 1 1 1 0.1 1.00000000 1.0000000000 1 1.0000000000000000000000000000000000000 0.10000000000000000000000000000000000000

View File

@ -144,64 +144,6 @@ true
true
true
-- !sql_now --
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
-- !sql_now_notnull --
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
2023-02-14T20:43:06
-- !sql_now_Integer --
h910-12-18 16:00:00.000000
2023-02-14T20:43:06.768
2023-02-14T20:43:06.768
2023-02-14T20:43:06.768
2023-02-14T20:43:06.768
2023-02-14T20:43:06.768
2023-02-14T20:43:06.768
2023-02-14T20:43:06.768
2023-02-14T20:43:06.768
2023-02-14T20:43:06.768
2023-02-14T20:43:06.768
2023-02-14T20:43:06.768
2023-02-14T20:43:06.768
-- !sql_now_Integer_notnull --
2023-02-14T20:43:06.772
2023-02-14T20:43:06.772
2023-02-14T20:43:06.772
2023-02-14T20:43:06.772
2023-02-14T20:43:06.772
2023-02-14T20:43:06.772
2023-02-14T20:43:06.772
2023-02-14T20:43:06.772
2023-02-14T20:43:06.772
2023-02-14T20:43:06.772
2023-02-14T20:43:06.772
2023-02-14T20:43:06.772
-- !sql_null_or_empty_Varchar --
false
false
@ -987,32 +929,32 @@ true
-- !sql_nvl_Date_DateTime --
\N
2012-03-01
2012-03-02
2012-03-03
2012-03-04
2012-03-05
2012-03-06
2012-03-07
2012-03-08
2012-03-09
2012-03-10
2012-03-11
2012-03-12
2012-03-01T00:00
2012-03-02T00:00
2012-03-03T00:00
2012-03-04T00:00
2012-03-05T00:00
2012-03-06T00:00
2012-03-07T00:00
2012-03-08T00:00
2012-03-09T00:00
2012-03-10T00:00
2012-03-11T00:00
2012-03-12T00:00
-- !sql_nvl_Date_DateTime_notnull --
2012-03-01
2012-03-02
2012-03-03
2012-03-04
2012-03-05
2012-03-06
2012-03-07
2012-03-08
2012-03-09
2012-03-10
2012-03-11
2012-03-12
2012-03-01T00:00
2012-03-02T00:00
2012-03-03T00:00
2012-03-04T00:00
2012-03-05T00:00
2012-03-06T00:00
2012-03-07T00:00
2012-03-08T00:00
2012-03-09T00:00
2012-03-10T00:00
2012-03-11T00:00
2012-03-12T00:00
-- !sql_nvl_DateTime_Date --
\N

View File

@ -1453,7 +1453,7 @@ true
\N
0.29640805436890805
0.584557663067101
2.2514343365321805
2.25143433653218
2.2985768978250287
2.3435868570715472
2.343933856604365
@ -1468,7 +1468,7 @@ true
\N
0.29640805436890805
0.584557663067101
2.2514343365321805
2.25143433653218
2.2985768978250287
2.3435868570715472
2.343933856604365
@ -1482,9 +1482,9 @@ true
-- !sql_st_azimuth_Varchar_Varchar --
\N
0.10887770754803192
0.6831103181292284
0.6831103181292286
1.5514282110255961
1.8473724820763877
1.8473724820763875
2.0312260636745996
5.086326478855965
5.170365116267284
@ -1497,9 +1497,9 @@ true
-- !sql_st_azimuth_Varchar_Varchar_notnull --
\N
0.10887770754803192
0.6831103181292284
0.6831103181292286
1.5514282110255961
1.8473724820763877
1.8473724820763875
2.0312260636745996
5.086326478855965
5.170365116267284
@ -1544,28 +1544,28 @@ true
1.1118578328276027E11
1.8542398742443716E11
1.2332047035253083E12
1.7001525674021448E12
1.700152567402145E12
2.7580570137621265E12
3.6269055655335474E12
4.961916929237378E12
4.961916929237377E12
7.513981106323984E12
1.2905961051326234E13
1.886514910145883E13
3.68807416450893E13
1.8865149101458824E13
3.688074164508929E13
-- !sql_st_area_square_meters_polygon_notnull --
7.437458708775987E10
1.1118578328276027E11
1.8542398742443716E11
1.2332047035253083E12
1.7001525674021448E12
1.700152567402145E12
2.7580570137621265E12
3.6269055655335474E12
4.961916929237378E12
4.961916929237377E12
7.513981106323984E12
1.2905961051326234E13
1.886514910145883E13
3.68807416450893E13
1.8865149101458824E13
3.688074164508929E13
-- !sql_st_area_km_circle --
\N
@ -1602,28 +1602,28 @@ true
111185.78328276028
185423.9874244372
1233204.7035253085
1700152.567402145
1700152.5674021454
2758057.0137621267
3626905.565533547
4961916.929237378
7513981.106323985
1.2905961051326236E7
1.8865149101458833E7
3.68807416450893E7
1.8865149101458825E7
3.688074164508929E7
-- !sql_st_area_km_polygon_notnull --
74374.58708775988
111185.78328276028
185423.9874244372
1233204.7035253085
1700152.567402145
1700152.5674021454
2758057.0137621267
3626905.565533547
4961916.929237378
7513981.106323985
1.2905961051326236E7
1.8865149101458833E7
3.68807416450893E7
1.8865149101458825E7
3.688074164508929E7
-- !sql_st_geometryfromtext_Varchar --
\N
@ -2322,62 +2322,62 @@ true
true
-- !sql_str_to_date_Varchar_Varchar --
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
-- !sql_str_to_date_Varchar_Varchar_notnull --
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
-- !sql_str_to_date_String_String --
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
-- !sql_str_to_date_String_String_notnull --
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
0000-00-00 00:00:00
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
\N
-- !sql_strleft_Varchar_Integer --
\N

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --
test_array_show_create CREATE TABLE `test_array_show_create` (\n `k1` int(11) NULL,\n `k2` array<smallint(6)> NOT NULL,\n `k3` array<int(11)> NOT NULL,\n `k4` array<bigint(20)> NOT NULL,\n `k5` array<char(1)> NOT NULL,\n `k6` array<varchar(20)> NULL,\n `k7` array<date> NOT NULL,\n `k8` array<datetime> NOT NULL,\n `k9` array<float> NOT NULL,\n `k10` array<double> NOT NULL,\n `k11` array<decimal(20, 6)> NULL\n) ENGINE=OLAP\nDUPLICATE KEY(`k1`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY HASH(`k1`) BUCKETS 1\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false"\n);
test_array_show_create CREATE TABLE `test_array_show_create` (\n `k1` int(11) NULL,\n `k2` array<smallint(6)> NOT NULL,\n `k3` array<int(11)> NOT NULL,\n `k4` array<bigint(20)> NOT NULL,\n `k5` array<char(1)> NOT NULL,\n `k6` array<varchar(20)> NULL,\n `k7` array<datev2> NOT NULL,\n `k8` array<datetimev2(0)> NOT NULL,\n `k9` array<float> NOT NULL,\n `k10` array<double> NOT NULL,\n `k11` array<decimal(20, 6)> NULL\n) ENGINE=OLAP\nDUPLICATE KEY(`k1`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY HASH(`k1`) BUCKETS 1\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false"\n);

View File

@ -1,4 +1,4 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --
test_array_show_create CREATE TABLE `test_array_show_create` (\n `k1` int(11) NULL,\n `k2` array<smallint(6)> NOT NULL,\n `k3` array<int(11)> NOT NULL,\n `k4` array<bigint(20)> NOT NULL,\n `k5` array<char(1)> NOT NULL,\n `k6` array<varchar(20)> NULL,\n `k7` array<date> NOT NULL,\n `k8` array<datetime> NOT NULL,\n `k9` array<float> NOT NULL,\n `k10` array<double> NOT NULL,\n `k11` array<decimal(20, 6)> NULL\n) ENGINE=OLAP\nDUPLICATE KEY(`k1`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY HASH(`k1`) BUCKETS 1\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false"\n);
test_array_show_create CREATE TABLE `test_array_show_create` (\n `k1` int(11) NULL,\n `k2` array<smallint(6)> NOT NULL,\n `k3` array<int(11)> NOT NULL,\n `k4` array<bigint(20)> NOT NULL,\n `k5` array<char(1)> NOT NULL,\n `k6` array<varchar(20)> NULL,\n `k7` array<datev2> NOT NULL,\n `k8` array<datetimev2(0)> NOT NULL,\n `k9` array<float> NOT NULL,\n `k10` array<double> NOT NULL,\n `k11` array<decimal(20, 6)> NULL\n) ENGINE=OLAP\nDUPLICATE KEY(`k1`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY HASH(`k1`) BUCKETS 1\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false"\n);

View File

@ -1,6 +1,6 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !select --
test_map_show_create CREATE TABLE `test_map_show_create` (\n `k1` int(11) NULL,\n `k2` MAP<smallint(6),text> NULL,\n `k3` MAP<int(11),text> NULL,\n `k4` MAP<date,int(11)> NULL,\n `k5` MAP<datetime,text> NULL,\n `k6` MAP<float,int(11)> NULL\n) ENGINE=OLAP\nDUPLICATE KEY(`k1`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY HASH(`k1`) BUCKETS 1\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false"\n);
test_map_show_create CREATE TABLE `test_map_show_create` (\n `k1` int(11) NULL,\n `k2` MAP<smallint(6),text> NULL,\n `k3` MAP<int(11),text> NULL,\n `k4` MAP<datev2,int(11)> NULL,\n `k5` MAP<datetimev2(0),text> NULL,\n `k6` MAP<float,int(11)> NULL\n) ENGINE=OLAP\nDUPLICATE KEY(`k1`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY HASH(`k1`) BUCKETS 1\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false"\n);
-- !select --
1 1 1 1 1

View File

@ -3,5 +3,5 @@
1 1 1 1 1 1 1 1 1 1
-- !select --
test_struct_show_create CREATE TABLE `test_struct_show_create` (\n `k1` int(11) NULL,\n `k2` STRUCT<f1:smallint(6)> NOT NULL,\n `k3` STRUCT<f1:smallint(6),f2:int(11)> NOT NULL,\n `k4` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20)> NOT NULL,\n `k5` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1)> NOT NULL,\n `k6` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1),f5:varchar(20)> NULL,\n `k7` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1),f5:varchar(20),f6:date> NOT NULL,\n `k8` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1),f5:varchar(20),f6:date,f7:datetime> NOT NULL,\n `k9` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1),f5:varchar(20),f6:date,f7:datetime,f8:float> NOT NULL,\n `k10` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1),f5:varchar(20),f6:date,f7:datetime,f8:float,f9:double> NOT NULL,\n `k11` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1),f5:varchar(20),f6:date,f7:datetime,f8:float,f9:double,f10:decimal(20, 6)> NULL\n) ENGINE=OLAP\nDUPLICATE KEY(`k1`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY HASH(`k1`) BUCKETS 1\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false"\n);
test_struct_show_create CREATE TABLE `test_struct_show_create` (\n `k1` int(11) NULL,\n `k2` STRUCT<f1:smallint(6)> NOT NULL,\n `k3` STRUCT<f1:smallint(6),f2:int(11)> NOT NULL,\n `k4` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20)> NOT NULL,\n `k5` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1)> NOT NULL,\n `k6` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1),f5:varchar(20)> NULL,\n `k7` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1),f5:varchar(20),f6:datev2> NOT NULL,\n `k8` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1),f5:varchar(20),f6:datev2,f7:datetimev2(0)> NOT NULL,\n `k9` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1),f5:varchar(20),f6:datev2,f7:datetimev2(0),f8:float> NOT NULL,\n `k10` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1),f5:varchar(20),f6:datev2,f7:datetimev2(0),f8:float,f9:double> NOT NULL,\n `k11` STRUCT<f1:smallint(6),f2:int(11),f3:bigint(20),f4:char(1),f5:varchar(20),f6:datev2,f7:datetimev2(0),f8:float,f9:double,f10:decimal(20, 6)> NULL\n) ENGINE=OLAP\nDUPLICATE KEY(`k1`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY HASH(`k1`) BUCKETS 1\nPROPERTIES (\n"replication_allocation" = "tag.location.default: 1",\n"storage_format" = "V2",\n"light_schema_change" = "true",\n"disable_auto_compaction" = "false"\n);

View File

@ -62,22 +62,22 @@ true
true
-- !if_nullif3 --
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
true
-1
10
10
10
10
10
10
10
10
10
10
10
10
10
10
10
-- !if_nullif4 --
false
@ -134,22 +134,22 @@ hello
hello
-- !if_nullif7 --
false
false
false
false
false
false
false
false
false
true
true
true
true
true
true
true
0
0
0
0
0
0
0
0
0
-1
-1
-1
-1
-1
-1
-1
-- !if_nullif8 --
-1
@ -399,14 +399,14 @@ null NULL null NULLL
11011905
-- !if_nullif23 --
123.123
1243.5
24453.325
123.123000000
1243.500000000
24453.325000000
-- !if_nullif24 --
123.123
1243.5
24453.325
123.123000000
1243.500000000
24453.325000000
-- !if_nullif23 --
false

View File

@ -264,7 +264,7 @@ February
2020-09-01T00:00
-- !sql_year_floor --
2023-01-01T00:00
2023-01-01
-- !sql --
2020-01-01T00:00

View File

@ -3,7 +3,7 @@
test_materialized_view_hll DUP_KEYS record_id INT INT Yes true \N true
seller_id INT INT Yes true \N true
store_id INT INT Yes true \N true
sale_date DATE DATE Yes false \N NONE true
sale_date DATE DATEV2 Yes false \N NONE true
sale_amt BIGINT BIGINT Yes false \N NONE true
amt_count AGG_KEYS mv_store_id INT INT Yes true \N true `store_id`

View File

@ -3,7 +3,7 @@
test_materialized_view_hll_with_light_sc DUP_KEYS record_id INT INT Yes true \N true
seller_id INT INT Yes true \N true
store_id INT INT Yes true \N true
sale_date DATE DATE Yes false \N NONE true
sale_date DATE DATEV2 Yes false \N NONE true
sale_amt BIGINT BIGINT Yes false \N NONE true
amt_count1 AGG_KEYS mv_store_id INT INT Yes true \N true `store_id`

View File

@ -3,7 +3,7 @@
test_materialized_view1 DUP_KEYS record_id INT INT Yes true \N true
seller_id INT INT Yes true \N true
store_id INT INT Yes true \N true
sale_date DATE DATE Yes false \N NONE true
sale_date DATE DATEV2 Yes false \N NONE true
sale_amt BIGINT BIGINT Yes false \N NONE true
amt_sum AGG_KEYS mv_store_id INT INT Yes true \N true `store_id`
@ -13,7 +13,7 @@ amt_sum AGG_KEYS mv_store_id INT INT Yes true \N true `store_id`
test_materialized_view2 DUP_KEYS record_id INT INT Yes true \N true
seller_id INT INT Yes true \N true
store_id INT INT Yes true \N true
sale_date DATE DATE Yes false \N NONE true
sale_date DATE DATEV2 Yes false \N NONE true
sale_amt BIGINT BIGINT Yes false \N NONE true
seller_id_order DUP_KEYS mv_store_id INT INT Yes true \N true `store_id`
@ -40,7 +40,7 @@ seller_id_order DUP_KEYS mv_store_id INT INT Yes true \N true `store_id`
mva_SUM__CASE WHEN `sale_amt` IS NULL THEN 0 ELSE 1 END BIGINT BIGINT No false \N SUM true CASE WHEN `sale_amt` IS NULL THEN 0 ELSE 1 END
mva_SUM__`sale_amt` BIGINT BIGINT Yes false \N SUM true `sale_amt`
sale_amt BIGINT BIGINT Yes false \N NONE true
sale_date DATE DATE Yes false \N NONE true
sale_date DATE DATEV2 Yes false \N NONE true
seller_id INT INT Yes true \N true
store_id INT INT Yes true \N true
amt_count AGG_KEYS mv_store_id INT INT Yes true \N true `store_id`

View File

@ -15,9 +15,133 @@
// specific language governing permissions and limitations
// under the License.
suite("fold_constant_by_fe") {
sql 'use nereids_fold_constant_test'
suite("test_fold_constant_by_fe") {
sql 'set enable_nereids_planner=true'
sql 'set enable_fallback_to_original_planner=false'
def test_date = [
"2021-04-12", "1969-12-31", "1356-12-12", "0001-01-01", "9998-12-31",
"2021-04-12", "1969-12-31", "1356-12-12", "0001-01-01", "9998-12-31",
"2021-04-12 12:54:53", "1969-12-31 23:59:59", "1356-12-12 12:56:12", "0001-01-01 00:00:01", "9998-12-31 00:00:59",
"2021-04-12 12:54:53", "1969-12-31 23:59:59", "1356-12-12 12:56:12", "0001-01-01 00:00:01", "9998-12-31 00:00:59"
]
def test_int = [1, 10, 25, 50, 1024]
for (date in test_date) {
for (interval in test_int) {
qt_sql "select date_add('${date}', ${interval}), date_sub('${date}', ${interval}), years_add('${date}', ${interval}), years_sub('${date}', ${interval})"
qt_sql "select months_add('${date}', ${interval}), months_sub('${date}', ${interval}), days_add('${date}', ${interval}), days_sub('${date}', ${interval})"
qt_sql "select hours_add('${date}', ${interval}), hours_sub('${date}', ${interval}), minutes_add('${date}', ${interval}), minutes_sub('${date}', ${interval})"
qt_sql "select seconds_add('${date}', ${interval}), seconds_sub('${date}', ${interval})"
}
}
for (date in test_date) {
for (date1 in test_date) {
qt_sql "select datediff('${date}', '${date1}')"
}
}
for (date in test_date) {
qt_sql "select year('${date}'), month('${date}'), dayofyear('${date}'), dayofmonth('${date}'), dayofweek('${date}'), day('${date}')"
qt_sql "select hour('${date}'), minute('${date}'), second('${date}')"
}
for (date in test_date) {
qt_sql "select date_format('${date}', '%Y-%m-%d'), to_monday('${date}'), last_day('${date}'), to_date('${date}'), to_days('${date}')"
}
for (date in test_date) {
qt_sql "select date_trunc('${date}', 'year'), date_trunc('${date}', 'month'), date_trunc('${date}', 'day')"
qt_sql "select date_trunc('${date}', 'hour'), date_trunc('${date}', 'minute'), date_trunc('${date}', 'second')"
}
for (date in test_date) {
qt_sql "select to_monday('${date}'), last_day('${date}'), to_date('${date}'), to_days('${date}'), date('${date}'), datev2('${date}')"
}
test_year = [2001, 2013, 123, 1969, 2023]
for (year in test_year) {
for (integer in test_int) {
qt_sql "select makedate(${year}, ${integer}), from_days(${year * integer}), from_unixtime(${year / 10 * year * integer})"
}
}
for (date in test_date) {
qt_sql "select unix_timestamp('${date}')"
}
String res
// check fold constant
for (date in test_date) {
for (interval in test_int) {
res = sql "explain select date_add('${date}', ${interval}), date_sub('${date}', ${interval}), years_add('${date}', ${interval}), years_sub('${date}', ${interval})"
res = res.split('VUNION')[1]
assertFalse(res.contains("add") || res.contains("sub"))
res = sql "explain select months_add('${date}', ${interval}), months_sub('${date}', ${interval}), days_add('${date}', ${interval}), days_sub('${date}', ${interval})"
res = res.split('VUNION')[1]
assertFalse(res.contains("add") || res.contains("sub"))
res = sql "explain select hours_add('${date}', ${interval}), hours_sub('${date}', ${interval}), minutes_add('${date}', ${interval}), minutes_sub('${date}', ${interval})"
res = res.split('VUNION')[1]
assertFalse(res.contains("add") || res.contains("sub"))
res = sql "explain select seconds_add('${date}', ${interval}), seconds_sub('${date}', ${interval})"
res = res.split('VUNION')[1]
assertFalse(res.contains("add") || res.contains("sub"))
}
}
for (date in test_date) {
for (date1 in test_date) {
res = sql "explain select datediff('${date}', '${date1}')"
res = res.split('VUNION')[1]
assertFalse(res.contains("datediff"))
}
}
for (date in test_date) {
res = sql "explain select year('${date}'), month('${date}'), dayofyear('${date}'), dayofmonth('${date}'), dayofweek('${date}'), day('${date}')"
res = res.split('VUNION')[1]
assertFalse(res.contains("year") || res.contains("month") || res.contains("dayofyear")
|| res.contains("dayofmonth") || res.contains("dayofweek") || res.contains("day"))
res = sql "explain select hour('${date}'), minute('${date}'), second('${date}')"
res = res.split('VUNION')[1]
assertFalse(res.contains("hour") || res.contains("minute") || res.contains("second"))
}
for (date in test_date) {
res = sql "explain select date_format('${date}', '%Y-%m-%d'), to_monday('${date}'), last_day('${date}'), to_date('${date}'), to_days('${date}')"
res = res.split('VUNION')[1]
assertFalse(res.contains("date_format"))
}
for (date in test_date) {
res = sql "explain select date_trunc('${date}', 'year'), date_trunc('${date}', 'month'), date_trunc('${date}', 'day')"
res = res.split('VUNION')[1]
assertFalse(res.contains("date_trunc"))
res = sql "explain select date_trunc('${date}', 'hour'), date_trunc('${date}', 'minute'), date_trunc('${date}', 'second')"
res = res.split('VUNION')[1]
assertFalse(res.contains("date_trunc"))
}
for (date in test_date) {
res = sql "explain select to_monday('${date}'), last_day('${date}'), to_date('${date}'), to_days('${date}'), date('${date}'), datev2('${date}')"
res = res.split('VUNION')[1]
assertFalse(res.contains("day") || res.contains("date"))
}
for (year in test_year) {
for (integer in test_int) {
res = sql "explain select makedate(${year}, ${integer}), from_days(${year * integer}), from_unixtime(${year / 10 * year * integer})"
res = res.split('VUNION')[1]
assertFalse(res.contains("makedate") || res.contains("from"))
}
}
for (date in test_date) {
res = sql "explain select unix_timestamp('${date}')"
res = res.split('VUNION')[1]
assertFalse(res.contains("unix"))
}
}

View File

@ -34,7 +34,7 @@ suite("type_cast") {
sql """insert into test_table2 values('2020-05-25');"""
def ret = sql"""explain verbose select * from test_table2 where day > CONVERT_tz('2020-05-25 00:00:00', 'Asia/Shanghai', 'Asia/Shanghai');"""
assertTrue(ret.toString().contains("CAST(day[#0] AS DATETIME)"))
assertTrue(ret.toString().contains("CAST(day[#0] AS DATETIMEV2(0))"))
qt_sql """select count(*) from test_table2 where 'a' = 'a';"""
qt_sql """select count(*) from test_table2 where cast('2020-01-01' as date) = cast('2020-01-01' as date);"""

View File

@ -634,7 +634,7 @@ suite("test_date_function") {
explain {
sql("select * from ${tableName} where date(birth) < timestamp(date '2022-01-01')")
contains "`birth` < '2022-01-01 00:00:00'"
contains "`birth` < '2022-01-01'"
}
explain {