Exemplo n.º 1
0
def test_array_at_index():
    compare_query(query=Company.match().as_var('a').array(
        Company.match(industry=var('a').industry))[0],
                  query_str='''FOR o_p_0 IN company'''
                  '''  LET a = o_p_0'''
                  '''  LET oqr_p = o_p_0'''
                  '''  LET array_p = ('''
                  '''    FOR o_p_1 IN company'''
                  '''     FILTER o_p_1.industry == a.industry'''
                  '''     RETURN o_p_1'''
                  '''  )'''
                  '''  RETURN array_p[0]''',
                  bind_vars={},
                  returns='array_p[0]',
                  result=Company)
Exemplo n.º 2
0
def test_one_key_value_filter():
    compare_query(query=Company.match(some='value'),
                  query_str='FOR o_p IN company'
                  '  FILTER o_p.some == @p_1 RETURN o_p',
                  bind_vars={'p_1': 'value'},
                  returns='o_p',
                  result=Company)
Exemplo n.º 3
0
def test_has_edges_of_collection_that_match_to_collection_inner():
    compare_query(
        query=Company.match(out(LocatedIn, SubsidiaryOf).match(to(
            Company, Country).match(field='value'),
                                                               field='value'),
                            field='value'),
        query_str='''FOR o_p IN company'''
        '''  LET p_1_sub = ('''
        '''     FOR p_1_v, p_1_e IN 1..1 OUTBOUND o_p._id located_at, subsidiary_of'''
        '''       LET p_1_0_sub = ('''
        '''         FILTER IS_SAME_COLLECTION('company',p_1_v) OR IS_SAME_COLLECTION('country',p_1_v)'''
        '''         FILTER p_1_v.field == @p_1_0_0'''
        '''         RETURN 1'''
        '''       )'''
        '''       FILTER LENGTH(p_1_0_sub) > 0'''
        '''       FILTER p_1_e.field == @p_1_1'''
        '''       RETURN 1'''
        '''  )'''
        '''  FILTER LENGTH(p_1_sub) > 0'''
        '''  FILTER o_p.field == @p_3'''
        '''  RETURN o_p''',
        bind_vars={
            'p_1_1': 'value',
            'p_1_0_0': 'value',
            'p_3': 'value'
        },
        returns='o_p',
        result=Company)
Exemplo n.º 4
0
def test_has_edge_and_edge_vertices_that_match():
    compare_query(query=Company.match(eq('name', 'name'),
                                      out().match(like('textual', '%avocado%'),
                                                  field='val').to().match(
                                                      gt('numerical', 42),
                                                      field='value'),
                                      this_field='this_field'),
                  query_str='FOR o_p IN company'
                  '  FILTER o_p.name == @p_1'
                  '  LET p_2_sub = ('
                  '     FOR p_2_v, p_2_e IN 1..1 OUTBOUND o_p._id'
                  '       FILTER p_2_v.numerical > @p_2_0'
                  '       FILTER p_2_v.field == @p_2_1'
                  '       FILTER p_2_e.textual LIKE @p_2_2'
                  '       FILTER p_2_e.field == @p_2_3'
                  '       RETURN 1'
                  '  )'
                  '  FILTER LENGTH(p_2_sub) > 0'
                  '  FILTER o_p.this_field == @p_6'
                  '  RETURN o_p',
                  bind_vars={
                      'p_1': 'name',
                      'p_2_0': 42,
                      'p_2_1': 'value',
                      'p_2_2': '%avocado%',
                      'p_2_3': 'val',
                      'p_6': 'this_field'
                  },
                  returns='o_p',
                  result=Company)
Exemplo n.º 5
0
def test_group_traversal():
    compare_query(
        query=Company.match().group(
            'industry',
            edges=out(LocatedIn),
            edge_targets=out(LocatedIn).to(Country)).by('industry'),
        query_str='''FOR o_p_0 IN company'''
        '''  COLLECT field_industry=o_p_0.industry INTO groups = o_p_0'''
        '''  RETURN {'''
        '''    @p_2: (field_industry),'''
        '''    @p_4: ('''
        '''      FOR p_3_doc in groups[*]'''
        '''        FOR p_3_v, p_3_e IN 1..1 OUTBOUND p_3_doc._id located_at'''
        '''          RETURN p_3_e'''
        '''    ),'''
        '''    @p_6: ('''
        '''      FOR p_5_doc in groups[*]'''
        '''        FOR p_5_v, p_5_e IN 1..1 OUTBOUND p_5_doc._id located_at'''
        '''          FILTER IS_SAME_COLLECTION('country', p_5_v)'''
        '''          RETURN p_5_v'''
        '''    )'''
        '''  }''',
        bind_vars={
            'p_2': 'industry',
            'p_4': 'edges',
            'p_6': 'edge_targets'
        },
        returns=None,
        result=DictResult(
            display_name_to_result={
                'industry': VALUE_RESULT,
                'edges': ListResult(AnyResult([LocatedIn])),
                'edge_targets': ListResult(AnyResult([Country]))
            }))
Exemplo n.º 6
0
def test_array_traversal():
    compare_query(
        query=Company.match().as_var('a').array(
            out(LocatedIn).to(Country)).as_var('b').select(company=var('a'),
                                                           countries=var('b')),
        query_str='''FOR o_p_0_0 IN company'''
        '''  LET a = o_p_0_0'''
        '''  LET oqr_p_0 = o_p_0_0'''
        '''  LET array_p_0 = ('''
        '''    FOR p_0_1_v, p_0_1_e IN 1..1 OUTBOUND oqr_p_0._id located_at'''
        '''      FILTER IS_SAME_COLLECTION('country',p_0_1_v)'''
        '''      RETURN p_0_1_v'''
        '''  )'''
        '''  LET b = array_p_0'''
        '''  RETURN {'''
        '''    @p_2: (a),'''
        '''    @p_4: (b)'''
        '''  }''',
        bind_vars={
            'p_2': 'company',
            'p_4': 'countries'
        },
        returns=None,
        result=DictResult(
            display_name_to_result={
                'company':
                Company,
                'countries':
                ListResult(inner_result=AnyResult(inner_result=[Country]))
            }))
Exemplo n.º 7
0
def test_gt():
    compare_query(query=Company.match(gt('some1', 5)),
                  query_str='FOR o_p IN company'
                  '  FILTER o_p.some1 > @p_1'
                  '  RETURN o_p',
                  bind_vars={'p_1': 5},
                  returns='o_p',
                  result=Company)
Exemplo n.º 8
0
def test_like():
    compare_query(query=Company.match(like('some1', 'avocado%')),
                  query_str='FOR o_p IN company'
                  '  FILTER o_p.some1 LIKE @p_1'
                  '  RETURN o_p',
                  bind_vars={'p_1': 'avocado%'},
                  returns='o_p',
                  result=Company)
Exemplo n.º 9
0
def test_document_attribute():
    compare_query(
        query=Company.match().name,
        query_str='''FOR o_p IN company'''
                  '''  RETURN o_p.name''',
        bind_vars={},
        returns='o_p.name',
        result=VALUE_RESULT,
    )
Exemplo n.º 10
0
def test_document_nested_attribute():
    compare_query(
        query=Company.match().address.city,
        query_str='''FOR o_p IN company'''
                  '''  RETURN o_p.address.city''',
        bind_vars={},
        returns='o_p.address.city',
        result=VALUE_RESULT,
    )
Exemplo n.º 11
0
def test_edge_target_attribute():
    compare_query(
        query=Company.match().out().to().name,
        query_str='''FOR o_p_0 IN company'''
                  '''  FOR p_v, p_e IN 1..1 OUTBOUND o_p_0._id'''
                  '''    RETURN p_v.name''',
        bind_vars={},
        returns='p_v.name',
        result=VALUE_RESULT,
    )
Exemplo n.º 12
0
def test_select_document():
    compare_query(query=Company.match().select(object),
                  query_str='''FOR o_p_0 IN company'''
                  '''  RETURN {'''
                  '''    @p_2: (o_p_0)'''
                  '''  }''',
                  bind_vars={'p_2': 'document'},
                  returns=None,
                  result=DictResult(
                      display_name_to_result={'document': DOCUMENT_RESULT}))
Exemplo n.º 13
0
def test_group_field_by_field():
    compare_query(
        query=Company.match().group('industry').by('industry'),
        query_str='FOR o_p_0 IN company'
        '  COLLECT field_industry=o_p_0.industry INTO groups = o_p_0'
        '  RETURN {'
        '    @p_2: (field_industry)'
        '  }',
        bind_vars={'p_2': 'industry'},
        returns=None,
        result=DictResult(display_name_to_result={'industry': VALUE_RESULT}))
Exemplo n.º 14
0
def test_document_as_var_select_attribute():
    compare_query(
        query=Company.match().as_var('a').select(var('a').name),
        query_str='''FOR o_p_0 IN company'''
                  '''  LET a = o_p_0'''
                  '''  RETURN {'''
                  '''    @p_2: (a.name)'''
                  '''  }''',
        bind_vars={'p_2': 'a'},
        returns=None,
        result=DictResult(display_name_to_result={'a': VALUE_RESULT}),
    )
Exemplo n.º 15
0
def test_has_edges():
    compare_query(query=Company.match(out()),
                  query_str='FOR o_p IN company'
                  '  LET p_1_sub = ('
                  '     FOR p_1_v, p_1_e IN 1..1 OUTBOUND o_p._id'
                  '         RETURN 1'
                  '  )'
                  '  FILTER LENGTH(p_1_sub) > 0'
                  '  RETURN o_p',
                  bind_vars={},
                  returns='o_p',
                  result=Company)
Exemplo n.º 16
0
def test_group():
    compare_query(
        query=Company.match().group(),
        query_str='FOR o_p_0 IN company'
        '  COLLECT field__key=o_p_0._key INTO groups = o_p_0'
        '  RETURN {'
        '    @p_2: (groups)'
        '  }',
        bind_vars={'p_2': 'document'},
        returns=None,
        result=DictResult(display_name_to_result={
            'document': ListResult(inner_result=DOCUMENT_RESULT)
        }))
Exemplo n.º 17
0
def test_multiple_operators():
    compare_query(query=Company.match(like('some_string', 'avocado%'),
                                      gt('some_number',
                                         42)).match(eq('some_value', 'value')),
                  query_str='FOR o_p IN company'
                  '  FILTER o_p.some_string LIKE @p_1'
                  '  FILTER o_p.some_number > @p_2'
                  '  FILTER o_p.some_value == @p_3'
                  '  RETURN o_p',
                  bind_vars={
                      'p_1': 'avocado%',
                      'p_2': 42,
                      'p_3': 'value'
                  },
                  returns='o_p',
                  result=Company)
Exemplo n.º 18
0
def test_multiple_matches():
    compare_query(query=Company.match(some1='value').match(
        some2=42, some3=True).match(some4=3.1415),
                  query_str='FOR o_p IN company'
                  '  FILTER o_p.some1 == @p_1'
                  '  FILTER o_p.some2 == @p_2'
                  '  FILTER o_p.some3 == @p_3'
                  '  FILTER o_p.some4 == @p_4'
                  '  RETURN o_p',
                  bind_vars={
                      'p_1': 'value',
                      'p_2': 42,
                      'p_3': True,
                      'p_4': 3.1415
                  },
                  returns='o_p',
                  result=Company)
Exemplo n.º 19
0
def test_has_edge_vertices_that_match():
    compare_query(query=Company.match(out().to().match(gt('numerical', 42),
                                                       field='value')),
                  query_str='FOR o_p IN company'
                  '  LET p_1_sub = ('
                  '     FOR p_1_v, p_1_e IN 1..1 OUTBOUND o_p._id'
                  '       FILTER p_1_v.numerical > @p_1_0'
                  '       FILTER p_1_v.field == @p_1_1'
                  '       RETURN 1'
                  '  )'
                  '  FILTER LENGTH(p_1_sub) > 0'
                  '  RETURN o_p',
                  bind_vars={
                      'p_1_0': 42,
                      'p_1_1': 'value'
                  },
                  returns='o_p',
                  result=Company)
Exemplo n.º 20
0
def test_has_edges_that_match_to():
    # equivalent to Company.match(out()) and Company.match(out().to())

    compare_query(query=Company.match(out().match(to())),
                  query_str='FOR o_p IN company'
                  '  LET p_1_sub = ('
                  '     FOR p_1_v, p_1_e IN 1..1 OUTBOUND o_p._id'
                  '       LET p_1_0_sub = ('
                  '         RETURN 1'
                  '       )'
                  '       FILTER LENGTH(p_1_0_sub) > 0 '
                  '       RETURN 1'
                  '  )'
                  '  FILTER LENGTH(p_1_sub) > 0'
                  '  RETURN o_p',
                  bind_vars={},
                  returns='o_p',
                  result=Company)
Exemplo n.º 21
0
def test_group_field_and_document_by_field():
    compare_query(query=Company.match().group('industry',
                                              object).by('industry'),
                  query_str='FOR o_p_0 IN company'
                  '  COLLECT field_industry=o_p_0.industry INTO groups = o_p_0'
                  '  RETURN {'
                  '    @p_2: (field_industry),'
                  '    @p_4: (groups)'
                  '  }',
                  bind_vars={
                      'p_2': 'industry',
                      'p_4': 'document'
                  },
                  returns=None,
                  result=DictResult(
                      display_name_to_result={
                          'industry': VALUE_RESULT,
                          'document': ListResult(inner_result=DOCUMENT_RESULT)
                      }))
Exemplo n.º 22
0
def test_multipltes_matches_and_operators():
    compare_query(query=Company.match(like('some_string', 'avocado%'),
                                      gt('some_number', 42),
                                      some_condition=True).match(
                                          eq('some_object.field', 'value'),
                                          another_value=[4, 5]),
                  query_str='FOR o_p IN company'
                  '  FILTER o_p.some_string LIKE @p_1'
                  '  FILTER o_p.some_number > @p_2'
                  '  FILTER o_p.some_condition == @p_3'
                  '  FILTER o_p.some_object.field == @p_4'
                  '  FILTER o_p.another_value == @p_5'
                  '  RETURN o_p',
                  bind_vars={
                      'p_1': 'avocado%',
                      'p_2': 42,
                      'p_3': True,
                      'p_4': 'value',
                      'p_5': [4, 5]
                  },
                  returns='o_p',
                  result=Company)
Exemplo n.º 23
0
def test_group_field_document_and_count_by_field():
    compare_query(
        query=Company.match().group('industry',
                                    max('employee_number'),
                                    companies=object).by('industry'),
        query_str='''FOR o_p_0 IN company'''
        '''  COLLECT field_industry=o_p_0.industry INTO groups = o_p_0'''
        '''  RETURN {'''
        '''    @p_2: (field_industry),'''
        '''    @p_4: (MAX(groups[*].employee_number)),'''
        '''    @p_6: (groups)'''
        '''  }''',
        bind_vars={
            'p_2': 'industry',
            'p_4': 'max_employee_number',
            'p_6': 'companies'
        },
        returns=None,
        result=DictResult(
            display_name_to_result={
                'industry': VALUE_RESULT,
                'max_employee_number': VALUE_RESULT,
                'companies': ListResult(DOCUMENT_RESULT)
            }))
Exemplo n.º 24
0
def test_has_edges_of_collection_that_match_to_collection_multiple_inner():
    compare_query(
        query=Company.match(out(LocatedIn,
                                SubsidiaryOf).match(field1='value').to(
                                    Company,
                                    Country).match(field2='value').inbound(
                                        LocatedIn, min_depth=2,
                                        max_depth=5).match(to(Company),
                                                           field3='value'),
                            field4='value'),
        query_str='''FOR o_p IN company'''
        '''  LET p_1_sub = ('''
        '''    FOR p_1_0_v, p_1_0_e IN 1..1 OUTBOUND p_1_0_v._id located_at,subsidiary_of'''
        '''      FILTER IS_SAME_COLLECTION('company', p_1_0_v) OR IS_SAME_COLLECTION('country', p_1_0_v)'''
        '''      FILTER p_1_0_v.field2 == @p_1_0_1'''
        '''      FILTER p_1_0_e.field1 == @p_1_0_2'''
        '''      FOR p_1_v, p_1_e IN 2..5 INBOUND p_1_0_v._id located_at'''
        '''        LET p_1_0_sub = ('''
        '''          FILTER IS_SAME_COLLECTION('company', p_1_v)'''
        '''            RETURN 1'''
        '''        )'''
        '''        FILTER LENGTH(p_1_0_sub) > 0'''
        '''    FILTER p_1_e.field3 == @p_1_0'''
        '''    RETURN 1'''
        '''  )'''
        '''  FILTER LENGTH(p_1_sub) > 0'''
        '''  FILTER o_p.field4 == @p_4'''
        '''  RETURN o_p''',
        bind_vars={
            'p_4': 'value',
            'p_1_0_1': 'value',
            'p_1_0_2': 'value',
            'p_1_0': 'value'
        },
        returns='o_p',
        result=Company)
Exemplo n.º 25
0
def test_return_all_from_collection():
    compare_query(query=Company.match(),
                  query_str='FOR o_p IN company RETURN o_p',
                  bind_vars={},
                  returns='o_p',
                  result=Company)