0

I'm trying to translate the following working gremlin query to C# using Gremlinq (CosmosDB provider), and I'm struggling to find the root cause why it doesn't compile.

Original query (working):

g.V('topic_1').optional(__.as ('source').outE('TopicBrowserItemReference').as ('guide').inV().as ('target')
.coalesce(
       choose(__.select('source').has('IsCarousel', true),
              outE('TopicBrowserItemReference').as ('guide2').inV().as ('target2').select('source', 'guide', 'target', 'guide2', 'target2'), 
              __.select('source', 'guide', 'target')),
    __.select('source', 'guide', 'target'), 
    __

Translation attempt (not compiling):

var wip = await _g
    .V<TopicBrowserItem>("topic_1")
    .Optional(__ => __
        .As((__, source) => __
            .OutE<TopicBrowserItemReference>()
            .As((__, guide) => __
                .InV<TopicBrowserItem>()
                .As((__, target) => __
                    .Coalesce((__) => __
                        .Choose(
                            // Predicate
                            __ => __.Select(source).Where(c => c.IsCarousel), // <- Compile error here
                            // True choice
                            __ => __.Select(target),
                            __ => __.OutE<TopicBrowserItemReference>()
                                .As((__, guide2) => __
                                    .InV<TopicBrowserItem>()
                                    .As((__, target2) => __
                                        .Select(source, guide, target, guide2, target2))),
                            // False choice
                            __ => __.Select(source, guide, target)),
                        __ => __.Select(source, guide, target),
                        __)))));

Since I'm new to graph processing, I'm not very confident that my approach is the easiest or the best one.

But what I basically want to achieve is:

  1. Starting from a node (return at least this node as result)
  2. Get descendants of this node (incl. edges)
  3. If the starting node has a truthy "IsCarousel" property, dig one level deeper and collect the edges/vertices for all paths (from root to grand-children)
  4. ...otherwise keep results of 2.

I'm not sure if it helps to provide the compile error, since it varies with every slight modification, and I have the feeling that the root cause for the error could lie at a totally different location within the query. But for the provided code, the error is:

'IChooseBuilder<IVertexGremlinQuery<TopicBrowserItem>>' does not contain a definition for 'Select' and the best extension method overload 'GremlinQuerySerializer.Select(IGremlinQuerySerializer, Func<object, object>)' requires a receiver of type 'IGremlinQuerySerializer'

martinoss
  • 5,268
  • 2
  • 45
  • 53

0 Answers0