Skip to content

Commit 69b5835

Browse files
Merge pull request #22 from SlicingDice/feature/update-tests_and_examples
Update count event/entities queries from tests and examples
2 parents 2cc49c5 + 7ee983b commit 69b5835

16 files changed

+30229
-31014
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Updated
44
- Update API errors code
5+
- Remove auto_create_columns parameter from insert method
56

67
## [1.0.0]
78
### Added

README.md

Lines changed: 93 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Official Python client for [SlicingDice](http://www.slicingdice.com/), Data Ware
99

1010
If you are new to SlicingDice, check our [quickstart guide](http://panel.slicingdice.com/docs/#quickstart-guide) and learn to use it in 15 minutes.
1111

12-
Please refer to the [SlicingDice official documentation](http://panel.slicingdice.com/docs/) for more information on [analytics databases](http://panel.slicingdice.com/docs/#analytics-concepts), [data modeling](http://panel.slicingdice.com/docs/#data-modeling), [indexing](http://panel.slicingdice.com/docs/#data-indexing), [querying](http://panel.slicingdice.com/docs/#data-querying), [limitations](http://panel.slicingdice.com/docs/#current-slicingdice-limitations) and [API details](http://panel.slicingdice.com/docs/#api-details).
12+
Please refer to the [SlicingDice official documentation](http://panel.slicingdice.com/docs/) for more information on [analytics databases](http://panel.slicingdice.com/docs/#analytics-concepts), [data modeling](http://panel.slicingdice.com/docs/#data-modeling), [insertion](http://panel.slicingdice.com/docs/#data-insertion), [querying](http://panel.slicingdice.com/docs/#data-querying), [limitations](http://panel.slicingdice.com/docs/#current-slicingdice-limitations) and [API details](http://panel.slicingdice.com/docs/#api-details).
1313

1414
## Tests and Examples
1515

@@ -40,18 +40,19 @@ from pyslicer import SlicingDice
4040
# Configure the client
4141
client = SlicingDice(master_key='API_KEY', uses_test_endpoint=False)
4242

43-
# Indexing data
44-
index_data = {
43+
# Inserting data
44+
insert_data = {
4545
"user1@slicingdice.com": {
4646
"age": 22
4747
},
48-
"auto-create-fields": True
48+
"auto-create": ["table", "column"]
4949
}
50-
client.index(index_data)
50+
client.insert(insert_data)
5151

5252
# Querying data
5353
query_data = {
54-
"users-between-20-and-40": [
54+
"query-name": "users-between-20-and-40",
55+
"query": [
5556
{
5657
"age": {
5758
"range": [
@@ -84,49 +85,37 @@ print client.count_entity(query_data)
8485
* `timeout (int)` - Amount of time, in seconds, to wait for results for each request.
8586
* `uses_test_endpoint (bool)` - If false the client will send requests to production end-point, otherwise to tests end-point.
8687

87-
### `get_projects()`
88-
Get all created projects, both active and inactive ones. This method corresponds to a [GET request at /project](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-project).
88+
### `get_database()`
89+
Get information about current database(related to api keys informed on construction). This method corresponds to a [GET request at /database](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-database).
8990

9091
#### Request example
9192

9293
```python
9394
from pyslicer import SlicingDice
9495
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
95-
print client.get_projects()
96+
print client.get_database()
9697
```
9798

9899
#### Output example
99100

100101
```json
101102
{
102-
"active": [
103-
{
104-
"name": "Project 1",
105-
"description": "My first project",
106-
"data-expiration": 30,
107-
"created-at": "2016-04-05T10:20:30Z"
108-
}
109-
],
110-
"inactive": [
111-
{
112-
"name": "Project 2",
113-
"description": "My second project",
114-
"data-expiration": 90,
115-
"created-at": "2016-04-05T10:20:30Z"
116-
}
117-
]
103+
"name": "Database 1",
104+
"description": "My first database",
105+
"data-expiration": 30,
106+
"created-at": "2016-04-05T10:20:30Z"
118107
}
119108
```
120109

121-
### `get_fields(test=False)`
122-
Get all created fields, both active and inactive ones. This method corresponds to a [GET request at /field](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-field).
110+
### `get_columns(test=False)`
111+
Get all created columns, both active and inactive ones. This method corresponds to a [GET request at /column](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-column).
123112

124113
#### Request example
125114

126115
```python
127116
from pyslicer import SlicingDice
128117
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
129-
print client.get_fields()
118+
print client.get_columns()
130119
```
131120

132121
#### Output example
@@ -157,22 +146,22 @@ print client.get_fields()
157146
}
158147
```
159148

160-
### `create_field(json_data, test=False)`
161-
Create a new field. This method corresponds to a [POST request at /field](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-field).
149+
### `create_column(json_data, test=False)`
150+
Create a new column. This method corresponds to a [POST request at /column](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-column).
162151

163152
#### Request example
164153

165154
```python
166155
from pyslicer import SlicingDice
167156
client = SlicingDice('MASTER_API_KEY', uses_test_endpoint=False)
168-
field = {
157+
column = {
169158
"name": "Year",
170159
"api-name": "year",
171160
"type": "integer",
172161
"description": "Year of manufacturing",
173162
"storage": "latest-value"
174163
}
175-
print client.create_field(field)
164+
print client.create_column(column)
176165
```
177166

178167
#### Output example
@@ -184,15 +173,15 @@ print client.create_field(field)
184173
}
185174
```
186175

187-
### `index(json_data, auto_create_fields=False)`
188-
Index data to existing entities or create new entities, if necessary. This method corresponds to a [POST request at /index](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-index).
176+
### `insert(json_data)`
177+
Insert data to existing entities or create new entities, if necessary. This method corresponds to a [POST request at /insert](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-insert).
189178

190179
#### Request example
191180

192181
```python
193182
from pyslicer import SlicingDice
194183
client = SlicingDice('MASTER_OR_WRITE_API_KEY', uses_test_endpoint=False)
195-
index_data = {
184+
insert_data = {
196185
"user1@slicingdice.com": {
197186
"car-model": "Ford Ka",
198187
"year": 2016
@@ -225,24 +214,24 @@ index_data = {
225214
"date": "2016-08-17T13:23:47+00:00"
226215
}
227216
},
228-
"auto-create-fields": True
217+
"auto-create": ["table", "column"]
229218
}
230-
print client.index(index_data)
219+
print client.insert(insert_data)
231220
```
232221

233222
#### Output example
234223

235224
```json
236225
{
237226
"status": "success",
238-
"indexed-entities": 4,
239-
"indexed-fields": 12,
227+
"inserted-entities": 4,
228+
"inserted-columns": 12,
240229
"took": 0.023
241230
}
242231
```
243232

244233
### `exists_entity(ids)`
245-
Verify which entities exist in a project given a list of entity IDs. This method corresponds to a [POST request at /query/exists/entity](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-query-exists-entity).
234+
Verify which entities exist in a database given a list of entity IDs. This method corresponds to a [POST request at /query/exists/entity](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-query-exists-entity).
246235

247236
#### Request example
248237

@@ -274,7 +263,7 @@ print client.exists_entity(ids)
274263
```
275264

276265
### `count_entity_total()`
277-
Count the number of indexed entities. This method corresponds to a [GET request at /query/count/entity/total](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-query-count-entity-total).
266+
Count the number of inserted entities. This method corresponds to a [GET request at /query/count/entity/total](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-query-count-entity-total).
278267

279268
#### Request example
280269

@@ -304,29 +293,36 @@ Count the number of entities matching the given query. This method corresponds t
304293
```python
305294
from pyslicer import SlicingDice
306295
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
307-
query = {
308-
"corolla-or-fit": [
309-
{
310-
"car-model": {
311-
"equals": "toyota corolla"
312-
}
313-
},
314-
"or",
315-
{
316-
"car-model": {
317-
"equals": "honda fit"
296+
query = [
297+
{
298+
"query-name": "corolla-or-fit",
299+
"query": [
300+
{
301+
"car-model": {
302+
"equals": "toyota corolla"
303+
}
304+
},
305+
"or",
306+
{
307+
"car-model": {
308+
"equals": "honda fit"
309+
}
318310
}
319-
},
320-
],
321-
"ford-ka": [
322-
{
323-
"car-model": {
324-
"equals": "ford ka"
311+
],
312+
"bypass-cache": False
313+
},
314+
{
315+
"query-name": "ford-ka",
316+
"query": [
317+
{
318+
"car-model": {
319+
"equals": "ford ka"
320+
}
325321
}
326-
}
327-
],
328-
"bypass-cache": False
329-
}
322+
],
323+
"bypass-cache": False
324+
}
325+
]
330326
print client.count_entity(query)
331327
```
332328

@@ -351,31 +347,38 @@ Count the number of occurrences for time-series events matching the given query.
351347
```python
352348
from pyslicer import SlicingDice
353349
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
354-
query = {
355-
"test-drives-in-ny": [
356-
{
357-
"test-drives": {
358-
"equals": "NY",
359-
"between": [
360-
"2016-08-16T00:00:00Z",
361-
"2016-08-18T00:00:00Z"
362-
]
350+
query = [
351+
{
352+
"query-name": "test-drives-in-ny",
353+
"query": [
354+
{
355+
"test-drives": {
356+
"equals": "NY",
357+
"between": [
358+
"2016-08-16T00:00:00Z",
359+
"2016-08-18T00:00:00Z"
360+
]
361+
}
363362
}
364-
}
365-
],
366-
"test-drives-in-ca": [
367-
{
368-
"test-drives": {
369-
"equals": "CA",
370-
"between": [
371-
"2016-04-04T00:00:00Z",
372-
"2016-04-06T00:00:00Z"
373-
]
363+
],
364+
"bypass-cache": True
365+
},
366+
{
367+
"query-name": "test-drives-in-ca",
368+
"query": [
369+
{
370+
"test-drives": {
371+
"equals": "CA",
372+
"between": [
373+
"2016-04-04T00:00:00Z",
374+
"2016-04-06T00:00:00Z"
375+
]
376+
}
374377
}
375-
}
376-
],
377-
"bypass-cache": True
378-
}
378+
],
379+
"bypass-cache": True
380+
}
381+
]
379382
print client.count_event(query)
380383
```
381384

@@ -451,7 +454,7 @@ print client.top_values(query)
451454
```
452455

453456
### `aggregation(json_data)`
454-
Return the aggregation of all fields in the given query. This method corresponds to a [POST request at /query/aggregation](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-query-aggregation).
457+
Return the aggregation of all columns in the given query. This method corresponds to a [POST request at /query/aggregation](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-query-aggregation).
455458

456459
#### Request example
457460

@@ -730,7 +733,7 @@ print client.delete_saved_query('my-saved-query')
730733
```
731734

732735
### `result(json_data)`
733-
Retrieve indexed values for entities matching the given query. This method corresponds to a [POST request at /data_extraction/result](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-data-extraction-result).
736+
Retrieve inserted values for entities matching the given query. This method corresponds to a [POST request at /data_extraction/result](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-data-extraction-result).
734737

735738
#### Request example
736739

@@ -751,7 +754,7 @@ query = {
751754
}
752755
}
753756
],
754-
"fields": ["car-model", "year"],
757+
"columns": ["car-model", "year"],
755758
"limit": 2
756759
}
757760
print client.result(query)
@@ -778,7 +781,7 @@ print client.result(query)
778781
```
779782

780783
### `score(json_data)`
781-
Retrieve indexed values as well as their relevance for entities matching the given query. This method corresponds to a [POST request at /data_extraction/score](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-data-extraction-score).
784+
Retrieve inserted values as well as their relevance for entities matching the given query. This method corresponds to a [POST request at /data_extraction/score](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-data-extraction-score).
782785

783786
#### Request example
784787

@@ -799,7 +802,7 @@ query = {
799802
}
800803
}
801804
],
802-
"fields": ["car-model", "year"],
805+
"columns": ["car-model", "year"],
803806
"limit": 2
804807
}
805808
print client.score(query)

0 commit comments

Comments
 (0)