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

Fix CreateTableOperation identifier issue, add several table ITs. #1348

Merged
merged 5 commits into from
Aug 20, 2024

Conversation

Yuqi-Du
Copy link
Contributor

@Yuqi-Du Yuqi-Du commented Aug 19, 2024

So in previous implementation of CreateTableOperation,

 public static CreateTableStart createTable(@Nullable String keyspace, @NonNull String tableName) {
        return createTable(keyspace == null ? null : CqlIdentifier.fromCql(keyspace), CqlIdentifier.fromCql(tableName));
    }

we are using createTable method from CQL Driver, which uses fromCql method to resolve identifier. This is a problematic, because if things are not quoted, driver will make them case-insensitive, to lower case.

e.g.
keyspace in DB: Yuqi_Keyspace
because of this string is not quoted, then CQL Driver decides to convert it to yuqi_keyspace, which does not exist.

So to be consistent with what we did for collection, I just added quote for keyspace and tableName in createTableCommand.

Enable table feature in test resource

add AbstractTableIntegrationTestBase, add few ITs for table.

Checklist

  • Changes manually tested
  • Automated Tests added/updated
  • Documentation added/updated
  • CLA Signed: DataStax CLA

@Yuqi-Du Yuqi-Du requested a review from a team as a code owner August 19, 2024 23:29

CreateTableStart create =
createTable(commandContext.schemaObject().name.keyspace(), tableName).ifNotExists();
String keyspaceQuoted = "\"%s\"".formatted(commandContext.schemaObject().name.keyspace());
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we not have helper method(s) in CqlIdentifier to handle quoting? Instead of manually surrounding with double quotes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did not find any method in driver that gives us CreateTableStart back and handle quote automatically.

    @NonNull
    public static CreateTableStart createTable(@NonNull String tableName) {
        return createTable(CqlIdentifier.fromCql(tableName));
    }

    @NonNull
    public static CreateTableStart createTable(@Nullable String keyspace, @NonNull String tableName) {
        return createTable(keyspace == null ? null : CqlIdentifier.fromCql(keyspace), CqlIdentifier.fromCql(tableName));
    }

I think they design this by the tableName/keyspace as cql representation. Which means if we want quoted string, we need to add by ourselves.

Copy link
Contributor

Choose a reason for hiding this comment

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

That seems very odd -- there's nothing that takes CqlIdentifier? We should pass

CqlIdentifier.fromInternal(tableName)

to ensure quoting is used if (and only if) necessary. But I agree, if only String is allowed then we must quote.

@tatu-at-datastax
Copy link
Contributor

@Yuqi-Du let's get this merged to make it easier to add other Table ITs!

@Yuqi-Du Yuqi-Du merged commit f41245b into main Aug 20, 2024
3 checks passed
@Yuqi-Du Yuqi-Du deleted the add-table-IT branch August 20, 2024 23:24
createTable(commandContext.schemaObject().name.keyspace(), tableName).ifNotExists();
CqlIdentifier keyspaceIdentifier =
CqlIdentifier.fromInternal(commandContext.schemaObject().name.keyspace());
CqlIdentifier tableIdentifier = CqlIdentifier.fromInternal(tableName);
Copy link
Contributor

Choose a reason for hiding this comment

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

Ok good!

Copy link
Collaborator

@vkarpov15 vkarpov15 left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants