Esempio n. 1
0
 def test_return_clause_when_timestamp_referenced_after_where(self):
     input_query = 'MATCH ()-[e]-() MATCH (a) WHERE e.timestamp > 4 ' \
         'RETURN [e.timestamps] AS timestamps'
     expected = 'RETURN [collect(e_timestamp)] AS timestamps'
     result = unwind_timestamps(input_query)
     result = 'RETURN' + result.split('RETURN')[1]
     self.assertEqual(result, expected)
Esempio n. 2
0
 def transpile_part(part):
     if ' '.join(part.split()).strip() in ('UNION', 'UNION ALL'):
         return part.strip()
     part = restrict_query_to_sketch(part, sketch_id)
     part = append_return_clause(part)
     part = unwind_timestamps(part)
     return part.strip()
Esempio n. 3
0
 def test_timestamp_referenced_in_where(self):
     input_query = 'MATCH ()-[e]-() WHERE e.timestamp < 4'
     expected = 'MATCH ()-[e]-() ' \
         'UNWIND e.timestamps + ' \
         'filter(a IN [null] WHERE e.timestamps_incomplete) ' \
         'AS e_timestamp ' \
         'WITH *  ' \
         'WHERE  coalesce((e_timestamp < 4), e_timestamp IS NULL)'
     result = unwind_timestamps(input_query)
     self.assertEqual(result, expected)
Esempio n. 4
0
 def test_timestamp_referenced_in_where_with_other_condition_1(self):
     input_query = 'MATCH ()-[e]-() WHERE e.timestamp < 4 ' \
         'AND e.foo = "foo"'
     expected = 'MATCH ()-[e]-() ' \
         'WHERE e.foo = "foo" ' \
         'UNWIND e.timestamps + ' \
         'filter(a IN [null] WHERE e.timestamps_incomplete) ' \
         'AS e_timestamp ' \
         'WITH *  ' \
         'WHERE  coalesce((e_timestamp < 4 AND e.foo = "foo"), ' \
         'e_timestamp IS NULL)'
     result = unwind_timestamps(input_query)
     self.assertEqual(result, expected)
Esempio n. 5
0
 def test_2_timestamps_referenced_in_where(self):
     input_query = 'MATCH ()-[e1]-()-[e2]-() ' \
         'WHERE e1.timestamp < e2.timestamp < e1.timestamp + 10'
     expected = 'MATCH ()-[e1]-()-[e2]-() ' \
         'UNWIND e1.timestamps + ' \
         'filter(a IN [null] WHERE e1.timestamps_incomplete) ' \
         'AS e1_timestamp ' \
         'UNWIND e2.timestamps + ' \
         'filter(a IN [null] WHERE e2.timestamps_incomplete) ' \
         'AS e2_timestamp ' \
         'WITH *  ' \
         'WHERE  coalesce((' \
         'e1_timestamp < e2_timestamp < e1_timestamp + 10), ' \
         'e1_timestamp IS NULL OR e2_timestamp IS NULL)'
     result = unwind_timestamps(input_query)
     self.assertEqual(result, expected)
Esempio n. 6
0
 def test_timestamp_not_referenced(self):
     input_query = 'MATCH (a) RETURN a'
     expected = 'MATCH (a) RETURN a'
     result = unwind_timestamps(input_query)
     self.assertEqual(result, expected)
Esempio n. 7
0
 def test_return_clause_when_timestamp_not_referenced(self):
     input_query = 'MATCH ()-[e]-() RETURN [e.timestamps] AS timestamps'
     expected = 'RETURN [e.timestamps] AS timestamps'
     result = unwind_timestamps(input_query)
     result = 'RETURN' + result.split('RETURN')[1]
     self.assertEqual(result, expected)