Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoteMutableEdge.save(bucketName) does not support update like its counter part RemoteMutableEdge.save() #1578

Open
rmsloan opened this issue Apr 29, 2024 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@rmsloan
Copy link

rmsloan commented Apr 29, 2024

ArcadeDB Version:

ArcadeDB Server v24.4.1

OS and JDK Version:

Linux 4.18.0-477.21.1.el8_8.x86_64 - OpenJDK 64-Bit Server VM 11.0.22 (Temurin-11.0.22+7)

Expected behavior

Expected RemoteMutableEdge.save(bucketName) to perform an sql update similarly to its counter part save()

Actual behavior

RemoteMutableEdge.save(bucketName) throws an IllegalStateException; however I believe it should do the following if (rid != null)

  • Check for bucket validity; just like MutableDocument does
  • sql update; just like its save() counterpart
MutableDocument - for comparison

  public MutableDocument save(final String bucketName) {
    dirty = true;
    if (rid != null) {
      // UPDATE
      if (rid.bucketId != database.getSchema().getBucketByName(bucketName).getFileId())
        throw new IllegalStateException("Cannot update a record in a custom bucket");

      database.updateRecord(this);
    } else
      // CREATE
      database.createRecord(this, bucketName);
    return this;
  }
RemoteMutableEdge - for comparison

  @Override
  public MutableEdge save() {
    dirty = true;
    if (rid != null)
      remoteDatabase.command("sql", "update " + rid + " content " + toJSON());
    else
      remoteDatabase.command("sql", "insert into " + getTypeName() + " content " + toJSON());
    dirty = false;
    return this;
  }
RemoteMutableEdge - Requires Fix

  @Override
  public MutableEdge save(final String bucketName) {
    dirty = true;
    if (rid != null)
      throw new IllegalStateException("Cannot update a record in a custom bucket");
    remoteDatabase.command("sql", "insert into " + getTypeName() + " bucket " + bucketName + " content " + toJSON());
    dirty = false;
    return this;
  }

Steps to reproduce

db is a RemoteDatabase

  db.transaction( () -> {
    MutableVertex elon = db.newVertex("User", "name", "Elon", "lastName", "Musk").save();
    MutableVertex steve = db.newVertex("User", "name", "Steve", "lastName", "Jobs").save();
    MutableEdge lEdge = elon.newEdge("IsFriendOf", steve, true, "since", 2010);
    lEdge.save("MyAwesomeBucket");
  });
@lvca lvca self-assigned this Apr 30, 2024
@lvca lvca added the bug Something isn't working label Apr 30, 2024
@lvca lvca added this to the 24.5.1 milestone Apr 30, 2024
@lvca
Copy link
Contributor

lvca commented Apr 30, 2024

@rmsloan you're absolutely right. WDYT on providing a PR?

@rmsloan
Copy link
Author

rmsloan commented Apr 30, 2024

For starters, I would have done this...

  @Override
  public MutableEdge save(final String bucketName) {
    dirty = true;
    if (rid != null) {
      // UPDATE
      if (rid.getBucketId() != remoteDatabase.getSchema().getBucketByName(bucketName).getFileId())
        throw new IllegalStateException("Cannot update a record in a custom bucket");

      // Haven't tested this syntax as I noticed something else that would have got me before this...
      remoteDatabase.command("sql", "update " + rid + " bucket " + bucketName + " set content " + toJSON());
    } else {
      // INSERT
      remoteDatabase.command("sql", "insert into " + getTypeName() + " bucket " + bucketName + " content " + toJSON());
    }
    dirty = false;
    return this;
  }

But as mentioned in the above comment...I soon realized...

  • RemoteSchema.getBucketByName(final String name) is Deprecated.

Ok, sure not the end of the world, say I use it anyway, as there are no comments as to why it was Deprecated.
Perhaps it was accidentally set to Deprecated (fingers crossed)

The problem now is RemoteBucket

  • Everything in there throws an UnsupportedOperationException

So before any attempt at a PR...

Is RemoteBucket bucketed ;-) for future feature work?
Or
Was this intentional and RemoteBucket can't be supported?

@lvca lvca modified the milestones: 24.5.1, 24.6.1 May 24, 2024
@lvca lvca modified the milestones: 24.6.1, 24.8.1 Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants