Skip to content

Commit

Permalink
[resotocore][fix] access to graphdb props (#1911)
Browse files Browse the repository at this point in the history
  • Loading branch information
aquamatthias committed Feb 14, 2024
1 parent ac50d97 commit f290cca
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
14 changes: 8 additions & 6 deletions resotocore/resotocore/db/arango_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def to_query(
) -> Tuple[str, Json]:
ctx = ArangoQueryContext()
query = query_model.query
start = from_collection or f"`{db.vertex_name}`"
start = from_collection or f"`{db.graph_vertex_name()}`"
cursor, query_str = query_string(db, query, query_model, start, with_edges, ctx, id_column=id_column)
last_limit = (
f" LIMIT {ll.offset}, {ll.length}" if ((ll := query.current_part.limit) and not query.is_aggregate()) else ""
Expand Down Expand Up @@ -473,7 +473,9 @@ def check_is(t: IsTerm) -> Optional[str]:
part_res = ctx.next_crs("part_res")
resolved = is_already_resolved(mq_in.query)
if resolved:
merge_result += f'LET {part_res} = DOCUMENT("{db.vertex_name}", {merge_cursor}.refs.{resolved}_id)'
merge_result += (
f'LET {part_res} = DOCUMENT("{db.graph_vertex_name()}", {merge_cursor}.refs.{resolved}_id)'
)
else:
add_merge_query(mq_in, part_res)
set_value_in_path(part_res, mq_in.name, merge_parts)
Expand Down Expand Up @@ -549,7 +551,7 @@ def with_usage(in_crsr: str, usage: WithUsage, term: Term, limit: Optional[Limit
for r in {after_filter_cursor}
let resource=r
let resource_usage = first(
for m in {db.usage_db.collection_name}
for m in {db.graph_usage_collection_nane()}
filter m.at>=@{start} and m.at<=@{end} and m.id==r._key
collect aggregate {", ".join(avgs)}, count = sum(1)
return {{usage:{{{",".join(merges)},entries:count,start:@{start_s},duration:@{duration}}}}}
Expand Down Expand Up @@ -740,7 +742,7 @@ def ft_term(cursor: str, ab_term: Term) -> str:
# Since fulltext filtering is handled separately, we replace the remaining filter term in the first part
query_parts[0] = evolve(query_parts[0], term=filter_term)
crs = ctx.next_crs()
doc = f"search_{db.vertex_name}"
doc = f"search_{db.graph_vertex_name()}"
ftt = ft_term("ft", ft_part)
q = f"LET {crs}=(FOR ft in {doc} SEARCH ANALYZER({ftt}, 'delimited') SORT BM25(ft) DESC RETURN ft)"
return q, crs
Expand Down Expand Up @@ -783,7 +785,7 @@ def possible_values(
skip: Optional[int] = None,
) -> Tuple[str, Json]:
path = path_or_predicate if isinstance(path_or_predicate, str) else path_or_predicate.name
start = f"`{db.vertex_name}`"
start = f"`{db.graph_vertex_name()}`"
ctx = ArangoQueryContext()
cursor, query_str = query_string(db, query.query, query, start, False, ctx, id_column="_key")

Expand Down Expand Up @@ -845,7 +847,7 @@ def create_time_series(
) -> Tuple[str, Json]:
query = query_model.query
ctx = ArangoQueryContext()
start = f"`{db.vertex_name}`"
start = f"`{db.graph_vertex_name()}`"
cursor, query_str = query_string(db, query, query_model, start, False, ctx)
next_crs = ctx.next_crs()
at_bvn = ctx.add_bind_var(at)
Expand Down
27 changes: 27 additions & 0 deletions resotocore/resotocore/db/graphdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ async def copy_graph(self, to_graph: GraphName, to_snapshot: bool = False) -> "G
async def insert_usage_data(self, data: List[UsageDatapoint]) -> None:
pass

@abstractmethod
def graph_vertex_name(self) -> str:
pass

@abstractmethod
def graph_usage_collection_nane(self) -> str:
pass

@abstractmethod
def edge_collection(self, edge_type: EdgeType) -> str:
pass


class ArangoGraphDB(GraphDB):
def __init__(self, db: AsyncArangoDB, name: GraphName, adjust_node: AdjustNode, config: GraphUpdateConfig) -> None:
Expand All @@ -247,6 +259,12 @@ def __init__(self, db: AsyncArangoDB, name: GraphName, adjust_node: AdjustNode,
def name(self) -> GraphName:
return self._name

def graph_vertex_name(self) -> str:
return self.vertex_name

def graph_usage_collection_nane(self) -> str:
return self.usage_db.collection_name

def edge_collection(self, edge_type: EdgeType) -> str:
return f"{self.name}_{edge_type}"

Expand Down Expand Up @@ -1819,3 +1837,12 @@ async def copy_graph(self, to_graph: GraphName, to_snapshot: bool = False) -> Gr

async def insert_usage_data(self, data: List[UsageDatapoint]) -> None:
await self.real.insert_usage_data(data)

def graph_vertex_name(self) -> str:
return self.real.graph_vertex_name()

def graph_usage_collection_nane(self) -> str:
return self.real.graph_usage_collection_nane()

def edge_collection(self, edge_type: EdgeType) -> str:
return self.real.edge_collection(edge_type)

0 comments on commit f290cca

Please sign in to comment.