Exemple #1
0
 def test_sync(self):
     client = self.get_client()
     remote_index = Index("remote-index-1")
     remote_field = remote_index.field("remote-field-1")
     schema1 = Schema()
     index11 = schema1.index("diff-index1")
     index11.field("field1-1")
     index11.field("field1-2")
     index12 = schema1.index("diff-index2")
     index12.field("field2-1")
     schema1.index(remote_index.name)
     try:
         client.ensure_index(remote_index)
         client.ensure_field(remote_field)
         client.sync_schema(schema1)
         # check that the schema was created
         schema2 = client.schema()
         self.assertTrue("remote-index-1" in schema2._indexes)
         self.assertTrue(
             "remote-field-1" in schema2.index("remote-index-1")._fields)
         self.assertTrue("diff-index1" in schema2._indexes)
         self.assertTrue("field1-1" in schema2.index("diff-index1")._fields)
         self.assertTrue("field1-2" in schema2.index("diff-index1")._fields)
         self.assertTrue("diff-index2" in schema2._indexes)
         self.assertTrue("field2-1" in schema2.index("diff-index2")._fields)
     finally:
         try:
             client.delete_index(remote_index)
             client.delete_index(index11)
             client.delete_index(index12)
         except PilosaError:
             pass
Exemple #2
0
    def test_diff(self):
        schema1 = Schema()
        index11 = schema1.index("diff-index1")
        index11.frame("frame1-1")
        index11.frame("frame1-2")
        index12 = schema1.index("diff-index2")
        index12.frame("frame2-1")

        schema2 = Schema()
        index21 = schema2.index("diff-index1")
        index21.frame("another-frame")

        target_diff12 = Schema()
        target_index1 = target_diff12.index("diff-index1")
        target_index1.frame("frame1-1")
        target_index1.frame("frame1-2")
        target_index2 = target_diff12.index("diff-index2")
        target_index2.frame("frame2-1")

        diff12 = schema1._diff(schema2)
        self.assertEqual(target_diff12, diff12)
Exemple #3
0
    def setUp(self):
        self.schema = Schema()
        self.index = self.schema.index(self.random_index_name())
        client = self.get_client()
        self.index.field("another-field")
        self.index.field("test")
        self.index.field("count-test")
        self.index.field("topn_test")

        self.col_index = self.schema.index(self.index.name + "-opts")
        self.field = self.col_index.field("collab")

        self.key_index = self.schema.index("key-index", keys=True)

        client.sync_schema(self.schema)
Exemple #4
0
    def test_create_index(self):
        index_name = "some-index"
        client = self.get_client()
        schema = Schema()
        index = schema.index(index_name, track_existence=True, keys=True)
        client.sync_schema(schema)
        try:
            schema = client.schema()
            self.assertTrue(schema.has_index(index_name))
            index = schema.index(index_name)
            self.assertTrue(index.keys)
            self.assertTrue(index.track_existence)
            self.assertNotEqual(0, index.shard_width)

        finally:
            client.delete_index(index)
 def test_sync(self):
     client = self.get_client()
     remote_index = Index("remote-index-1")
     remote_frame = remote_index.frame("remote-frame-1")
     schema1 = Schema()
     index11 = schema1.index("diff-index1")
     index11.frame("frame1-1")
     index11.frame("frame1-2")
     index12 = schema1.index("diff-index2")
     index12.frame("frame2-1")
     schema1.index(remote_index.name)
     try:
         client.ensure_index(remote_index)
         client.ensure_frame(remote_frame)
         client.sync_schema(schema1)
     finally:
         try:
             client.delete_index(remote_index)
             client.delete_index(index11)
             client.delete_index(index12)
         except PilosaError:
             pass
Exemple #6
0
 def test_other_class_not_equals(self):
     schema = Schema()
     self.assertNotEqual(projectIndex, schema)
Exemple #7
0
 def test_same_equals(self):
     schema = Schema()
     self.assertEqual(schema, schema)
Exemple #8
0
 def test_other_class_not_equals(self):
     schema = Schema()
     self.assertNotEqual(sampleFrame, schema)
Exemple #9
0
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
# DAMAGE.
#

import unittest
from datetime import datetime

from pilosa import PilosaError, Index, TimeQuantum, CacheType, IntField, ValidationError
from pilosa.orm import Schema

schema = Schema()
sampleIndex = schema.index("sample-db")
sampleFrame = sampleIndex.frame("sample-frame")
projectIndex = schema.index("project-db", column_label="user")
collabFrame = projectIndex.frame("collaboration", row_label="project")


class SchemaTestCase(unittest.TestCase):
    def test_diff(self):
        schema1 = Schema()
        index11 = schema1.index("diff-index1")
        index11.frame("frame1-1")
        index11.frame("frame1-2")
        index12 = schema1.index("diff-index2")
        index12.frame("frame2-1")
Exemple #10
0
def get_schema(index_keys, field_keys):
    from pilosa.orm import Schema, Index, Field
    schema = Schema()
    index = schema.index("foo", keys=index_keys)
    field = index.field("bar", keys=field_keys)
    return field
Exemple #11
0
 def test_has_index(self):
     schema = Schema()
     schema.index("some-index")
     self.assertTrue(schema.has_index("some-index"))
     self.assertFalse(schema.has_index("another-index"))