コード例 #1
0
    def _send_batch_and_read_results(self,
                                     schema,
                                     graphson,
                                     add_all=False,
                                     use_schema=True):
        traversals = []
        datatypes = schema.fixtures.datatypes()
        values = {}
        g = self.fetch_traversal_source(graphson)
        ep = self.get_execution_profile(graphson)
        batch = DseGraph.batch(session=self.session,
                               execution_profile=self.get_execution_profile(
                                   graphson, traversal=True))
        for data in six.itervalues(datatypes):
            typ, value, deserializer = data
            vertex_label = VertexLabel([typ])
            property_name = next(six.iterkeys(vertex_label.non_pk_properties))
            values[property_name] = value
            if use_schema or schema is CoreGraphSchema:
                schema.create_vertex_label(self.session,
                                           vertex_label,
                                           execution_profile=ep)

            traversal = g.addV(str(vertex_label.label)).property(
                'pkid', vertex_label.id).property(property_name, value)
            if not add_all:
                batch.add(traversal)
            traversals.append(traversal)

        if add_all:
            batch.add_all(traversals)

        self.assertEqual(len(datatypes), len(batch))

        batch.execute()

        vertices = self.execute_traversal(g.V(), graphson)
        self.assertEqual(len(vertices), len(datatypes),
                         "g.V() returned {}".format(vertices))

        # Iterate over all the vertices and check that they match the original input
        for vertex in vertices:
            schema.ensure_properties(self.session,
                                     vertex,
                                     execution_profile=ep)
            key = [k for k in list(vertex.properties.keys())
                   if k != 'pkid'][0].replace("value", "")
            original = values[key]
            self._check_equality(original, vertex)
コード例 #2
0
    def _test_all_datatypes(self, schema, graphson):
        ep = self.get_execution_profile(graphson)

        for data in six.itervalues(schema.fixtures.datatypes()):
            typ, value, deserializer = data
            vertex_label = VertexLabel([typ])
            property_name = next(six.iterkeys(vertex_label.non_pk_properties))
            schema.create_vertex_label(self.session,
                                       vertex_label,
                                       execution_profile=ep)
            vertex = list(
                schema.add_vertex(self.session,
                                  vertex_label,
                                  property_name,
                                  value,
                                  execution_profile=ep))[0]

            def get_vertex_properties():
                return list(
                    schema.get_vertex_properties(self.session,
                                                 vertex,
                                                 execution_profile=ep))

            prop_returned = 1 if DSE_VERSION < Version(
                '5.1') else 2  # include pkid >=5.1
            wait_until(lambda: len(get_vertex_properties()) == prop_returned,
                       0.2, 15)

            vertex_properties = get_vertex_properties()
            if graphson == GraphProtocol.GRAPHSON_1_0:
                vertex_properties = [
                    vp.as_vertex_property() for vp in vertex_properties
                ]

            for vp in vertex_properties:
                if vp.label == 'pkid':
                    continue

                self.assertIsInstance(vp, VertexProperty)
                self.assertEqual(vp.label, property_name)
                if graphson == GraphProtocol.GRAPHSON_1_0:
                    deserialized_value = deserializer(
                        vp.value) if deserializer else vp.value
                    self.assertEqual(deserialized_value, value)
                else:
                    self.assertEqual(vp.value, value)
コード例 #3
0
    def _test_basic_query_with_type_wrapper(self, schema, graphson):
        """
        Test to validate that a query using a type wrapper works.

        @since 2.8.0
        @jira_ticket PYTHON-1051
        @expected_result graph query works and doesn't raise an exception

        @test_category dse graph
        """
        ep = self.get_execution_profile(graphson)
        vl = VertexLabel(['tupleOf(Int, Bigint)'])
        schema.create_vertex_label(self.session, vl, execution_profile=ep)

        prop_name = next(six.iterkeys(vl.non_pk_properties))
        with self.assertRaises(InvalidRequest):
            schema.add_vertex(self.session, vl, prop_name, (1, 42), execution_profile=ep)

        schema.add_vertex(self.session, vl, prop_name, (1, to_bigint(42)), execution_profile=ep)
コード例 #4
0
    def _test_geometric_graph_types(self, schema, graphson):
        """
        Test to validate that geometric types function correctly

        Creates a very simple graph, and tries to insert a simple point type

        @since 1.0.0
        @jira_ticket DSP-8087
        @expected_result json types associated with insert is parsed correctly

        @test_category dse graph
        """
        vertex_label = VertexLabel([('pointP', "Point()")])
        ep = self.get_execution_profile(graphson)
        schema.create_vertex_label(self.session, vertex_label, ep)
        # import org.apache.cassandra.db.marshal.geometry.Point;
        rs = schema.add_vertex(self.session, vertex_label, 'pointP', Point(0, 1), ep)

        # if result set is not parsed correctly this will throw an exception
        self.assertIsNotNone(rs)
コード例 #5
0
    def _write_and_read_data_types(self, schema, graphson, use_schema=True):
        g = self.fetch_traversal_source(graphson)
        ep = self.get_execution_profile(graphson)
        for data in six.itervalues(schema.fixtures.datatypes()):
            typ, value, deserializer = data
            vertex_label = VertexLabel([typ])
            property_name = next(six.iterkeys(vertex_label.non_pk_properties))
            if use_schema or schema is CoreGraphSchema:
                schema.create_vertex_label(self.session,
                                           vertex_label,
                                           execution_profile=ep)

            write_traversal = g.addV(str(vertex_label.label)).property('pkid', vertex_label.id).\
                property(property_name, value)
            self.execute_traversal(write_traversal, graphson)

            read_traversal = g.V().hasLabel(str(
                vertex_label.label)).has(property_name).properties()
            results = self.execute_traversal(read_traversal, graphson)

            for result in results:
                if result.label == 'pkid':
                    continue
                self._check_equality(g, value, result.value)
コード例 #6
0
    def __test_udt(self, schema, graphson, address_class,
                   address_with_tags_class, complex_address_class,
                   complex_address_with_owners_class):
        if schema is not CoreGraphSchema or DSE_VERSION < Version('6.8'):
            raise unittest.SkipTest(
                "Graph UDT is only supported with DSE 6.8+ and Core graphs.")

        ep = self.get_execution_profile(graphson)

        Address = address_class
        AddressWithTags = address_with_tags_class
        ComplexAddress = complex_address_class
        ComplexAddressWithOwners = complex_address_with_owners_class

        # setup udt
        self.session.execute_graph("""
                schema.type('address').property('address', Text).property('city', Text).property('state', Text).create();
                schema.type('addressTags').property('address', Text).property('city', Text).property('state', Text).
                    property('tags', setOf(Text)).create();
                schema.type('complexAddress').property('address', Text).property('address_tags', frozen(typeOf('addressTags'))).
                    property('city', Text).property('state', Text).property('props', mapOf(Text, Int)).create();
                schema.type('complexAddressWithOwners').property('address', Text).
                    property('address_tags', frozen(typeOf('addressTags'))).
                    property('city', Text).property('state', Text).property('props', mapOf(Text, Int)).
                    property('owners', frozen(listOf(tupleOf(Text, Int)))).create();
                """,
                                   execution_profile=ep)

        # wait max 10 seconds to get the UDT discovered.
        wait_until_not_raised(
            lambda: self.session.cluster.register_user_type(
                self.graph_name, 'address', Address), 1, 10)
        wait_until_not_raised(
            lambda: self.session.cluster.register_user_type(
                self.graph_name, 'addressTags', AddressWithTags), 1, 10)
        wait_until_not_raised(
            lambda: self.session.cluster.register_user_type(
                self.graph_name, 'complexAddress', ComplexAddress), 1, 10)
        wait_until_not_raised(
            lambda: self.session.cluster.register_user_type(
                self.graph_name, 'complexAddressWithOwners',
                ComplexAddressWithOwners), 1, 10)

        data = {
            "udt1":
            ["typeOf('address')",
             Address('1440 Rd Smith', 'Quebec', 'QC')],
            "udt2": [
                "tupleOf(typeOf('address'), Text)",
                (Address('1440 Rd Smith', 'Quebec', 'QC'), 'hello')
            ],
            "udt3": [
                "tupleOf(frozen(typeOf('address')), Text)",
                (Address('1440 Rd Smith', 'Quebec', 'QC'), 'hello')
            ],
            "udt4": [
                "tupleOf(tupleOf(Int, typeOf('address')), Text)",
                ((42, Address('1440 Rd Smith', 'Quebec', 'QC')), 'hello')
            ],
            "udt5": [
                "tupleOf(tupleOf(Int, typeOf('addressTags')), Text)",
                ((42,
                  AddressWithTags('1440 Rd Smith', 'Quebec', 'QC',
                                  {'t1', 't2'})), 'hello')
            ],
            "udt6": [
                "tupleOf(tupleOf(Int, typeOf('complexAddress')), Text)",
                ((42,
                  ComplexAddress(
                      '1440 Rd Smith',
                      AddressWithTags('1440 Rd Smith', 'Quebec', 'QC',
                                      {'t1', 't2'}), 'Quebec', 'QC', {
                                          'p1': 42,
                                          'p2': 33
                                      })), 'hello')
            ],
            "udt7": [
                "tupleOf(tupleOf(Int, frozen(typeOf('complexAddressWithOwners'))), Text)",
                ((42,
                  ComplexAddressWithOwners(
                      '1440 Rd Smith',
                      AddressWithTags('1440 CRd Smith', 'Quebec', 'QC',
                                      {'t1', 't2'}), 'Quebec', 'QC', {
                                          'p1': 42,
                                          'p2': 33
                                      }, [('Mike', 43),
                                          ('Gina', 39)])), 'hello')
            ]
        }

        g = self.fetch_traversal_source(graphson)
        for typ, value in six.itervalues(data):
            vertex_label = VertexLabel([typ])
            property_name = next(six.iterkeys(vertex_label.non_pk_properties))
            schema.create_vertex_label(self.session,
                                       vertex_label,
                                       execution_profile=ep)

            write_traversal = g.addV(str(vertex_label.label)).property('pkid', vertex_label.id). \
                property(property_name, value)
            self.execute_traversal(write_traversal, graphson)

            #vertex = list(schema.add_vertex(self.session, vertex_label, property_name, value, execution_profile=ep))[0]
            #vertex_properties = list(schema.get_vertex_properties(
            #    self.session, vertex, execution_profile=ep))

            read_traversal = g.V().hasLabel(str(
                vertex_label.label)).has(property_name).properties()
            vertex_properties = self.execute_traversal(read_traversal,
                                                       graphson)

            self.assertEqual(len(vertex_properties), 2)  # include pkid
            for vp in vertex_properties:
                if vp.label == 'pkid':
                    continue

                self.assertIsInstance(vp, (VertexProperty, TravVertexProperty))
                self.assertEqual(vp.label, property_name)
                self.assertEqual(vp.value, value)
コード例 #7
0
    def __test_udt(self, schema, graphson, address_class,
                   address_with_tags_class, complex_address_class,
                   complex_address_with_owners_class):
        if schema is not CoreGraphSchema or DSE_VERSION < Version('6.8'):
            raise unittest.SkipTest(
                "Graph UDT is only supported with DSE 6.8+ and Core graphs.")

        ep = self.get_execution_profile(graphson)

        Address = address_class
        AddressWithTags = address_with_tags_class
        ComplexAddress = complex_address_class
        ComplexAddressWithOwners = complex_address_with_owners_class

        # setup udt
        self.session.execute_graph("""
                schema.type('address').property('address', Text).property('city', Text).property('state', Text).create();
                schema.type('addressTags').property('address', Text).property('city', Text).property('state', Text).
                    property('tags', setOf(Text)).create();
                schema.type('complexAddress').property('address', Text).property('address_tags', frozen(typeOf('addressTags'))).
                    property('city', Text).property('state', Text).property('props', mapOf(Text, Int)).create();
                schema.type('complexAddressWithOwners').property('address', Text).
                    property('address_tags', frozen(typeOf('addressTags'))).
                    property('city', Text).property('state', Text).property('props', mapOf(Text, Int)).
                    property('owners', frozen(listOf(tupleOf(Text, Int)))).create();
                """,
                                   execution_profile=ep)

        time.sleep(2)  # wait the UDT to be discovered
        self.session.cluster.register_user_type(self.graph_name, 'address',
                                                Address)
        self.session.cluster.register_user_type(self.graph_name, 'addressTags',
                                                AddressWithTags)
        self.session.cluster.register_user_type(self.graph_name,
                                                'complexAddress',
                                                ComplexAddress)
        self.session.cluster.register_user_type(self.graph_name,
                                                'complexAddressWithOwners',
                                                ComplexAddressWithOwners)

        data = {
            "udt1":
            ["typeOf('address')",
             Address('1440 Rd Smith', 'Quebec', 'QC')],
            "udt2": [
                "tupleOf(typeOf('address'), Text)",
                (Address('1440 Rd Smith', 'Quebec', 'QC'), 'hello')
            ],
            "udt3": [
                "tupleOf(frozen(typeOf('address')), Text)",
                (Address('1440 Rd Smith', 'Quebec', 'QC'), 'hello')
            ],
            "udt4": [
                "tupleOf(tupleOf(Int, typeOf('address')), Text)",
                ((42, Address('1440 Rd Smith', 'Quebec', 'QC')), 'hello')
            ],
            "udt5": [
                "tupleOf(tupleOf(Int, typeOf('addressTags')), Text)",
                ((42,
                  AddressWithTags('1440 Rd Smith', 'Quebec', 'QC',
                                  {'t1', 't2'})), 'hello')
            ],
            "udt6": [
                "tupleOf(tupleOf(Int, typeOf('complexAddress')), Text)",
                ((42,
                  ComplexAddress(
                      '1440 Rd Smith',
                      AddressWithTags('1440 Rd Smith', 'Quebec', 'QC',
                                      {'t1', 't2'}), 'Quebec', 'QC', {
                                          'p1': 42,
                                          'p2': 33
                                      })), 'hello')
            ],
            "udt7": [
                "tupleOf(tupleOf(Int, frozen(typeOf('complexAddressWithOwners'))), Text)",
                ((42,
                  ComplexAddressWithOwners(
                      '1440 Rd Smith',
                      AddressWithTags('1440 CRd Smith', 'Quebec', 'QC',
                                      {'t1', 't2'}), 'Quebec', 'QC', {
                                          'p1': 42,
                                          'p2': 33
                                      }, [('Mike', 43),
                                          ('Gina', 39)])), 'hello')
            ]
        }

        for typ, value in six.itervalues(data):
            vertex_label = VertexLabel([typ])
            property_name = next(six.iterkeys(vertex_label.non_pk_properties))
            schema.create_vertex_label(self.session,
                                       vertex_label,
                                       execution_profile=ep)

            vertex = list(
                schema.add_vertex(self.session,
                                  vertex_label,
                                  property_name,
                                  value,
                                  execution_profile=ep))[0]

            def get_vertex_properties():
                return list(
                    schema.get_vertex_properties(self.session,
                                                 vertex,
                                                 execution_profile=ep))

            wait_until(lambda: len(get_vertex_properties()) == 2, 0.2, 15)

            vertex_properties = get_vertex_properties()
            for vp in vertex_properties:
                if vp.label == 'pkid':
                    continue

                self.assertIsInstance(vp, VertexProperty)
                self.assertEqual(vp.label, property_name)
                self.assertEqual(vp.value, value)