def test_insert_relationships_by_batch_skip_row_if_not_target_nodes(self):
        df_iterator = self._create_dataframe_iterator()
        with MockNeo4jHandle() as neo4jhandle:
            params_temp = copy.copy(self.params)
            params_temp.skip_row_if_not_target = True
            neo4jhandle.insert_relationships_by_batch(df_iterator,
                                                      self.dataset_schema,
                                                      params_temp)
            print(f"neo4jhandle.queries[1]: {neo4jhandle.queries[1]}")
            assert len(neo4jhandle.queries) == len(df_iterator)
            reference_query = """
WITH $data AS dataset
UNWIND dataset AS rows
MATCH (tgt:`Club` {`name`: rows.`club_name`})
SET tgt.`country` = rows.`club_country`
MERGE (src:`Player` {`name`: rows.`player_name`})

MERGE (src)-[rel:`TRANSFER_TO`]->(tgt)
ON CREATE SET rel.`transfer_date` = datetime(rows.`timestamp`)
ON MATCH SET rel.`transfer_date` = datetime(rows.`timestamp`)
ON CREATE SET rel.`transfer_fee` = toFloat(rows.`fee`)
ON MATCH SET rel.`transfer_fee` = toFloat(rows.`fee`)
ON CREATE SET rel.`player_age` = toInteger(rows.`player_age`)
ON MATCH SET rel.`player_age` = toInteger(rows.`player_age`)
ON CREATE SET rel.weight = 1
ON MATCH SET rel.weight = rel.weight + 1
"""
            compare_queries(neo4jhandle.queries[1], reference_query)
    def test_load_relationships_from_csv(self):
        file_handler = MockImportFileHandler()
        df_iterator = self._create_dataframe_iterator()
        with MockNeo4jHandle() as neo4jhandle:
            print(f"self.params.used_columns: {self.params.used_columns}")
            neo4jhandle.load_relationships_from_csv(df_iterator,
                                                    self.dataset_schema,
                                                    self.params, file_handler)
            print(f"neo4jhandle.queries[0]:\n{neo4jhandle.queries[0]}")
            reference_query = """
USING PERIODIC COMMIT 500
LOAD CSV FROM 'file:///dss_neo4j_export_temp_file_001.csv.gz' AS line FIELDTERMINATOR ','
WITH line[0] AS `club_country`, line[1] AS `club_name`, line[2] AS `fee`, line[3] AS `player_age`, line[4] AS `player_name`, line[5] AS `timestamp`
MERGE (src:`Player` {`name`: `player_name`})

MERGE (tgt:`Club` {`name`: `club_name`})
ON CREATE SET tgt.`country` = `club_country`
ON MATCH SET tgt.`country` = `club_country`
MERGE (src)-[rel:`TRANSFER_TO`]->(tgt)
ON CREATE SET rel.`transfer_date` = datetime(`timestamp`)
ON MATCH SET rel.`transfer_date` = datetime(`timestamp`)
ON CREATE SET rel.`transfer_fee` = toFloat(`fee`)
ON MATCH SET rel.`transfer_fee` = toFloat(`fee`)
ON CREATE SET rel.`player_age` = toInteger(`player_age`)
ON MATCH SET rel.`player_age` = toInteger(`player_age`)
ON CREATE SET rel.weight = 1
ON MATCH SET rel.weight = rel.weight + 1
"""
            compare_queries(neo4jhandle.queries[0], reference_query)
Ejemplo n.º 3
0
    def test_delete_nodes(self):
        with MockNeo4jHandle() as neo4jhandle:
            neo4jhandle.delete_nodes(self.params.nodes_label)
            reference_query = """
CALL apoc.periodic.iterate("MATCH (n:`Player`) return n", "DETACH DELETE n", {batchSize:1000})
YIELD batches, total RETURN batches, total
"""
            compare_queries(neo4jhandle.queries[0], reference_query)
Ejemplo n.º 4
0
    def test_add_unique_constraint_on_nodes(self):
        with MockNeo4jHandle() as neo4jhandle:
            neo4jhandle.add_unique_constraint_on_nodes(self.params)
            reference_query = """
CREATE CONSTRAINT IF NOT EXISTS ON (n:`Player`)
ASSERT n.`name` IS UNIQUE
"""
            compare_queries(neo4jhandle.queries[0], reference_query)
Ejemplo n.º 5
0
    def test_insert_nodes_by_batch(self):
        df_iterator = self._create_dataframe_iterator()
        with MockNeo4jHandle() as neo4jhandle:
            neo4jhandle.insert_nodes_by_batch(df_iterator, self.dataset_schema,
                                              self.params)
            assert len(neo4jhandle.queries) == len(df_iterator)
            reference_query = """
WITH $data AS dataset
UNWIND dataset AS rows
MERGE (src:`Player` {`name`: rows.`player_name`})
ON CREATE SET src.`age` = toInteger(rows.`player_age`)
ON MATCH SET src.`age` = toInteger(rows.`player_age`)
ON CREATE SET src.`country` = rows.`player_country`
ON MATCH SET src.`country` = rows.`player_country`
ON CREATE SET src.`birthdate` = datetime(rows.`timestamp`)
ON MATCH SET src.`birthdate` = datetime(rows.`timestamp`)
ON CREATE SET src.`value` = toFloat(rows.`fee`)
ON MATCH SET src.`value` = toFloat(rows.`fee`)
"""
            compare_queries(neo4jhandle.queries[1], reference_query)
Ejemplo n.º 6
0
    def test_load_nodes_from_csv(self):
        file_handler = MockImportFileHandler()
        df_iterator = self._create_dataframe_iterator()
        with MockNeo4jHandle() as neo4jhandle:
            neo4jhandle.load_nodes_from_csv(df_iterator, self.dataset_schema,
                                            self.params, file_handler)
            reference_query = """
USING PERIODIC COMMIT 500
LOAD CSV FROM 'file:///dss_neo4j_export_temp_file_001.csv.gz' AS line FIELDTERMINATOR ','
WITH line[0] AS `player_name`, line[1] AS `player_age`, line[2] AS `player_country`, line[3] AS `timestamp`, line[4] AS `fee`
MERGE (src:`Player` {`name`: `player_name`})
ON CREATE SET src.`age` = toInteger(`player_age`)
ON MATCH SET src.`age` = toInteger(`player_age`)
ON CREATE SET src.`country` = `player_country`
ON MATCH SET src.`country` = `player_country`
ON CREATE SET src.`birthdate` = datetime(`timestamp`)
ON MATCH SET src.`birthdate` = datetime(`timestamp`)
ON CREATE SET src.`value` = toFloat(`fee`)
ON MATCH SET src.`value` = toFloat(`fee`)
"""
            compare_queries(neo4jhandle.queries[0], reference_query)