[feature-wip] Support all date functions for datev2/datetimev2 (#11265)

* [feature-wip] (datetimev2) support convert_tz function

* [feature-wip] Support all date functions for datev2/datetimev2
This commit is contained in:
Gabriel
2022-07-28 08:18:59 +08:00
committed by GitHub
parent 87b1f4c071
commit 72d2feae99
22 changed files with 801 additions and 269 deletions

View File

@ -32,6 +32,7 @@ import org.apache.doris.catalog.ScalarFunction;
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.common.util.VectorizedUtil;
@ -1026,10 +1027,12 @@ public class FunctionCallExpr extends Expr {
for (int i = 0; i < argTypes.length; ++i) {
// For varargs, we must compare with the last type in callArgs.argTypes.
int ix = Math.min(args.length - 1, i);
if (!argTypes[i].matchesType(args[ix]) && !(
if (!argTypes[i].matchesType(args[ix]) && Config.use_date_v2_by_default
&& !argTypes[i].isDateType() && (args[ix].isDate() || args[ix].isDatetime())) {
uncheckedCastChild(DateLiteral.getDefaultDateType(args[ix]), i);
} else if (!argTypes[i].matchesType(args[ix]) && !(
argTypes[i].isDateType() && args[ix].isDateType())) {
uncheckedCastChild(args[ix], i);
//if (argTypes[i] != args[ix]) castChild(args[ix], i);
}
}
}
@ -1075,6 +1078,22 @@ public class FunctionCallExpr extends Expr {
this.type = fn.getReturnType();
}
Type[] childTypes = collectChildReturnTypes();
if ((this.type.isDate() || this.type.isDatetime()) && Config.use_date_v2_by_default
&& fn.getArgs().length == childTypes.length) {
boolean implicitCastToDate = false;
for (int i = 0; i < fn.getArgs().length; i++) {
implicitCastToDate = Type.canCastTo(childTypes[i], fn.getArgs()[i]);
if (implicitCastToDate) {
break;
}
}
if (implicitCastToDate) {
this.type = DateLiteral.getDefaultDateType(fn.getReturnType());
fn.setReturnType(DateLiteral.getDefaultDateType(fn.getReturnType()));
}
}
if (this.type.isDecimalV3()) {
// DECIMAL need to pass precision and scale to be
if (DECIMAL_FUNCTION_SET.contains(fn.getFunctionName().getFunction())