Skip to content

Change table to dimension on code #30

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

Merged
merged 1 commit into from
Feb 26, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 14 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SlicingDice Official Python Client (v2.0.0)
# SlicingDice Official Python Client (v2.0.1)
### Build Status: [![CircleCI](https://circleci.com/gh/SlicingDice/slicingdice-python.svg?style=svg)](https://circleci.com/gh/SlicingDice/slicingdice-python)

Official Python client for [SlicingDice](http://www.slicingdice.com/), Data Warehouse and Analytics Database as a Service.
Expand Down Expand Up @@ -43,7 +43,7 @@ insert_data = {
"user1@slicingdice.com": {
"age": 22
},
"auto-create": ["table", "column"]
"auto-create": ["dimension", "column"]
}
client.insert(insert_data)

Expand Down Expand Up @@ -74,17 +74,16 @@ print(client.count_entity(query_data))

### Constructor

`__init__(self, write_key=None, read_key=None, master_key=None, custom_key=None, use_ssl=True, timeout=60, uses_test_endpoint=False)`
`__init__(self, write_key=None, read_key=None, master_key=None, custom_key=None, use_ssl=True, timeout=60)`
* `write_key (str)` - [API key](https://docs.slicingdice.com/docs/api-keys) to authenticate requests with the SlicingDice API Write Key.
* `read_key (str)` - [API key](https://docs.slicingdice.com/docs/api-keys) to authenticate requests with the SlicingDice API Read Key.
* `master_key (str)` - [API key](https://docs.slicingdice.com/docs/api-keys) to authenticate requests with the SlicingDice API Master Key.
* `custom_key (str)` - [API key](https://docs.slicingdice.com/docs/api-keys) to authenticate requests with the SlicingDice API Custom Key.
* `use_ssl (bool)` - Define if the requests verify SSL for HTTPS requests.
* `timeout (int)` - Amount of time, in seconds, to wait for results for each request.
* `uses_test_endpoint (bool)` - If false the client will send requests to production end-point, otherwise to tests end-point.

### `get_database()`
Get information about current database(related to api keys informed on construction). This method corresponds to a `GET` request at `/database`.
Get information about current database(related to api keys informed on construction). This method corresponds to a [`GET` request at `/database`](https://docs.slicingdice.com/docs/how-to-list-edit-or-delete-databases).

#### Request example

Expand All @@ -100,7 +99,7 @@ print(client.get_database())
{
"name": "Database 1",
"description": "My first database",
"tables": [
"dimensions": [
"default",
"users"
],
Expand All @@ -109,7 +108,7 @@ print(client.get_database())
}
```

### `get_columns(test=False)`
### `get_columns()`
Get all created columns, both active and inactive ones. This method corresponds to a [GET request at /column](https://docs.slicingdice.com/docs/how-to-list-edit-or-delete-columns).

#### Request example
Expand Down Expand Up @@ -148,7 +147,7 @@ print(client.get_columns())
}
```

### `create_column(json_data, test=False)`
### `create_column(json_data)`
Create a new column. This method corresponds to a [POST request at /column](https://docs.slicingdice.com/docs/how-to-create-columns#section-creating-columns-using-column-endpoint).

#### Request example
Expand Down Expand Up @@ -216,7 +215,7 @@ insert_data = {
"date": "2016-08-17T13:23:47+00:00"
}
},
"auto-create": ["table", "column"]
"auto-create": ["dimension", "column"]
}
print(client.insert(insert_data))
```
Expand All @@ -232,8 +231,8 @@ print(client.insert(insert_data))
}
```

### `exists_entity(ids, table=None)`
Verify which entities exist in a table (uses `default` table if not provided) given a list of entity IDs. This method corresponds to a [POST request at /query/exists/entity](https://docs.slicingdice.com/docs/exists).
### `exists_entity(ids, dimension=None)`
Verify which entities exist in a dimension (uses `default` dimension if not provided) given a list of entity IDs. This method corresponds to a [POST request at /query/exists/entity](https://docs.slicingdice.com/docs/exists).

#### Request example

Expand Down Expand Up @@ -288,18 +287,18 @@ print(client.count_entity_total())
}
```

### `count_entity_total(tables)`
Count the total number of inserted entities in the given tables. This method corresponds to a [POST request at /query/count/entity/total](https://docs.slicingdice.com/docs/total#section-counting-specific-tables).
### `count_entity_total(dimensions)`
Count the total number of inserted entities in the given dimensions. This method corresponds to a [POST request at /query/count/entity/total](https://docs.slicingdice.com/docs/total#section-counting-specific-tables).

#### Request example

```python
from pyslicer import SlicingDice
client = SlicingDice('MASTER_OR_READ_API_KEY')

tables = ['default']
dimensions = ['default']

print(client.count_entity_total(tables))
print(client.count_entity_total(dimensions))
```

#### Output example
Expand Down
16 changes: 8 additions & 8 deletions pyslicer/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,16 @@ def count_entity(self, query):
url = SlicingDice.BASE_URL + URLResources.QUERY_COUNT_ENTITY
return self._count_query_wrapper(url, query)

def count_entity_total(self, tables=None):
def count_entity_total(self, dimensions=None):
"""Make a count entity total query

Keyword arguments:
tables -- A dictionary containing the tables in which
dimensions -- A dictionary containing the dimensions in which
the total query will be performed
"""
query = {}
if tables is not None:
query['tables'] = tables
if dimensions is not None:
query['dimensions'] = dimensions
url = SlicingDice.BASE_URL + URLResources.QUERY_COUNT_ENTITY_TOTAL
return self._make_request(
url=url,
Expand Down Expand Up @@ -263,12 +263,12 @@ def top_values(self, query):
req_type="post",
key_level=0)

def exists_entity(self, ids, table=None):
def exists_entity(self, ids, dimension=None):
"""Make a exists entity query

Keyword arguments:
ids -- A list with entities to check if exists
table -- In which table entities check be checked
dimension -- In which dimension entities check be checked
"""
url = SlicingDice.BASE_URL + URLResources.QUERY_EXISTS_ENTITY
if len(ids) > 100:
Expand All @@ -277,8 +277,8 @@ def exists_entity(self, ids, table=None):
query = {
'ids': ids
}
if table:
query['table'] = table
if dimension:
query['dimension'] = dimension
return self._make_request(
url=url,
json_data=ujson.dumps(query),
Expand Down
2 changes: 1 addition & 1 deletion pyslicer/utils/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def _has_empty_column(self):
# Value is a dictionary when it is an entity being inserted:
# "my-entity": {"year": 2016}
# It can also be a parameter, such as "auto-create":
# "auto-create": ["table", "column"]
# "auto-create": ["dimension", "column"]
if not isinstance(
value, (dict, list)) or value is None or len(
str(value)) == 0:
Expand Down
6 changes: 3 additions & 3 deletions tests_and_examples/examples/count_entity.json
Original file line number Diff line number Diff line change
Expand Up @@ -23283,7 +23283,7 @@
"name": "Test for a \"COUNT ENTITY\" query using automatically created columns, operator \"AND\" and parameter \"EQUALS\".",
"columns": [],
"insert": {
"auto-create": ["table", "column"],
"auto-create": ["dimension", "column"],
"24": {
"string-test-column": "value:matched_value",
"numeric-test-column": 1000001
Expand Down Expand Up @@ -23713,7 +23713,7 @@
"name": "Test for a \"COUNT ENTITY\" query using automatically created columns, operators \"AND\" and \"OR\" and parameter \"EQUALS\".",
"columns": [],
"insert": {
"auto-create": ["table", "column"],
"auto-create": ["dimension", "column"],
"24": {
"string-test-column": "value:matched_value",
"boolean-test-column": "true",
Expand Down Expand Up @@ -24251,7 +24251,7 @@
"name": "Test for a \"COUNT ENTITY\" query using automatically created columns, operators \"AND\" and \"OR\" and parameters \"EQUALS\", \"BETWEEN\" and \"MINFREQ\".",
"columns": [],
"insert": {
"auto-create": ["table", "column"],
"auto-create": ["dimension", "column"],
"24": {
"string-test-column": "value:matched_value",
"boolean-test-column": "true",
Expand Down
16 changes: 8 additions & 8 deletions tests_and_examples/examples/sql_insert.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"city": "New York",
"country": "USA",
"age": 19,
"table": "users",
"dimension": "users",
"name": "joao",
"browser": "firefox",
"os": "Linux",
Expand Down Expand Up @@ -41,7 +41,7 @@
"city": "Natal",
"country": "Brazil",
"age": 21,
"table": "users",
"dimension": "users",
"name": "eduardo",
"browser": "chrome",
"os": "Windows",
Expand Down Expand Up @@ -76,7 +76,7 @@
"city": "Salvador",
"country": "Brazil",
"age": 17,
"table": "users",
"dimension": "users",
"name": "gabriela",
"browser": "safari",
"os": "mac",
Expand Down Expand Up @@ -106,7 +106,7 @@
]
},
"auto-create": [
"table",
"dimension",
"column"
]
},
Expand All @@ -116,10 +116,10 @@
"salary": 2350.50,
"age": 19,
"admission": "2017-07-17",
"table": "jobs"
"dimension": "jobs"
},
"auto-create": [
"table",
"dimension",
"column"
]
},
Expand All @@ -140,10 +140,10 @@
"value": 15,
"date": "2017-08-18T00:00:00Z"
},
"table": "inserttest"
"dimension": "inserttest"
},
"auto-create": [
"table",
"dimension",
"column"
]
}
Expand Down