mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-09 14:41:02 +00:00
Merge pull request #1390 from yuce/update-getting-started
Updated getting started section for latest develop
This commit is contained in:
commit
ec6fa268c7
2 changed files with 73 additions and 69 deletions
|
|
@ -46,16 +46,16 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
// We need to refer to indexes and frames before we can use them in a query.
|
||||
// We need to refer to indexes and fields before we can use them in a query.
|
||||
repository, _ := schema.Index("repository")
|
||||
stargazer, _ := repository.Frame("stargazer")
|
||||
language, _ := repository.Frame("language")
|
||||
stargazer, _ := repository.Field("stargazer")
|
||||
language, _ := repository.Field("language")
|
||||
|
||||
var response *pilosa.QueryResponse
|
||||
|
||||
// Which repositories did user 14 star:
|
||||
response, _ = client.Query(stargazer.Bitmap(14))
|
||||
fmt.Println("User 14 starred: ", response.Result().Bitmap().Bits)
|
||||
response, _ = client.Query(stargazer.Row(14))
|
||||
fmt.Println("User 14 starred: ", response.Result().Row().Columns)
|
||||
|
||||
// What are the top 5 languages in the sample data?
|
||||
response, err = client.Query(language.TopN(5))
|
||||
|
|
@ -68,26 +68,26 @@ func main() {
|
|||
// Which repositories were starred by both user 14 and 19:
|
||||
response, _ = client.Query(
|
||||
repository.Intersect(
|
||||
stargazer.Bitmap(14),
|
||||
stargazer.Bitmap(19)))
|
||||
fmt.Println("Both user 14 and 19 starred:", response.Result().Bitmap().Bits)
|
||||
stargazer.Row(14),
|
||||
stargazer.Row(19)))
|
||||
fmt.Println("Both user 14 and 19 starred:", response.Result().Row().Columns)
|
||||
|
||||
// Which repositories were starred by user 14 or 19:
|
||||
response, _ = client.Query(
|
||||
repository.Union(
|
||||
stargazer.Bitmap(14),
|
||||
stargazer.Bitmap(19)))
|
||||
fmt.Println("User 14 or 19 starred:", response.Result().Bitmap().Bits)
|
||||
stargazer.Row(14),
|
||||
stargazer.Row(19)))
|
||||
fmt.Println("User 14 or 19 starred:", response.Result().Row().Columns)
|
||||
|
||||
// Which repositories were starred by user 14 or 19 and were written in language 1:
|
||||
response, _ = client.Query(
|
||||
repository.Intersect(
|
||||
repository.Union(
|
||||
stargazer.Bitmap(14),
|
||||
stargazer.Bitmap(19),
|
||||
stargazer.Row(14),
|
||||
stargazer.Row(19),
|
||||
),
|
||||
language.Bitmap(1)))
|
||||
fmt.Println("User 14 or 19 starred, written in language 1:", response.Result().Bitmap().Bits)
|
||||
language.Row(1)))
|
||||
fmt.Println("User 14 or 19 starred, written in language 1:", response.Result().Row().Columns)
|
||||
|
||||
// Set user 99999 as a stargazer for repository 77777?
|
||||
client.Query(stargazer.SetBit(99999, 77777))
|
||||
|
|
@ -112,6 +112,7 @@ We are going to use the index you have created in the [Getting Started](../getti
|
|||
Error handling has been omitted in the example below for brevity.
|
||||
|
||||
```python
|
||||
from __future__ import print_function
|
||||
from pilosa import Index, Client, PilosaError, TimeQuantum
|
||||
|
||||
# We will just use the default client which assumes the server is at http://localhost:10101
|
||||
|
|
@ -122,8 +123,8 @@ client = Client()
|
|||
# and the stargazer data should be imported.
|
||||
# See the Getting Started repository: https://github.com/pilosa/getting-started/
|
||||
|
||||
# Let's create Index and Frame objects, which will contain the settings
|
||||
# for the corresponding indexes and frames.
|
||||
# Let's create Index and Field objects, which will contain the settings
|
||||
# for the corresponding indexes and fields.
|
||||
try:
|
||||
schema = client.schema()
|
||||
except PilosaError as e:
|
||||
|
|
@ -132,13 +133,13 @@ except PilosaError as e:
|
|||
# We will just terminate the program in this case.
|
||||
raise SystemExit(e)
|
||||
|
||||
# We need to refer to indexes and frames before we can use them in a query.
|
||||
# We need to refer to indexes and fields before we can use them in a query.
|
||||
repository = schema.index("repository")
|
||||
stargazer = repository.frame("stargazer")
|
||||
language = repository.frame("language")
|
||||
stargazer = repository.field("stargazer")
|
||||
language = repository.field("language")
|
||||
|
||||
# Which repositories did user 8 star:
|
||||
repository_ids = client.query(stargazer.bitmap(14)).result.bitmap.bits
|
||||
repository_ids = client.query(stargazer.row(14)).result.row.columns
|
||||
print("User 8 starred: ", repository_ids)
|
||||
|
||||
# What are the top 5 languages in the sample data:
|
||||
|
|
@ -147,29 +148,29 @@ print("Top 5 languages: ", [item.id for item in top_languages])
|
|||
|
||||
# Which repositories were starred by both user 14 and 19:
|
||||
query = repository.intersect(
|
||||
stargazer.bitmap(14),
|
||||
stargazer.bitmap(19)
|
||||
stargazer.row(14),
|
||||
stargazer.row(19)
|
||||
)
|
||||
mutually_starred = client.query(query).result.bitmap.bits
|
||||
mutually_starred = client.query(query).result.row.columns
|
||||
print("Both user 14 and 19 starred:", mutually_starred)
|
||||
|
||||
# Which repositories were starred by user 14 or 19:
|
||||
query = repository.union(
|
||||
stargazer.bitmap(14),
|
||||
stargazer.bitmap(19)
|
||||
stargazer.row(14),
|
||||
stargazer.row(19)
|
||||
)
|
||||
either_starred = client.query(query).result.bitmap.bits
|
||||
either_starred = client.query(query).result.row.columns
|
||||
print("User 14 or 19 starred:", either_starred)
|
||||
|
||||
# Which repositories were starred by user 14 or 19 and were written in language 1:
|
||||
query = repository.intersect(
|
||||
repository.union(
|
||||
stargazer.bitmap(14),
|
||||
stargazer.bitmap(19)
|
||||
stargazer.row(14),
|
||||
stargazer.row(19)
|
||||
),
|
||||
language.bitmap(1)
|
||||
language.row(1)
|
||||
)
|
||||
mutually_starred = client.query(query).result.bitmap.bits
|
||||
mutually_starred = client.query(query).result.row.columns
|
||||
print("User 14 or 19 starred, written in language 1:", mutually_starred)
|
||||
|
||||
# Set user 99999 as a stargazer for repository 77777
|
||||
|
|
@ -218,10 +219,10 @@ public class StarTrace {
|
|||
throw new RuntimeException(ex);
|
||||
}
|
||||
|
||||
// We need to refer to indexes and frames before we can use them in a query.
|
||||
// We need to refer to indexes and fields before we can use them in a query.
|
||||
Index repository = schema.index("repository");
|
||||
Frame stargazer = repository.frame("stargazer");
|
||||
Frame language = repository.frame("language");
|
||||
Field stargazer = repository.field("stargazer");
|
||||
Field language = repository.field("language");
|
||||
|
||||
QueryResponse response;
|
||||
QueryResult result;
|
||||
|
|
@ -229,8 +230,8 @@ public class StarTrace {
|
|||
List<Long> repositoryIDs;
|
||||
|
||||
// Which repositories did user 14 star:
|
||||
response = client.query(stargazer.bitmap(14));
|
||||
repositoryIDs = response.getResult().getBitmap().getBits();
|
||||
response = client.query(stargazer.row(14));
|
||||
repositoryIDs = response.getResult().getRow().getColumns();
|
||||
System.out.println("User 14 starred: " + repositoryIDs);
|
||||
|
||||
// What are the top 5 languages in the sample data:
|
||||
|
|
@ -245,32 +246,32 @@ public class StarTrace {
|
|||
|
||||
// Which repositories were starred by both user 14 and 19:
|
||||
query = repository.intersect(
|
||||
stargazer.bitmap(14),
|
||||
stargazer.bitmap(19)
|
||||
stargazer.row(14),
|
||||
stargazer.row(19)
|
||||
);
|
||||
response = client.query(query);
|
||||
repositoryIDs = response.getResult().getBitmap().getBits();
|
||||
repositoryIDs = response.getResult().getRow().getColumns();
|
||||
System.out.println("Both user 14 and 19 starred: " + repositoryIDs);
|
||||
|
||||
// Which repositories were starred by user 14 or 19:
|
||||
query = repository.union(
|
||||
stargazer.bitmap(14),
|
||||
stargazer.bitmap(19)
|
||||
stargazer.row(14),
|
||||
stargazer.row(19)
|
||||
);
|
||||
response = client.query(query);
|
||||
repositoryIDs = response.getResult().getBitmap().getBits();
|
||||
repositoryIDs = response.getResult().getRow().getColumns();
|
||||
System.out.println("User 14 or 19 starred: " + repositoryIDs);
|
||||
|
||||
// Which repositories were starred by user 14 or 19 and were written in language 1:
|
||||
query = repository.intersect(
|
||||
repository.union(
|
||||
stargazer.bitmap(14),
|
||||
stargazer.bitmap(19)
|
||||
stargazer.row(14),
|
||||
stargazer.row(19)
|
||||
),
|
||||
language.bitmap(1)
|
||||
language.row(1)
|
||||
);
|
||||
response = client.query(query);
|
||||
repositoryIDs = response.getResult().getBitmap().getBits();
|
||||
repositoryIDs = response.getResult().getRow().getColumns();
|
||||
System.out.println("User 14 or 19 starred, written in language 1: " + repositoryIDs);
|
||||
|
||||
// Set user 99999 as a stargazer for repository 77777:
|
||||
|
|
|
|||
|
|
@ -34,14 +34,15 @@ Let's make sure Pilosa is running:
|
|||
curl localhost:10101/status
|
||||
```
|
||||
``` response
|
||||
{"state":"NORMAL","nodes":[{"id":"18eb5546-5a1a-4ba4-9c52-b53fbe22317e","uri":{"scheme":"http","host":"localhost","port":10101}}]}
|
||||
{"state":"NORMAL","nodes":[{"id":"91715a50-7d50-4c54-9a03-873801da1cd1","uri":{"scheme":"http","host":"localhost","port
|
||||
":10101},"isCoordinator":true}],"localID":"91715a50-7d50-4c54-9a03-873801da1cd1"}
|
||||
```
|
||||
|
||||
### Sample Project
|
||||
|
||||
In order to better understand Pilosa's capabilities, we will create a sample project called "Star Trace" containing information about 1,000 popular Github repositories which have "go" in their name. The Star Trace index will include data points such as programming language, tags, and stargazers—people who have starred a project.
|
||||
|
||||
Although Pilosa doesn't keep the data in a tabular format, we still use the terms "columns" and "rows" when describing the data model. We put the primary objects in columns, and the properties of those objects in rows. For example, the Star Trace project will contain an index called "repository" which contains columns representing Github repositories, and rows representing properties like programming languages and tags. We can better organize the rows by grouping them into sets called Frames. So the "repository" index might have a "languages" frame as well as a "tags" frame. You can learn more about indexes and frames in the [Data Model](../data-model/) section of the documentation.
|
||||
Although Pilosa doesn't keep the data in a tabular format, we still use the terms "columns" and "rows" when describing the data model. We put the primary objects in columns, and the properties of those objects in rows. For example, the Star Trace project will contain an index called "repository" which contains columns representing Github repositories, and rows representing properties like programming languages and tags. We can better organize the rows by grouping them into sets called Fields. So the "repository" index might have a "languages" field as well as a "tags" field. You can learn more about indexes and fields in the [Data Model](../data-model/) section of the documentation.
|
||||
|
||||
#### Create the Schema
|
||||
|
||||
|
|
@ -55,7 +56,7 @@ curl localhost:10101/schema
|
|||
{"indexes":null}
|
||||
```
|
||||
|
||||
Before we can import data or run queries, we need to create our indexes and the frames within them. Let's create the repository index first:
|
||||
Before we can import data or run queries, we need to create our indexes and the fields within them. Let's create the repository index first:
|
||||
``` request
|
||||
curl localhost:10101/index/repository -X POST
|
||||
```
|
||||
|
|
@ -63,27 +64,29 @@ curl localhost:10101/index/repository -X POST
|
|||
{}
|
||||
```
|
||||
|
||||
Let's create the `stargazer` frame which has user IDs of stargazers as its rows:
|
||||
Let's create the `stargazer` field which has user IDs of stargazers as its rows:
|
||||
``` request
|
||||
curl localhost:10101/index/repository/frame/stargazer \
|
||||
curl localhost:10101/index/repository/field/stargazer \
|
||||
-X POST \
|
||||
-d '{"options": {"timeQuantum": "YMD"}}'
|
||||
-d '{"options": {"type": "time", "timeQuantum": "YMD"}}'
|
||||
```
|
||||
``` response
|
||||
{}
|
||||
```
|
||||
|
||||
Since our data contains time stamps for the time users starred repos, we set the *time quantum* for the `stargazer` frame in the options as well. Time quantum is the resolution of the time we want to use, and we set it to `YMD` (year, month, day) for `stargazer`.
|
||||
Since our data contains time stamps for the time users starred repos, we set the field type to `time`. Time quantum is the resolution of the time we want to use, and we set it to `YMD` (year, month, day) for `stargazer`.
|
||||
|
||||
Next up is the `language` frame, which will contain IDs for programming languages:
|
||||
Next up is the `language` field, which will contain IDs for programming languages:
|
||||
``` request
|
||||
curl localhost:10101/index/repository/frame/language \
|
||||
curl localhost:10101/index/repository/field/language \
|
||||
-X POST
|
||||
```
|
||||
``` response
|
||||
{}
|
||||
```
|
||||
|
||||
The `language` is a `set` field, but since the default field type is `set`, we didn't specify it in field options.
|
||||
|
||||
#### Import Data From CSV Files
|
||||
|
||||
Download the `stargazer.csv` and `language.csv` files here:
|
||||
|
|
@ -116,14 +119,14 @@ Which repositories did user 14 star:
|
|||
``` request
|
||||
curl localhost:10101/index/repository/query \
|
||||
-X POST \
|
||||
-d 'Bitmap(frame="stargazer", row=14)'
|
||||
-d 'Bitmap(field="stargazer", row=14)'
|
||||
```
|
||||
``` response
|
||||
{
|
||||
"results":[
|
||||
{
|
||||
"attrs":{},
|
||||
"bits":[1,2,3,362,368,391,396,409,416,430,436,450,454,460,461,464,466,469,470,483,484,486,490,491,503,504,514]
|
||||
"columns":[1,2,3,362,368,391,396,409,416,430,436,450,454,460,461,464,466,469,470,483,484,486,490,491,503,504,514]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -133,7 +136,7 @@ What are the top 5 languages in the sample data:
|
|||
``` request
|
||||
curl localhost:10101/index/repository/query \
|
||||
-X POST \
|
||||
-d 'TopN(frame="language", n=5)'
|
||||
-d 'TopN(field="language", n=5)'
|
||||
```
|
||||
``` response
|
||||
{
|
||||
|
|
@ -154,8 +157,8 @@ Which repositories were starred by user 14 and 19:
|
|||
curl localhost:10101/index/repository/query \
|
||||
-X POST \
|
||||
-d 'Intersect(
|
||||
Bitmap(frame="stargazer", row=14),
|
||||
Bitmap(frame="stargazer", row=19)
|
||||
Bitmap(field="stargazer", row=14),
|
||||
Bitmap(field="stargazer", row=19)
|
||||
)'
|
||||
```
|
||||
``` response
|
||||
|
|
@ -163,7 +166,7 @@ curl localhost:10101/index/repository/query \
|
|||
"results":[
|
||||
{
|
||||
"attrs":{},
|
||||
"bits":[2,3,362,396,416,461,464,466,470,486]
|
||||
"columns":[2,3,362,396,416,461,464,466,470,486]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -174,8 +177,8 @@ Which repositories were starred by user 14 or 19:
|
|||
curl localhost:10101/index/repository/query \
|
||||
-X POST \
|
||||
-d 'Union(
|
||||
Bitmap(frame="stargazer", row=14),
|
||||
Bitmap(frame="stargazer", row=19)
|
||||
Bitmap(field="stargazer", row=14),
|
||||
Bitmap(field="stargazer", row=19)
|
||||
)'
|
||||
```
|
||||
``` response
|
||||
|
|
@ -183,7 +186,7 @@ curl localhost:10101/index/repository/query \
|
|||
"results":[
|
||||
{
|
||||
"attrs":{},
|
||||
"bits":[1,2,3,361,362,368,376,377,378,382,386,388,391,396,398,400,409,411,412,416,426,428,430,435,436,450,452,453,454,456,460,461,464,465,466,469,470,483,484,486,487,489,490,491,500,503,504,505,512,514]
|
||||
"columns":[1,2,3,361,362,368,376,377,378,382,386,388,391,396,398,400,409,411,412,416,426,428,430,435,436,450,452,453,454,456,460,461,464,465,466,469,470,483,484,486,487,489,490,491,500,503,504,505,512,514]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -194,9 +197,9 @@ Which repositories were starred by user 14 and 19 and also were written in langu
|
|||
curl localhost:10101/index/repository/query \
|
||||
-X POST \
|
||||
-d 'Intersect(
|
||||
Bitmap(frame="stargazer", row=14),
|
||||
Bitmap(frame="stargazer", row=19),
|
||||
Bitmap(frame="language", row=1)
|
||||
Bitmap(field="stargazer", row=14),
|
||||
Bitmap(field="stargazer", row=19),
|
||||
Bitmap(field="language", row=1)
|
||||
)'
|
||||
```
|
||||
``` response
|
||||
|
|
@ -204,7 +207,7 @@ curl localhost:10101/index/repository/query \
|
|||
"results":[
|
||||
{
|
||||
"attrs":{},
|
||||
"bits":[2,362,416,461]
|
||||
"columns":[2,362,416,461]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -214,7 +217,7 @@ Set user 99999 as a stargazer for repository 77777:
|
|||
``` request
|
||||
curl localhost:10101/index/repository/query \
|
||||
-X POST \
|
||||
-d 'SetBit(frame="stargazer", col=77777, row=99999)'
|
||||
-d 'SetBit(field="stargazer", col=77777, row=99999)'
|
||||
```
|
||||
``` response
|
||||
{"results":[true]}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue