Skip to content

Commit

Permalink
Lua: add unchanged_columns field to Record (#1608)
Browse files Browse the repository at this point in the history
This allows disambiguating a null value as unchanged for toast columns

Ignore UnchangedToastColumns on DeleteRecord since queues don't care about soft delete
  • Loading branch information
serprex authored Apr 11, 2024
1 parent 94efd33 commit 3293f8f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions flow/pua/peerdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,39 @@ func LuaRecordIndex(ls *lua.LState) int {
ls.Push(lua.LString(record.GetDestinationTableName()))
case "source":
ls.Push(lua.LString(record.GetSourceTableName()))
case "unchanged_columns":
if ur, ok := record.(*model.UpdateRecord); ok {
tbl := ls.CreateTable(0, len(ur.UnchangedToastColumns))
for col := range ur.UnchangedToastColumns {
tbl.RawSetString(col, lua.LTrue)
}
ls.Push(tbl)
} else {
ls.Push(lua.LNil)
}
default:
return 0
}
return 1
}

func LuaRecordJson(ls *lua.LState) int {
ud := ls.Get(1)
tbl := ls.CreateTable(0, 6)
ud := ls.CheckUserData(1)
tbl := ls.CreateTable(0, 7)
for _, key := range []string{
"kind", "old", "new", "checkpoint", "commit_time", "source",
} {
tbl.RawSetString(key, ls.GetField(ud, key))
}
if ur, ok := ud.Value.(*model.UpdateRecord); ok {
if len(ur.UnchangedToastColumns) > 0 {
unchanged := ls.CreateTable(len(ur.UnchangedToastColumns), 0)
for col := range ur.UnchangedToastColumns {
unchanged.Append(lua.LString(col))
}
tbl.RawSetString("unchanged_columns", unchanged)
}
}
ls.Push(tbl)
return 1
}
Expand Down

0 comments on commit 3293f8f

Please sign in to comment.