예제 #1
0
 def test_own_param_name(self):
     test_labels = ['Foo']
     test_param_name = 'nodes'
     query = nodes_create_unwind(test_labels,
                                 property_parameter=test_param_name)
     assert query == 'UNWIND ${0} AS properties CREATE (n:{1}) SET n = properties'.format(
         test_param_name, test_labels[0])
예제 #2
0
    def test_query_creates_nodes(self, graph, clear_graph):
        query = nodes_create_unwind(['Foo', 'Bar'])

        graph.run(query, props=[{'testid': 1}, {'testid': 2}])

        result = graph.run('MATCH (n:Foo:Bar) RETURN n.testid AS testid')

        collected_ids = set()

        for row in result:
            assert row['testid']
            collected_ids.add(row['testid'])

        assert collected_ids == {1, 2}
예제 #3
0
    def create(self,
               graph,
               batch_size=None,
               raise_on_result_count_deviation=False):
        """
        Create all nodes from NodeSet.


        :raise_on_result_count_deviation: boolean. Raise if less nodes were processed on DB side as sended with the query. This can happen in parallel processing environments. set Nodeset.failed_batch_handler(error,query,batch) to catch single failed batches
        """
        log.debug('Create NodeSet')
        if not batch_size:
            batch_size = self.batch_size
        log.debug('Batch Size: {}'.format(batch_size))

        i = 1
        for batch in chunks(self.nodes, size=batch_size):
            batch = list(batch)
            log.debug('Batch {}'.format(i))

            query = nodes_create_unwind(self.labels)
            log.debug(query)
            try:
                tx = graph.begin()
                tx.run(query, props=batch)
                result = tx.run(query, props=batch)
                tx.commit()
                count = result.data()[0]["cnt"]
                if raise_on_result_count_deviation and count < len(batch):
                    raise MissingNodesEx(
                        "Excepted {} Nodes to be inserted, got {}", len(batch),
                        count)
            except Exception as e:
                if self.failed_batch_handler is not None:
                    self.failed_batch_handler(self, e, query, batch)
                else:
                    raise

            #with graph.session() as s:
            #    result = s.run(query, props=batch)

            i += 1
예제 #4
0
    def create(self, graph, batch_size=None):
        """
        Create all nodes from NodeSet.
        """
        log.debug('Create NodeSet')
        if not batch_size:
            batch_size = self.batch_size
        log.debug('Batch Size: {}'.format(batch_size))

        i = 1
        for batch in chunks(self.nodes, size=batch_size):
            batch = list(batch)
            log.debug('Batch {}'.format(i))

            query = nodes_create_unwind(self.labels)
            log.debug(query)

            result = graph.run(query, props=batch)

            i += 1
예제 #5
0
 def test_mulitple_labels(self):
     test_labels = ['Foo', 'Bar']
     query = nodes_create_unwind(test_labels)
     assert query == 'UNWIND $props AS properties CREATE (n:Foo:Bar) SET n = properties'
예제 #6
0
 def test_single_label(self):
     test_labels = ['Foo']
     query = nodes_create_unwind(test_labels)
     assert query == 'UNWIND $props AS properties CREATE (n:Foo) SET n = properties'