Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Set field keys on load #149

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
27 changes: 26 additions & 1 deletion integration_tests/test_client_it.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ def test_store(self):
finally:
client.delete_index(index)


def test_ensure_index_exists(self):
client = self.get_client()
index = Index(self.index.name + "-ensure")
Expand Down Expand Up @@ -736,6 +735,32 @@ def test_shards(self):
self.assertEquals(100, response.result.row.columns[0])
self.assertEquals(shard_width*3, response.result.row.columns[1])

def test_field_opts(self):
client = self.get_client()
schema = client.schema()
index = schema.index("index_wkeys", keys=True, track_existence=True, shard_width=2 ** 10)
try:
# create the schema
index.field("field_wkeys",
keys=True,
cache_type=CacheType.LRU,
cache_size=1000)
client.sync_schema(schema)

# check that the correct schema was created
schema = client.schema()
index = schema.index("index_wkeys")
self.assertEqual("index_wkeys", index.name)
self.assertTrue(index.keys)
self.assertTrue(index.track_existence)
field = index.field("field_wkeys")
self.assertEqual("field_wkeys", field.name)
self.assertTrue(field.keys)
self.assertEqual(CacheType.LRU, field.cache_type)
self.assertEqual(1000, field.cache_size)
finally:
client.delete_index(index)

def test_create_index_fail(self):
server = MockServer(404)
with server:
Expand Down
8 changes: 6 additions & 2 deletions pilosa/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,13 +486,17 @@ def __connect(self):

def decode_field_meta_options(field_info):
meta = field_info.get("options", {})
return {
opts = {
"cache_size": meta.get("cacheSize", 50000),
"cache_type": CacheType(meta.get("cacheType", "")),
"time_quantum": TimeQuantum(meta.get("timeQuantum", "")),
"int_min": meta.get("min", 0),
"int_max": meta.get("max", 0),
"int_max": meta.get("max", 0)
}
keys_opt = meta.get("keys")
if keys_opt is not None:
opts["keys"] = keys_opt
return opts


class URI:
Expand Down
6 changes: 6 additions & 0 deletions pilosa/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ def __init__(self, value):
def __str__(self):
return self.value

def __repr__(self):
return "TimeQuantum(%s)" % self.value

def __eq__(self, other):
if isinstance(other, TimeQuantum):
return self.value == other.value
Expand Down Expand Up @@ -107,6 +110,9 @@ def __init__(self, value):
def __str__(self):
return self.value

def __repr__(self):
return "CacheType(%s)" % self.value

def __eq__(self, other):
if isinstance(other, CacheType):
return self.value == other.value
Expand Down
5 changes: 2 additions & 3 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_create_client(self):
# create with invalid type
self.assertRaises(PilosaError, Client, 15000)

def test_decode_field_meta_options(self):
def test_decode_default_field_meta_options(self):
field_info = {}
options = decode_field_meta_options(field_info)
target = {
Expand All @@ -72,7 +72,6 @@ def test_decode_field_meta_options(self):
self.assertEquals(target, options)



class URITestCase(unittest.TestCase):

def test_default(self):
Expand Down Expand Up @@ -317,7 +316,7 @@ def test_node_url(self):


def get_schema(index_keys, field_keys):
from pilosa.orm import Schema, Index, Field
from pilosa.orm import Schema
schema = Schema()
index = schema.index("foo", keys=index_keys)
field = index.field("bar", keys=field_keys)
Expand Down