-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Mutation typed input #2167
Changes from 21 commits
f8ab109
0462b75
0ae5b5a
b49ddb8
3b473d0
fafb111
266b197
3ed7679
63d9f7c
808a3b0
44cbfb3
8838487
0080965
7853ade
1f1ede4
cbf948d
0d6e6c0
36adf4c
6993345
35f895f
f0687c9
245ceb5
4bd619f
876a693
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,6 @@ | |
package planner | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/sourcenetwork/defradb/client" | ||
"github.com/sourcenetwork/defradb/client/request" | ||
"github.com/sourcenetwork/defradb/core" | ||
|
@@ -37,9 +35,9 @@ type createNode struct { | |
// collection name, meta-data, etc. | ||
collection client.Collection | ||
|
||
// newDoc is the JSON string of the new document, unparsed | ||
newDocStr string | ||
doc *client.Document | ||
// input map of fields and values | ||
input map[string]any | ||
doc *client.Document | ||
|
||
err error | ||
|
||
|
@@ -59,7 +57,7 @@ func (n *createNode) Kind() string { return "createNode" } | |
func (n *createNode) Init() error { return nil } | ||
|
||
func (n *createNode) Start() error { | ||
doc, err := client.NewDocFromJSON([]byte(n.newDocStr), n.collection.Schema()) | ||
doc, err := client.NewDocFromMap(n.input, n.collection.Schema()) | ||
if err != nil { | ||
n.err = err | ||
return err | ||
|
@@ -135,24 +133,14 @@ func (n *createNode) Close() error { | |
|
||
func (n *createNode) Source() planNode { return n.results } | ||
|
||
func (n *createNode) simpleExplain() (map[string]any, error) { | ||
data := map[string]any{} | ||
err := json.Unmarshal([]byte(n.newDocStr), &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return map[string]any{ | ||
dataLabel: data, | ||
}, nil | ||
} | ||
|
||
// Explain method returns a map containing all attributes of this node that | ||
// are to be explained, subscribes / opts-in this node to be an explainablePlanNode. | ||
func (n *createNode) Explain(explainType request.ExplainType) (map[string]any, error) { | ||
switch explainType { | ||
case request.SimpleExplain: | ||
return n.simpleExplain() | ||
return map[string]any{ | ||
dataLabel: n.input, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: the name |
||
}, nil | ||
|
||
case request.ExecuteExplain: | ||
return map[string]any{ | ||
|
@@ -173,7 +161,7 @@ func (p *Planner) CreateDoc(parsed *mapper.Mutation) (planNode, error) { | |
// create a mutation createNode. | ||
create := &createNode{ | ||
p: p, | ||
newDocStr: parsed.Data, | ||
input: parsed.Input, | ||
results: results, | ||
docMapper: docMapper{parsed.DocumentMapping}, | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -31,7 +31,8 @@ | |||||
|
||||||
docIDs []string | ||||||
|
||||||
patch string | ||||||
// input map of fields and values | ||||||
input map[string]any | ||||||
|
||||||
isUpdating bool | ||||||
|
||||||
|
@@ -67,7 +68,11 @@ | |||||
if err != nil { | ||||||
return false, err | ||||||
} | ||||||
_, err = n.collection.UpdateWithDocID(n.p.ctx, docID, n.patch) | ||||||
patch, err := json.Marshal(n.input) | ||||||
if err != nil { | ||||||
return false, err | ||||||
} | ||||||
_, err = n.collection.UpdateWithDocID(n.p.ctx, docID, string(patch)) | ||||||
if err != nil { | ||||||
return false, err | ||||||
} | ||||||
|
@@ -126,12 +131,7 @@ | |||||
} | ||||||
|
||||||
// Add the attribute that represents the patch to update with. | ||||||
data := map[string]any{} | ||||||
err := json.Unmarshal([]byte(n.patch), &data) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
simpleExplainMap[dataLabel] = data | ||||||
simpleExplainMap[dataLabel] = n.input | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: Similar to other suggestions please change the variable name to be more relevant.
Suggested change
|
||||||
|
||||||
return simpleExplainMap, nil | ||||||
} | ||||||
|
@@ -160,7 +160,7 @@ | |||||
filter: parsed.Filter, | ||||||
docIDs: parsed.DocIDs.Value(), | ||||||
isUpdating: true, | ||||||
patch: parsed.Data, | ||||||
input: parsed.Input, | ||||||
docMapper: docMapper{parsed.DocumentMapping}, | ||||||
} | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: Please delete this
Data
variable now, it is now not used anywhere.