How to find all nodes which linked by edge with exact property in OrientDB?

49 Views Asked by At

I have several services and would like to see how they linked via requests

So I created edges as class "Http" and added property "request"

All services

I have 4 services

  1. Gateway
  2. ServiceA
  3. ServiceB
  4. ServiceC

I would like to display all services which linked by edge with property equal "get_user_info"

Gateway -> ServiceA -> ServiceC -> ServiceB

What I would like to see

And property equal "delete_user"

Gateway -> ServiceB

What I would like to see

It can be like that "SELECT * FROM Services WHERE edge.request ='get_user_info'"

I tried

SELECT * 
FROM Services 
WHERE in('http').request = 'get_user_info' OR out('http').request = 'get_user_info'
SELECT expand(in('http')[request='get_user_info']) FROM Services;

But it does not work

I tried

select * from `Services` WHERE @rid IN (select in from `http` where request = 'get_user_info') OR @rid IN (select out from `http` where request = 'get_user_info') 

and it works, but I see Link from ServiceB to Gateway Can I filter that link?

1

There are 1 best solutions below

0
hartmut On

still using OrientDB? I suggest to upgrade to ArcadeDB.

used your case as test-case for the ruby-interface to ArcadeDB (https://github.com/topofocus/arcadedb)

Basically, use a match statement. Its compiled at the bottom of the test-case.

RSpec.describe Arcade::Base do
  before(:all) do
    connect
    db = Arcade::Init.db
    My::V1.create_type
    My::E1.create_type
    db.begin_transaction
    My::V1.delete all: true
    g,a,b,c = ["Gateway", "ServiceA", "ServiceB", "ServiceC"].map {|y| My::V1.insert a: y}
    request='get_user_info'
    g.assign via: My::E1, to: a, request: request  #  create edges
    g.assign via: My::E1, to: b, request: "delete_user"
    a.assign via: My::E1, to: c, request: request
    c.assign via: My::E1, to: b, request: request

  end
  after(:all) do
     db = Arcade::Init.db
     db.rollback
  end

  context "check setup" do

    Given( :gateway  ){ My::V1.find a: 'Gateway' }
    Then { gateway.out.size == 2 }
    When( :deleted_service ){ My::V1.where a: 'ServiceB' }
    When( :request_service ){ My::V1.where a: 'ServiceA' }
    Then { gateway.nodes( :outE, where: { request: "delete_user" }) == deleted_service }
    Then { gateway.nodes( :outE, where: { request: "get_user_info" }) == request_service }

  end

  context "get deleted User relation" do
    Given( :gateway_record ){ Arcade::Match.new type: My::V1, where:{ a: 'Gateway' }, as: :g }
    Given( :gateway  ){ My::V1.where a: 'Gateway' }
    Given( :deleted_service ){ My::V1.where a: 'ServiceB' }
    Then  { gateway_record.to_s == "MATCH { type: my_v1, where: ( a='Gateway' ), as: g } RETURN g " }
    Then  { gateway_record.execute.select_result ==  gateway}

    Given( :deleted_user_record  ){ gateway_record.outE( My::E1,  where: { request: 'delete_user' }).node(as: :f) }
    Then { deleted_user_record.to_s == "MATCH { type: my_v1, where: ( a='Gateway' ), as: g }.outE('my_e1'){ where: ( request='delete_user' ) }.inV(){ as: f } RETURN g,f " }
    Then { deleted_user_record.execute.allocate_model  ==   gateway + deleted_service }
  end

end