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

Enable testColumnName in TestCassandraDistributedQueries #3623

Merged
merged 2 commits into from
May 6, 2020

Conversation

ebyhr
Copy link
Member

@ebyhr ebyhr commented May 5, 2020

This requires changes of AbstractTestDistributedQueries.

  • Cassandra allows only 48 characters for column names
  • Column name id is automatically generated in Cassandra connector

(Ongoing Oracle PR's column length limitation is 30 due to the image version)

@cla-bot cla-bot bot added the cla-signed label May 5, 2020
@ebyhr ebyhr force-pushed the cassandra-name-test branch 3 times, most recently from ac4d3f3 to 5ca95a9 Compare May 5, 2020 03:21
Copy link
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

% comment

{
String randomSuffix = Long.toString(abs(random.nextLong()), MAX_RADIX);
return randomSuffix.substring(0, min(RANDOM_SUFFIX_LENGTH, randomSuffix.length()));
return randomSuffix.substring(0, min(maxLength, randomSuffix.length()));
Copy link
Member

Choose a reason for hiding this comment

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

can we simply change the default here? 12 was quite big.

@@ -289,7 +290,7 @@ private CassandraOutputTableHandle createTable(ConnectorTableMetadata tableMetad
for (ColumnMetadata column : tableMetadata.getColumns()) {
columnNames.add(column.getName());
columnTypes.add(column.getType());
columnExtra.add(new ExtraColumnMetadata(column.getName(), column.isHidden()));
columnExtra.add(new ExtraColumnMetadata(escapeSingleQuote(column.getName()), column.isHidden()));
Copy link
Member

Choose a reason for hiding this comment

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

Escaping should be done when we construct a CQL query

{
return '"' + identifier + '"';
return identifier.replace("'", "''");
Copy link
Member

Choose a reason for hiding this comment

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

I am concerned about escape function that doesn't quote.
Generally, escaping and quoting should be done at the same time, so they should be done
at once, in one function.

@@ -94,6 +93,11 @@ protected boolean supportsArrays()
return true;
}

protected String randomTableSuffix()
Copy link
Member

Choose a reason for hiding this comment

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

@@ -27,7 +27,7 @@
implements AutoCloseable
{
private static final SecureRandom random = new SecureRandom();
private static final int RANDOM_SUFFIX_LENGTH = 12;
private static final int RANDOM_SUFFIX_LENGTH = 6;
Copy link
Member

Choose a reason for hiding this comment

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

about 2^31 options, but since we generate them a lot.... can this be eg 8?

we can shorted the table name's base a bit maybe?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, only 0startingwithdigit is the problem. Let me rename to 0startwithdigit. and drop the commit to shorten.

@@ -1180,7 +1180,7 @@ private void testColumnName(String columnName, boolean delimited)

try {
// TODO test with both CTAS *and* CREATE TABLE + INSERT, since they use different connector API methods.
assertUpdate("CREATE TABLE " + tableName + "(id varchar, " + nameInSql + " varchar)");
assertUpdate("CREATE TABLE " + tableName + "(key varchar, " + nameInSql + " varchar)");
Copy link
Member

Choose a reason for hiding this comment

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

Rename id column to key in testColumnName

in the commit message maybe mention that id has a special meaning in Cassandra.

@@ -150,16 +150,6 @@ protected TestTable createTableWithDefaultColumns()
throw new SkipException("Cassandra connector does not support column default values");
}

@Override
public void testColumnName(String columnName)
Copy link
Member

Choose a reason for hiding this comment

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

Enable testColumnName in TestCassandraDistributedQueries

Consider squashing this commit with Use Metadata.quote in CassandraCqlUtils -- if this is what fixes Cassandra and makes this test pass now.

ebyhr added 2 commits May 5, 2020 20:31
The id column name is reserved in Cassandra connector.
Replace 0startingwithdigit with 0startwithdigit to avoid
column name length limitation (48) in Cassandra.
To use escaping logic of Metadata.quote method.
Additionally, escape single quotation for table comment
and enable testColumnName in Cassandra.
@ebyhr
Copy link
Member Author

ebyhr commented May 6, 2020

CI failure: #3635

@ebyhr ebyhr merged commit fdbeea3 into trinodb:master May 6, 2020
@ebyhr ebyhr deleted the cassandra-name-test branch May 6, 2020 04:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants