Skip to content
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

Allow deletion of specific language. #3242

Merged
merged 3 commits into from Apr 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions chunker/rdf/parse_test.go
Expand Up @@ -114,6 +114,26 @@ var testNQuads = []struct {
ObjectValue: &api.Value{Val: &api.Value_DefaultVal{DefaultVal: "Alice In Wonderland"}},
},
},
{
input: `_:alice <name@en> "Alice In Wonderland" .`,
nq: api.NQuad{
Subject: "_:alice",
Predicate: "name",
ObjectId: "",
Lang: "en",
ObjectValue: &api.Value{Val: &api.Value_DefaultVal{DefaultVal: "Alice In Wonderland"}},
},
},
{
input: `_:alice <name@en> * .`,
nq: api.NQuad{
Subject: "_:alice",
Predicate: "name",
ObjectId: "",
Lang: "en",
ObjectValue: &api.Value{Val: &api.Value_DefaultVal{DefaultVal: "_STAR_ALL"}},
},
},
{
input: `_:alice <name> "Alice In Wonderland"^^<xs:string> .`,
nq: api.NQuad{
Expand Down
44 changes: 44 additions & 0 deletions dgraph/cmd/alpha/run_test.go
Expand Up @@ -1468,6 +1468,50 @@ func TestDeleteScalarValue(t *testing.T) {
require.JSONEq(t, `{"data": {"me":[]}}`, output)
}

func TestDeleteValueLang(t *testing.T) {
var s = `name: string @lang .`
require.NoError(t, schema.ParseBytes([]byte(""), 1))
require.NoError(t, alterSchemaWithRetry(s))

var m = `
{
set {
<0x12345> <name> "Mark"@en .
<0x12345> <name> "Marco"@es .
<0x12345> <name> "Marc"@fr .
}
}
`
err := runMutation(m)
require.NoError(t, err)

q := `
{
me(func: uid(0x12345)) {
name@*
}
}`
output, err := runQuery(q)
require.NoError(t, err)
require.JSONEq(t, `{"data": {"me":[
{"name@en":"Mark", "name@es":"Marco", "name@fr":"Marc"}]}}`, output)

var d1 = `
{
delete {
<0x12345> <name@fr> * .
}
}
`
err = runMutation(d1)
require.NoError(t, err)

// Verify only the specific tagged value was deleted.
output, err = runQuery(q)
require.NoError(t, err)
require.JSONEq(t, output, `{"data": {"me":[{"name@en":"Mark", "name@es":"Marco"}]}}`)
}

func TestDropAll(t *testing.T) {
var m1 = `
{
Expand Down
2 changes: 1 addition & 1 deletion posting/list.go
Expand Up @@ -190,7 +190,7 @@ func (l *List) SetForDeletion() bool {
}

func hasDeleteAll(mpost *pb.Posting) bool {
return mpost.Op == Del && bytes.Equal(mpost.Value, []byte(x.Star))
return mpost.Op == Del && bytes.Equal(mpost.Value, []byte(x.Star)) && len(mpost.LangTag) == 0
}

// Ensure that you either abort the uncommitted postings or commit them before calling me.
Expand Down
13 changes: 13 additions & 0 deletions wiki/content/mutations/index.md
Expand Up @@ -268,6 +268,19 @@ Deleting the value of a non-list predicate (i.e a 1-to-1 relation) can be done i
1. Using the star notation mentioned in the last section.
1. Setting the object to a specific value. If the value passed is not the current value, the mutation will succeed but will have no effect. If the value passed is the current value, the mutation will succeed and will delete the triple.

For language-tagged values, the following special syntax is supported:

```
{
delete {
<0x12345> <name@es> * .
}
}
```

In this example, the value of name tagged with language tag `es` will be deleted.
Other tagged values are left untouched.

## Mutations using cURL

Mutations can be done over HTTP by making a `POST` request to an Alpha's `/mutate` endpoint. On the command line this can be done with curl. To commit the mutation, pass the HTTP header `X-DgraphCommitNow: true`.
Expand Down