Skip to content

feat: implement ALTER TYPE oldName NAME newName operation - #1501

Merged
lvca merged 8 commits into
ArcadeData:mainfrom
daffodilistic:dev-daffodilistic
Oct 22, 2024
Merged

lvca merged 8 commits into
ArcadeData:mainfrom
daffodilistic:dev-daffodilistic

Conversation

@daffodilistic

Copy link
Copy Markdown
Contributor

What does this PR do?

Implement ALTER TYPE oldName NAME newName

Motivation

It's listed in the documentation page, but its not working in the database

Related issues

N/A

Additional Notes

N/A

Checklist

  • I have run the build using mvn clean package command
  • My unit tests cover both failure and success scenarios

@lvca
lvca self-requested a review March 6, 2024 15:06
@lvca lvca added the enhancement New feature or request label Mar 6, 2024

@lvca lvca left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR! You're right, we never completed the rename of the type. Have you already tested it? We'd need some test cases too. Let me know if you can do it, or we can find somebody can help with that.

@daffodilistic

Copy link
Copy Markdown
Contributor Author

Thanks for this PR! You're right, we never completed the rename of the type. Have you already tested it? We'd need some test cases too. Let me know if you can do it, or we can find somebody can help with that.

I'm not sure where the tests are located (e2e folder?). Some guidance would be good :)
Also documentation update on the underlying mechanics has to be done too.

@lvca

lvca commented Mar 9, 2024

Copy link
Copy Markdown
Member

Also, in the case of indexes, we have to rename them as well. Not fundamental, because they are linked in the schema.json so it would still work with the old names.

The only important thing missing is, at least, one test case to avoid regression and to test that this change works.

@lvca
lvca self-requested a review March 9, 2024 00:20
public void sqlAlterTypeName() {
database.command("sql", "CREATE VERTEX TYPE Mpv");
database.command("sql", "ALTER TYPE Mpv NAME Sedan");
Assertions.assertNotNull(database.getSchema().getType("Sedan"));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be wonderful if you can also test the previous Mpv type doesn't exist anymore


@Test
public void sqlAlterTypeName() {
database.command("sql", "CREATE VERTEX TYPE Mpv");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please create a property with an index, so see if everything works as expected? Thanks in advance @daffodilistic !

database.command("sql", "CREATE INDEX ON Sedan(engine_number) UNIQUE");
database.begin();
// insert a random record
database.getSchema().getType("Sedan").newRecord().set("engine_number", "123").save();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change. I meant creating an index on the old type and see what happens when you rename it. Is the index still working or does it need to be renamed too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do!

@daffodilistic

Copy link
Copy Markdown
Contributor Author

Hi,

I'm getting an error with the latest changes to the test case. It seems like there's an issue with existing documents of the type with a custom index, before being renamed:

[ERROR] com.arcadedb.query.sql.executor.AlterTypeExecutionTest.sqlAlterTypeName -- Time elapsed: 0.312 s <<< ERROR!
java.lang.ArithmeticException: / by zero
        at com.arcadedb.schema.LocalSchema.copyType(LocalSchema.java:379)
        at com.arcadedb.query.sql.parser.AlterTypeStatement.executeDDL(AlterTypeStatement.java:120)
        at com.arcadedb.query.sql.executor.DDLExecutionPlan.executeInternal(DDLExecutionPlan.java:60)
        at com.arcadedb.query.sql.parser.DDLStatement.execute(DDLStatement.java:49)
        at com.arcadedb.query.sql.parser.Statement.execute(Statement.java:65)
        at com.arcadedb.query.sql.SQLQueryEngine.command(SQLQueryEngine.java:113)
        at com.arcadedb.database.LocalDatabase.command(LocalDatabase.java:1327)
        at com.arcadedb.query.sql.executor.AlterTypeExecutionTest.sqlAlterTypeName(AlterTypeExecutionTest.java:129)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)

Not quite sure what to make of it. I'll try syncing my branch with upstream master first to see if any bugfixes resolved it

lvca added a commit that referenced this pull request Oct 21, 2024
@lvca

lvca commented Oct 21, 2024

Copy link
Copy Markdown
Member

That issue should be fixed now in main.

@daffodilistic

Copy link
Copy Markdown
Contributor Author

Should this PR be closed and merged, or a new one created? The test passed with the latest version on main branch

@lvca lvca added this to the 24.11.1 milestone Oct 22, 2024
@lvca

lvca commented Oct 22, 2024

Copy link
Copy Markdown
Member

That works, thanks!

@lvca lvca closed this Oct 22, 2024
@lvca lvca reopened this Oct 22, 2024
@lvca
lvca merged commit 22e08d2 into ArcadeData:main Oct 22, 2024
tae898 pushed a commit to humemai/arcadedb-embedded-python that referenced this pull request Jun 28, 2026
tae898 pushed a commit to humemai/arcadedb-embedded-python that referenced this pull request Jun 28, 2026
…#1501)

* feat: implement ALTER TYPE oldName NAME newName operation

* fix: whoops, forgot to break out of switch-case

* fix: remove extraneous check for type existence before copy operation

* test: add test for ALTER TYPE oldName NAME newName

* test: add test to confirm previous type doesn't exist when renaming types

* test: add test for indexing on renamed types

* test: add property and index on old type, before renaming
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants