-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial sketch of qrep scripting, mechanism should work for cdc too
Needs to address error handling, maybe run inside errgroup as a long way to cancel incoming stream Also need to implement __newindex on LuaRow to allow mutating value
- Loading branch information
Showing
3 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package pua | ||
|
||
import ( | ||
"github.com/yuin/gopher-lua" | ||
|
||
"github.com/PeerDB-io/peer-flow/model" | ||
) | ||
|
||
func AttachToStream(ls *lua.LState, lfn *lua.LFunction, stream *model.QRecordStream) *model.QRecordStream { | ||
output := model.NewQRecordStream(0) | ||
go func() { | ||
schema := stream.Schema() | ||
output.SetSchema(schema) | ||
for record := range stream.Records { | ||
row := model.NewRecordItems(len(record)) | ||
for i, qv := range record { | ||
row.AddColumn(schema.Fields[i].Name, qv) | ||
} | ||
ls.Push(lfn) | ||
ls.Push(LuaRow.New(ls, row)) | ||
if err := ls.PCall(1, 0, nil); err != nil { | ||
panic(err.Error()) // TODO error handling | ||
} | ||
for i, field := range schema.Fields { | ||
record[i] = row.GetColumnValue(field.Name) | ||
} | ||
output.Records <- record | ||
} | ||
output.Close(stream.Err()) | ||
}() | ||
return output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters