Gremlin addV () возвращает «неверные аргументы запроса» - PullRequest
0 голосов
/ 17 января 2020

Следующий тест не пройден с ошибкой Invalid Request Arguments, возвращенной из JanusGraph 0.4 с серверной частью cassandra 3.11:

const url = "ws://localhost:8182/gremlin"

var target *DocumentGraph

func TestMain(m *testing.M) {
    var err error
    target, err = NewDocumentGraph(url)
    if err != nil {
        fmt.Printf("failed to initialize gremlin cluster: %v\n", err)
        os.Exit(1)
    }
    os.Exit(m.Run())
}

func TestDocumentGraph_CreateFromJSON(t *testing.T) {
    data := `{
    "label":"inline",
    "tagName":"img",
    "key":"inline_VMJc8GgHqqJjmvb",
    "attributes":{
        "alt":"",
        "border":"0",
        "height":"1",
        "src":"http://links.transactions.overstock.com/wf/open?upn=lvH1F6JqxvnN0PAh3-2B8DWHCc6xqkDFpMVqX-2F-2F5xEHnOuk56mqNJgyKTEH4WKg1ov-2FNuwliFWi7L8-2B268R5AHIsziCbIAIfk3yJkj4St6VLbMb7KSBbacUm0cOuk-2Bbc8s1AU42HQ0qXvV5RjQoP1kHZvbQTNtpLRgsHqp4qBfCUyNvIkyTuQYk-2BrGwE-2BuIFLR37x2H8QgDhDb6BRqPqRa1sBoBktHbPkPzToRS0450idiTYDCBw-2BGuYcmjsxiioABXbhiD83nLxak5QKz3fEGpcWDtV0FIJ6791hoRnbV-2FDSWPdtvCNUVXFFF0N4zhsYS-2Bgj4kXAin-2FZvHdfc7WwtGH17ZrHT4euNwpxBgoVHQZ9Q-2BrLvhMS35ktJFtOV5YwVf3-2FEopcH1ZLJrRxDRfLqjUktPLU9b5mUtmRYky-2F38wzbEWn-2BR7OcG2XZAcIsr-2BjCvduEW04bS1Gpt-2F9fRL59vzEBUnPidS2e9CNPxu8ew4m-2BHLxUScvqISAO9cIsrxZh-2FxctpugiqU2Cof1i9IZ2eyO9CXG4Mm00qaWzUaW4cofLSb-2FswC6fmM0IEaI9WcRTFBhiHmHbotLQquw4K0vXLyi6pbHn-2Bo6NaKDM6-2BjeaaGULUqLmDdnGGw6D0Txe4v8bDYxjtbkPvCs9VWHzPYcXQ-3D-3D",
        "style@border-width":"0 !important",
        "style@height":"1px !important",
        "style@margin-bottom":"0 !important",
        "style@margin-left":"0 !important",
        "style@margin-right":"0 !important",
        "style@margin-top":"0 !important",
        "style@padding-bottom":"0 !important",
        "style@padding-left":"0 !important",
        "style@padding-right":"0 !important",
        "style@padding-top":"0 !important",
        "style@width":"1px !important",
        "width":"1"
    }
}`
    v := &vertex{
        children: make([]*vertex, 0),
    }
    if err := JSON.Unmarshal([]byte(data), v); err != nil {
        t.Fatalf("failed to unmarshal test json data: %v", err)
    }

    if err := target.createVertex(v); err != nil {
        t.Errorf("failed to create vertex: %v", err)
    }
}

Странная часть, если я удаляю ЛЮБОЕ 2 attributes, это работает хорошо. Я знаю, что gremlin не ограничен 14 property операторами, потому что я выполнил оператор с более чем 17 из консоли, так что происходит?

EDIT: если я удаляю параметры из значений свойства и просто отправьте запрос без каких-либо параметров он работает. Так есть ли ограничения на количество параметров для запроса?

Вот соответствующий код:

type vertex struct {
    ID         int64 `json:"id,omitempty"`
    parent     *vertex
    children   []*vertex
    Label      string            `json:"label,omitempty"`
    TagName    string            `json:"tagName,omitempty"`
    Key        string            `json:"key,omitempty"`
    Attributes map[string]string `json:"attributes"`
}

type DocumentGraph struct {
    graph *gremlin.Client
}

func NewDocumentGraph(url string) (*DocumentGraph, error) {
    g, err := gremlin.NewClient(url)
    if err != nil {
        return nil, fmt.Errorf("failed to create gremlin client: %v", err)
    }

    return &DocumentGraph{
        graph: g,
    }, nil
}

func (d *DocumentGraph) createVertex(v *vertex) error {
    var (
        labelParam = "labelName"
        keyParam   = "docKey"
    )
    var q strings.Builder
    p := gremlin.Bind{
        labelParam: v.Label,
        keyParam:   v.Key,
    }
    q.WriteString(fmt.Sprintf(`g.addV(%s).as(%s).property("document_key", %s)`, labelParam, keyParam, keyParam))
    for k, v := range v.Attributes {
        pname := strings.ReplaceAll(strings.ReplaceAll(k, `-`, `_`), `@`, `_at_`)
        q.WriteString(fmt.Sprintf(`.property(%q, %s)`, k, pname))
        p[pname] = v
    }

    for i, c := range v.children {
        q.WriteString(fmt.Sprintf(`.V(id_%d).addE("parent").to(%s)`, i, keyParam))
        p[fmt.Sprintf("id_%d", i)] = c.ID
    }

    // terminal step will trigger the batch to write everything
    q.WriteString(fmt.Sprintf(".select(%s).valueMap(true)", keyParam))

    // read result for id
    req := gremlin.Query(q.String()).Bindings(p)
    b, _ := gremlin.GraphSONSerializer(req)
    data, err := d.graph.Exec(req)
    if err != nil {
        return fmt.Errorf("failed to create vertex for query : %s: %v", b, err)
    }

    fmt.Printf("successfully created vertex: %s\n", b)
    return nil
}

...