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

[WIP] Selector-based simple views #5310

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nickva
Copy link
Contributor

@nickva nickva commented Oct 16, 2024

Try to see what a simple selector-based views might look like. Inspired by comments in the "allow_fallback" pr and the discussion in CouchDB dev meeting.

This is as simple as possible:

  • We already have support for design doc languages, so go with that: use "selector" as a language, then use the regular _design/../_view API
  • selector picks documents to be indexed. The usual selector syntax, nothing new
  • keys - list of field values emitted as the key (an array)
  • values - list of fields values emitted as the value (an array)

Example (DB=http://adm:[email protected]:15984)

echo "Recreating DB"
http -q delete $DB/db1
http -b put $DB/db1

echo "Adding some docs"
http -b put $DB/db1/a k:='1' v=x s:='10'
http -b put $DB/db1/b k:='3' v=x s:='11'
http -b put $DB/db1/c k:='4' v=y s:='12'
http -b put $DB/db1/d k:='2' v=x s:='13'
http -b put $DB/db1/e k:='5' v=x s:='14'
http -b put $DB/db1/f w:='1' v=x s:='15'
http -b put $DB/db1/g k:='3' o=o s:='16'

echo "Add two silly selector thingers"
http -b put $DB/db1/_design/s language=selector views:='{
  "v1": {"map": {"selector": {"s":{"$gt":12}}, "keys":["k"], "values":["v"]}},
  "v2": {"map": {"keys":["w"]}}
}'

echo "Query the silly selector thinger"
http -b $DB/db1/_design/s/_view/v1

echo "Query the even sillier one without a selector"
http -b $DB/db1/_design/s/_view/v2

Query the silly selector thinger

{
    "offset": 0,
    "rows": [
        {"id": "d", "key": [2], "value": ["x"]},
        {"id": "e", "key": [5], "value": ["x"]}
    ],
    "total_rows": 2
}

Query the even sillier one without a selector. Pick docs based on keys only.

{
    "offset": 0,
    "rows": [
        {"id": "f", "key": [1], "value": null}
    ],
    "total_rows": 1
}

Try to see what a simple selector-based views might look like. Inspired by
comments in the "allow_fallback" pr and the discussion in CouchDB dev
meeting.

This is as simple as possible:

 * We already have support for design doc languages, so go with
 that: use "selector" as a language, then use the regular `_design/../_view` API
 * `selector` picks documents to be indexed. The usual selector syntax, nothing new
 * `keys` - list of field values emitted as the key (an array)
 * `values` - list of fields values emitted as the value (an array)

Example (DB=http://adm:[email protected]:15984)

```
echo "Recreating DB"
http -q delete $DB/db1
http -b put $DB/db1

echo "Adding some docs"
http -b put $DB/db1/a k:='1' v=x s:='10'
http -b put $DB/db1/b k:='3' v=x s:='11'
http -b put $DB/db1/c k:='4' v=y s:='12'
http -b put $DB/db1/d k:='2' v=x s:='13'
http -b put $DB/db1/e k:='5' v=x s:='14'
http -b put $DB/db1/f w:='1' v=x s:='15'
http -b put $DB/db1/g k:='3' o=o s:='16'

echo "Add two silly selector thingers"
http -b put $DB/db1/_design/s language=selector views:='{
  "v1": {"map": {"selector": {"s":{"$gt":12}}, "keys":["k"], "values":["v"]}},
  "v2": {"map": {"keys":["w"]}}
}'

echo "Query the silly selector thinger"
http -b $DB/db1/_design/s/_view/v1

echo "Query the even sillier one without a selector"
http -b $DB/db1/_design/s/_view/v2
```

Query the silly selector thinger
```
{
    "offset": 0,
    "rows": [
        {"id": "d", "key": [2], "value": ["x"]},
        {"id": "e", "key": [5], "value": ["x"]}
    ],
    "total_rows": 2
}
```

Query the even sillier one without a selector. Pick docs based on `keys` only.

```
{
    "offset": 0,
    "rows": [
        {"id": "f", "key": [1], "value": null}
    ],
    "total_rows": 1
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant