GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Cypher `MERGE` should use merge key with unique index · Issue #1301 · ArcadeData/arcadedb

Cypher MERGE should use merge key with unique index #1301

New issue
Copy link
New issue
Copy link
Closed
Closed
Cypher MERGE should use merge key with unique index#1301
Copy link
Assignees
lvca
Labels
documentationImprovements or additions to documentationwontfixThis will not be worked onworkaround-provided
Milestone
23.11.1

Description

@LeonardoMarrancone
LeonardoMarrancone
opened on Nov 3, 2023
Issue body actions

ArcadeDB Version:

23.10.1

OS and JDK Version:

docker image

Expected behavior

Cypher MERGE should use merge key with unique index

Actual behavior

Cypher MERGE should use merge key with unique index, please look at the steps to reproduce the problem.

Steps to reproduce

CREATE VERTEX TYPE Test;
CREATE PROPERTY Test.id STRING;
CREATE INDEX ON Test (id) UNIQUE;
CREATE (v:Test{id: 0});
UNWIND range(0, 10) AS id MERGE (v:Test{id: id}) RETURN v; // returns: Found duplicate key in index Duplicated key [0] found on index 'Test[id]' already assigned to record #1:0

Activity

  1. lvca
    self-assigned this
    on Nov 6, 2023
  2. lvca
    added
    bug
    on Nov 6, 2023
  3. lvca
    added this to the 23.11.1 milestone on Nov 6, 2023
  4. lvca commented on Nov 7, 2023

    @lvca
    lvca
    on Nov 7, 2023
    Member
    More actions

    Reproduced.

  5. lvca commented on Nov 8, 2023

    @lvca
    lvca
    on Nov 8, 2023
    Member
    More actions

    This issue happens inside the Cypher to Gremlin converter. The generated gremlin for a simple MERGE query is not very readable. Also, it's hard to fix that component.

    What about using SQL for that? You could do the same using a SQL UPDATE ... UPSERT ...

  6. lvca
    added
    workaround-provided
    waiting for user
    on Nov 8, 2023
  7. LeonardoMarrancone commented on Nov 8, 2023

    @LeonardoMarrancone
    LeonardoMarrancone
    on Nov 8, 2023
    Author
    More actions

    Unfortunately we cannot move to SQL, we have to stick with Cypher, we're using a tool that works only with it. Could you please elaborate what the problem is? I mean what is the expected gremlin query vs the actual? Thank you so much!

  8. lvca commented on Nov 8, 2023

    @lvca
    lvca
    on Nov 8, 2023
    Member
    More actions

    This is the compiled query to Gremlin:

    g.inject('  cypher.start').repeat(__.sideEffect(__.loops().aggregate('  GENERATED1'))).until(__.loops().is(gt(10))).select('  GENERATED1').unfold().as('id').choose(__.V().as('v').hasLabel('Test').where(__.select('v').values('id').where(eq('id'))), __.V().as('v').hasLabel('Test').where(__.select('v').values('id').where(eq('id'))), __.identity().addV('Test').as('v').property(single, 'id', __.select('id'))).select('v').project('v').by(__.valueMap().with('~tinkerpop.valueMap.tokens'))
    
  9. LeonardoMarrancone commented on Nov 9, 2023

    @LeonardoMarrancone
    LeonardoMarrancone
    on Nov 9, 2023
    Author
    More actions

    My Gremlin Knowledge is not so advanced so please forgive me if I'm saying something wrong.
    Checking the generated query looks fine because (for sure is not optimized I agree):

    g.inject('  cypher.start')
    	.repeat(__.sideEffect(__.loops().aggregate('  GENERATED1')))
    	.until(__.loops().is(gt(10)))
    	.select('  GENERATED1')
    	.unfold()
    	.as('id')
    	.choose(
    		__.V().as('v').hasLabel('Test').where(__.select('v').values('id').where(eq('id'))),
            __.V().as('v').hasLabel('Test').where(__.select('v').values('id').where(eq('id'))),
    		__.identity().addV('Test').as('v').property(single, 'id', __.select('id'))
    	)
    	.select('v')
    	.project('v')
    	.by(__.valueMap().with('~tinkerpop.valueMap.tokens'))
    

    in the choose step it checks before if the node exists if true gets it, otherwise it creates a new one.
    Do you see any issue in there?

  10. lvca commented on Nov 9, 2023

    @lvca
    lvca
    on Nov 9, 2023
    Member
    More actions

    I'm not a Gremlin expert. Tried to check in debug and it calls the addV() with id = 0 so the choose doesn't work for some reason.

  11. lvca
    added a commit that references this issue on Nov 9, 2023

    test: added test case, commented because it's failing

    2c5baa5
  12. LeonardoMarrancone commented on Nov 14, 2023

    @LeonardoMarrancone
    LeonardoMarrancone
    on Nov 14, 2023
    Author
    More actions

    After a debug session we realised that there is no real problem in fact we declare Test.id as STRING and then we use an integer; changing it to CREATE PROPERTY Test.id INTEGER; make everything work as expected. Btw we would expect a type error with the first create, and that lead us to the problem; maybe is good to have a type check if it's defined.

  13. lvca commented on Nov 14, 2023

    @lvca
    lvca
    on Nov 14, 2023
    Member
    More actions

    You're right, the loookup on the index must always fail when insert the vertex with Id 0.

    This is a bug and shouldn't happen. We support automatic cast between types when they are compatible., but seems like a piece is missing here.

    Either we raise an error because the type wasn't a string or we should transform the value to string during the index lookup.

  14. lvca commented on Nov 14, 2023

    @lvca
    lvca
    on Nov 14, 2023
    Member
    More actions

    I can't drop the automatic conversion, otherwise in production systems would break after the upgrade. And honestly I think it's nice to have in place.

    By debugging the original test case and the issue is not in the ArcadeDB part, but Gremlin: the comparison during the traversal (org.apache.tinkerpop.gremlin.process.traversal.Compare.eq()) fails because the automatic conversion is not supported by gremlin and the string "0" is not equals to 0.

    Looking for a solution.

  15. lvca
    added a commit that references this issue on Nov 14, 2023

    test: fixed test case from the issue

    670b3ac
  16. lvca commented on Nov 14, 2023

    @lvca
    lvca
    on Nov 14, 2023
    Member
    More actions

    Tried to intercept where the Product value is computed, but those classes are not extendable and would require to rewrite large pieces of Gremlin Steps to add this custom transformation. I think it's better to document this limitation in our documentation for further users. I've added a new paragraph "Known Limitations" in both Gremlin and Cypher chapters.

    Known Limitations with the Cypher Implementation

    ArcadeDB automatically handles the conversion between compatible types, such as strings and numbers when possible. Cypher does not. So if you define a schema with the ArcadeDB API and then you use Cypher for a traversal, ensure you’re using the same type you defined in the schema. For example, if you define a property "id" to be a string, and then you’re executing traversal by using integers for the ids, the result could be unpredictable.

  17. lvca
    closed this as completedon Nov 14, 2023
  18. lvca
    added
    documentationImprovements or additions to documentation
    wontfixThis will not be worked on
    and removed
    bug
    waiting for user
    on Nov 14, 2023
  19. mergify
    added a commit that references this issue on Dec 1, 2025

    chore(deps): bump org.codehaus.mojo:versions-maven-plugin from 2.19.1…

    abcb9ff
  20. tae898
    added 3 commits that reference this issue on Jun 28, 2026

    test: added test case, commented because it's failing

    a3c1e37

    test: fixed test case from the issue

    f7f3f4a

    chore(deps): bump org.codehaus.mojo:versions-maven-plugin from 2.19.1…

    c39faf2
  21. mergify
    added 2 commits that reference this issue on Jun 29, 2026

    chore(deps): update psycopg requirement from >=3.2.13 to >=3.3.4 in /…

    62f3281

    chore(deps): update psycopg-binary requirement from >=3.2.13 to >=3.3…

    6d30d72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @lvca
    lvca

Labels

documentationImprovements or additions to documentationwontfixThis will not be worked onworkaround-provided

Type

No type

Projects

No projects

    Milestone

    • 23.11.1

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.