Skip to content
Snippets Groups Projects
Unverified Commit 2159bfd8 authored by ou yuanning's avatar ou yuanning Committed by GitHub
Browse files

improve date_add/sub function building (#2808)

parent f53ffa47
No related branches found
No related tags found
No related merge requests found
......@@ -171,6 +171,14 @@ func getFunctionExprByNameAndAstExprs(name string, astExprs []tree.Expr, ctx Com
if len(args) != 2 {
return nil, false, errors.New(errno.SyntaxErrororAccessRuleViolation, "date_add/date_sub function need two args")
}
if args[0].Typ.Id == plan.Type_VARCHAR {
args[0], err = appendCastExpr(args[0], &plan.Type{
Id: plan.Type_DATE,
})
if err != nil {
return
}
}
args, err = resetIntervalFunctionExprs(args[0], args[1])
if err != nil {
return
......
......@@ -403,6 +403,7 @@ func TestSingleTableSqlBuilder(t *testing.T) {
"select sum(n_nationkey) as s from nation order by s",
"select date_add(date '2001-01-01', interval 1 day) as a",
"select date_sub(date '2001-01-01', interval '1 day') as a",
"select date_add('2001-01-01', interval '1 day') as a",
"SELECT N_REGIONKEY + 2 as a, N_REGIONKEY/2, N_REGIONKEY* N_NATIONKEY, N_REGIONKEY % N_NATIONKEY, N_REGIONKEY - N_NATIONKEY FROM NATION WHERE -N_NATIONKEY < -20", //test more expr
"SELECT N_REGIONKEY FROM NATION where N_REGIONKEY >= N_NATIONKEY or (N_NAME like '%ddd' and N_REGIONKEY >0.5)", //test more expr
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment