ngs-doo / revenj

DSL Platform compatible backend

Home Page:https://dsl-platform.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

View generated from snowflake should have left join

Kobus-Smit opened this issue · comments

Hi @zapov

Given this cut down dsl

module test {

root client(id) {
  int id { sequence; }
  string name;
}

root facility(id, client_id) {
  string id;
  int client_id;

  relationship client_rel(client_id) client; index(client_id);
}

root rating(id) {
  long id { sequence; }
  client *client { serialization name 'client'; }
  int clientID;
  string? facility_id;
  long? assigned_from;

  relationship assigned_from_rel(assigned_from) rating;        index(assigned_from);
  relationship facility_rel(facility_id, clientID) facility;   index(facility_id, clientID);
}

snowflake<rating> rating_list {
  id;
  client.id as client_id;
  client.name as client_name;
  facility_rel.id as facility_id;
  assigned_from_rel.client.name as assignor_name;
}

}

Note the optional facility_id.
The v2.5.7202.21321 compiler generates this view:

create view rating_list("URI", id, client_id, client_name, facility_id, assignor_name) as
select (_entity.id)::text as "URI",
       _entity.id,
       _entity_client.id as client_id,
       _entity_client.name as client_name,
       _entity_facility_rel.id as facility_id,
       _entity_assigned_from_rel_client.name as assignor_name
from ((((test.rating_entity _entity
  join test.client_entity _entity_client on ((_entity_client.id = _entity."clientID")))
  join test.facility_entity _entity_facility_rel on ((((_entity_facility_rel.id)::text = (_entity.facility_id)::text) and
                                                      (_entity_facility_rel.client_id = _entity."clientID"))))
  left join test.rating_entity _entity_assigned_from_rel on ((_entity_assigned_from_rel.id = _entity.assigned_from)))
  left join test.client_entity _entity_assigned_from_rel_client on ((_entity_assigned_from_rel_client.id = _entity_assigned_from_rel."clientID")));

In this case I'd expect a left join facility_entity. Currently the view does not return any rows where the rating does not have a facility_id.

Please advise.

Regards
Kobus

commented

Tnx for the bug report.
I've fixed this and will deploy new version later today after tests finish. I suspect there might be some other side-effects of this fix which are not in sync.

btw. if you are into db friendly names there is database { postgres name <table>; } and int clientID { postgres name client_id; } if you prefer to use such names

Thanks @zapov

I'll remember the postgres name next time. This specific database was created 1.5 years ago, that's why it has mixed * and relationship's. I might do that refactoring because it will be cleaner and friendlier to do sql without the double quotes.

commented

New compiler is up. It should work now

Fixed in 2.5.7526.35703