Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 61214ea

Browse files
committed
Introducing logical fromUnixTime func
1 parent 40ac249 commit 61214ea

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

platform/frontend_connectors/schema_transformer.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -912,8 +912,9 @@ func (s *SchemaCheckPass) convertQueryDateTimeFunctionToClickhouse(indexSchema s
912912
}
913913
return model.NewFunction("toHour", e.Args[0].Accept(b).(model.Expr))
914914

915-
// TODO this is a place for over date/time related functions
916-
// add more
915+
case model.FromUnixTimeFunction:
916+
args := b.VisitChildren(e.Args)
917+
return model.NewFunction("fromUnixTimestamp64Milli", args...)
917918

918919
default:
919920
return visitFunction(b, e)
@@ -941,9 +942,9 @@ func (s *SchemaCheckPass) convertQueryDateTimeFunctionToDoris(indexSchema schema
941942
return e
942943
}
943944
return model.NewFunction("HOUR", e.Args[0].Accept(b).(model.Expr))
944-
945-
// TODO this is a place for over date/time related functions
946-
// add more
945+
case model.FromUnixTimeFunction:
946+
args := b.VisitChildren(e.Args)
947+
return model.NewFunction("FROM_UNIXTIME", args...)
947948

948949
default:
949950
return visitFunction(b, e)
@@ -1083,7 +1084,7 @@ func (s *SchemaCheckPass) acceptIntsAsTimestamps(indexSchema schema.Schema, quer
10831084
}
10841085
}
10851086
if ok {
1086-
if f, okF := model.ToFunction(expr); okF && f.Name == "fromUnixTimestamp64Milli" && len(f.Args) == 1 {
1087+
if f, okF := model.ToFunction(expr); okF && f.Name == model.FromUnixTimeFunction && len(f.Args) == 1 {
10871088
if l, okL := model.ToLiteral(f.Args[0]); okL {
10881089
if _, exists := l.Format(); exists { // heuristics: it's a date <=> it has a format
10891090
return model.NewInfixExpr(col, e.Op, f.Args[0])
@@ -1105,7 +1106,7 @@ func (s *SchemaCheckPass) acceptIntsAsTimestamps(indexSchema schema.Schema, quer
11051106
if f.Name == "toTimezone" && len(f.Args) == 2 {
11061107
if col, ok := model.ExtractColRef(f.Args[0]); ok && table.IsInt(col.ColumnName) {
11071108
// adds fromUnixTimestamp64Milli
1108-
return model.NewFunction("toTimezone", model.NewFunction("fromUnixTimestamp64Milli", f.Args[0]), f.Args[1])
1109+
return model.NewFunction("toTimezone", model.NewFunction(model.FromUnixTimeFunction, f.Args[0]), f.Args[1])
11091110
}
11101111
}
11111112
return visitFunction(b, f)

platform/frontend_connectors/schema_transformer_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2039,7 +2039,7 @@ func Test_acceptIntsAsTimestamps(t *testing.T) {
20392039
model.NewInfixExpr(
20402040
model.NewFunction("timeZoneOffset", model.NewFunction(
20412041
"toTimezone",
2042-
model.NewFunction("fromUnixTimestamp64Milli", model.NewColumnRef("timestampInt")),
2042+
model.NewFunction(model.FromUnixTimeFunction, model.NewColumnRef("timestampInt")),
20432043
model.NewLiteral("'Europe/Warsaw'")),
20442044
),
20452045
"*",

0 commit comments

Comments
 (0)