Max
Max
Explore posts from servers
ATApache TinkerPop
Created by Max on 10/2/2024 in #questions
Confusing behavior of `select()`.
The following traversal acts as a counter:
g.withSideEffect("map", [3: "foo", 4: "bar"]).
inject("a", "b", "c", "d").
aggregate(local, "x").
map(select("x").count(local))
g.withSideEffect("map", [3: "foo", 4: "bar"]).
inject("a", "b", "c", "d").
aggregate(local, "x").
map(select("x").count(local))
It produces:
==>1
==>2
==>3
==>4
==>1
==>2
==>3
==>4
I want to modify the traversal to use this count to produce ["foo", "bar"]. So, I tried adding .as("cnt").select("map").select(select("cnt")) like this:
g.withSideEffect("map", [3: "foo", 4: "bar"]).
inject("a", "b", "c", "d").
aggregate(local, "x").
map(select("x").count(local)).
as("cnt").
select("map").select(select('cnt'))
g.withSideEffect("map", [3: "foo", 4: "bar"]).
inject("a", "b", "c", "d").
aggregate(local, "x").
map(select("x").count(local)).
as("cnt").
select("map").select(select('cnt'))
But the code above does not work as expected, it produces no output. Interestingly, if I change select("cnt") to constant(3), then it starts producing foo:
==>foo
==>foo
==>foo
==>foo
==>foo
==>foo
==>foo
==>foo
Could someone help me understand why select("cnt") is not working here and why using constant(3) works? Thanks in advance!
11 replies
ATApache TinkerPop
Created by Max on 9/28/2024 in #questions
Best practices for local development with Neptune.
I would like to use a local Gremlin server with TinkerGraph for local development, and then deploy changes to Neptune later. However, there are several differences between TinkerGraph and Neptune that impact the portability of the code. The most important one is probably the fact that in Tinkergraph vertex and edge ids are numeric, but they are strings in Neptune. Also, I think there are some differences in how properties are handled if the cardinality is a list. What is the recommended workflow to minimize discrepancies between my local environment and Neptune?
11 replies
ATApache TinkerPop
Created by Max on 9/28/2024 in #questions
Sequential edge creation between streamed vertices
I would like to create an edge between vertices as they are streamed in sequence from a traversal. I want to connect each vertex to the next one in the stream, like a linear chain of vertices with a next edge. For example, given this g.V().hasLabel("person").values("name") produces:
==> josh
==> peter
==> marko
==> vadas
==> josh
==> peter
==> marko
==> vadas
I'd like to achieve something like josh -next-> peter -next-> marko -next-> vadas My current approach is to create a "sliding window" of vertex pairs:
g.V().
hasLabel("person").
aggregate(local, "a").by("name").
map(select("a").tail(local, 2)).
skip(1)
g.V().
hasLabel("person").
aggregate(local, "a").by("name").
map(select("a").tail(local, 2)).
skip(1)
Which results in:
==> [josh, peter]
==> [peter, marko]
==> [marko, vadas]
==> [josh, peter]
==> [peter, marko]
==> [marko, vadas]
Next I add edges between each pair:
g.V().
hasLabel("person").
aggregate(local, "a").
map(select("a").tail(local, 2)).
skip(1).
addE("next").from(limit(local, 1)).to(tail(local, 1))
g.V().
hasLabel("person").
aggregate(local, "a").
map(select("a").tail(local, 2)).
skip(1).
addE("next").from(limit(local, 1)).to(tail(local, 1))
This works, but I’m not sure if this is the idiomatic way to do this. I think modeling data where vertices are explicitly ordered through an edge connection is not uncommon, right?
5 replies
ATApache TinkerPop
Created by Max on 9/3/2024 in #questions
Gremlin query to order vertices with some locked to specific positions
I'm working with a product catalog in a graph database using Gremlin. The graph structure includes: 1. Product vertices 2. Category vertices 3. belongsTo edges connecting products to categories. The edge can have an optional lockedPosition property as integer. I need to create a query that returns products in a specific order, where: 1. Some products are "locked" to specific positions (stored as a lockedPosition property on the belongsTo edge) 2. Other "unlocked" products should fill in around these fixed positions For example, if I have 20 products in a category, and product A is locked to position 3 and product B to position 7, the result should return these products in those exact positions, with other products filling the remaining slots with whatever sorting order. (this "product pinning/locking" functionality is used by merchandising team to manually re-arrange products on a product listing page). Can anyone suggest a Gremlin query to achieve this? Also, maybe my data model is wrong for this use case, so I am also keen to accept other suggestions to represent this use case. Thank you!
18 replies
DDeno
Created by Max on 5/12/2024 in #help
Deno package management questions.
I have a few questions regarding package management in Deno. 1. Here Deno documentation states that import maps are only applied to applications, and that library authors should prefer the deps.ts pattern. Contrarily, the jsr documentation specifies that a dependency manifest like the import map in the deno.json file can be used by a library. Does this mean that the deps.ts pattern is now obsolete? 2. How do I use packages published with jsr in a browser environment? Using esm.sh, I can do import ... from "https://esm.sh/[email protected]". Can I do the same with jsr? 3. In jsr, all entry points have to be specified explicitly, so we no longer need to add a package with a trailing slash in the import map to import modules beyond the default entry point. Is this correct? 4. How do I replicate a configuration like this in jsr, specifically specifying external dependencies and aliases?
"imports": {
...
"@headlessui/react": "https://esm.sh/@headlessui/[email protected]?external=react,react-dom&alias=@types/react:preact/compat",
...
},
"imports": {
...
"@headlessui/react": "https://esm.sh/@headlessui/[email protected]?external=react,react-dom&alias=@types/react:preact/compat",
...
},
3 replies
DDeno
Created by Max on 11/26/2023 in #help
Custom `401 Unauthorized` error page, similar to builtin `404 Not Found`?
How can I create a custom error page that is rendered by middleware in Fresh? The middleware handles authentication for incoming requests and if a request fails authentication, the middleware should generate a 401 Unauthorized response that includes the body of the custom error page.
2 replies