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

Add TestMemSqlDistributedQueries and implement gaps #5495

Merged
merged 5 commits into from
Oct 22, 2020
Merged

Add TestMemSqlDistributedQueries and implement gaps #5495

merged 5 commits into from
Oct 22, 2020

Conversation

hashhar
Copy link
Member

@hashhar hashhar commented Oct 9, 2020

Fixes #5369.

@cla-bot cla-bot bot added the cla-signed label Oct 9, 2020
@hashhar hashhar requested a review from findepi October 9, 2020 15:29
@findepi
Copy link
Member

findepi commented Oct 9, 2020

i merged type mapping test, please rebase.

@hashhar
Copy link
Member Author

hashhar commented Oct 10, 2020

Seems like MemSql tests were skipped. https://github.com/prestosql/presto/runs/1231980668?check_suite_focus=true#step:5:1
cc: @sopel39

Will rebase.

Copy link
Member Author

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

I had some questions and have added them as comments.

@Override
public void testLargeIn()
{
// TODO Caused by: java.sql.SQLException: Thread stack overrun: Used: 1048713 of a 1048576 stack. Use 'memsqld --thread_stack=#' to specify a bigger stack if needed.
Copy link
Member Author

Choose a reason for hiding this comment

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

I opted to skip this test instead of modifying the test container since I don't think there's any point in making this test pass if it will actually fail in practice for most people.

@@ -95,7 +106,8 @@ private static DataTypeTest singlePrecisionFloatingPointTests(DataType<Float> fl
// we are not testing Nan/-Infinity/+Infinity as those are not supported by MemSQL
return DataTypeTest.create()
.addRoundTrip(floatType, 3.14f)
// .addRoundTrip(floatType, 3.1415927f) // Overeagerly rounded by MemSQL to 3.14159 TODO
// TODO Overeagerly rounded by MemSQL to 3.14159
Copy link
Member Author

Choose a reason for hiding this comment

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

This seems to be due to MemSQL's FLOAT type having low precision rather than rounding errors.

{
jsonTestCases(jsonDataType(value -> "JSON " + formatStringLiteral(value)))
.execute(getQueryRunner(), prestoCreateAsSelect("presto_test_json"));
// TODO MemSQL doesn't support CAST to JSON but accepts string literals as JSON values
Copy link
Member Author

Choose a reason for hiding this comment

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

CAST to JSON doesn't exist. There's a TO_JSON function but that parses strings into JSON values. ie. strings get converted into double quoted JSON strings. Passing strings that are valid JSON seem to get parsed into JSON during INSERT.

Copy link
Member

Choose a reason for hiding this comment

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

Having comment is good, but this shouldn't be a TODO, because that's nor our problem.

@hashhar
Copy link
Member Author

hashhar commented Oct 12, 2020

@findepi Rebased on top of your PR. All tests in io.prestosql.plugin.memsql package are passing. Tested locally.

This PR will fix the following:

#5369
#5454
#5453

Copy link
Member

@findepi findepi left a comment

Choose a reason for hiding this comment

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

early feedback

@hashhar
Copy link
Member Author

hashhar commented Oct 13, 2020

@findepi AC.

@hashhar hashhar requested a review from sopel39 October 14, 2020 08:01
switch (typeHandle.getJdbcType()) {
case Types.VARCHAR:
VarcharType varcharType = (columnSize <= VarcharType.MAX_LENGTH) ? createVarcharType(columnSize) : createUnboundedVarcharType();
// Remote database can be case insensitive.
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 know if it is and react accordingly?

Copy link
Member Author

Choose a reason for hiding this comment

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

We can fire a query to test the easy cases (eg A = a) but it is possible for such checks to pass for ASCII characters but fail for unicode characters (eg. S = ß) depending on the collation used by the remote database.

I'm working on adding a smoke test to at-least verify that such-cases are caught in tests.

public PreparedStatement getPreparedStatement(Connection connection, String sql)
throws SQLException
{
return connection.prepareStatement(sql);
Copy link
Member

Choose a reason for hiding this comment

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

Override seems redundant?

Comment on lines 203 to 263
else if (varcharType.getBoundedLength() <= 65535) {
dataType = "text";
}
else if (varcharType.getBoundedLength() <= 16777215) {
dataType = "mediumtext";
Copy link
Member

Choose a reason for hiding this comment

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

define constatns for these numbers, like you did for MEMSQL_VARCHAR_MAX_LENGTH

return WriteMapping.sliceMapping(dataType, varcharWriteFunction());
}
if (VARBINARY.equals(type)) {
return WriteMapping.sliceMapping("mediumblob", varbinaryWriteFunction());
Copy link
Member

Choose a reason for hiding this comment

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

medium or longblob?

return WriteMapping.longMapping("datetime", timestampWriteFunction(TIMESTAMP_MILLIS));
}

return super.toWriteMapping(session, type);
Copy link
Member

Choose a reason for hiding this comment

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

// TODO add explicit mappings

}

@Override
public void renameTable(JdbcIdentity identity, JdbcTableHandle handle, SchemaTableName newTableName)
Copy link
Member

Choose a reason for hiding this comment

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

move this above renameColumn (ideally, keep order as in superclass)

return dataType("date", DATE, toLiteral, identity());
}

private static DataType<String> memSqlJsonDataType(Function<String, String> toLiteral)
Copy link
Member

Choose a reason for hiding this comment

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

please do the rename jsonDataType -> memSqlJsonDataType
in the commit which intro'd the function

return Optional.empty();
}
return super.filterColumnNameTestData(columnName);
return nullToEmpty(exception.getMessage()).matches(".*(Incorrect column name).*");
Copy link
Member

Choose a reason for hiding this comment

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

braces in the pattern are redundant.

public void createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata)
{
// MemSQL doesn't accept `some;column` in CTAS statements - so we explicitly block it and throw a proper error message
// TODO figure out how to quote ; in column names
Copy link
Member

Choose a reason for hiding this comment

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

let's remove the TODO. I wouldn't spent time on it
same for copyTableSchema

Comment on lines 106 to 107
.findAny();
if (illegalColumnName.isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

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

you can get away without an assigment

.findAny()
.ifPresent(illegalColumnName -> {
    throw ...

same in the other method

{
// MemSQL doesn't accept `some;column` in CTAS statements - so we explicitly block it and throw a proper error message
// TODO figure out how to quote ; in column names
Optional<String> illegalColumnName = columnNames.stream().filter(s -> s.contains(";")).findAny();
Copy link
Member

Choose a reason for hiding this comment

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

break the line before .filter and .findAny

@hashhar
Copy link
Member Author

hashhar commented Oct 22, 2020

@findepi AC.

@findepi findepi merged commit 79e5ec8 into trinodb:master Oct 22, 2020
@findepi
Copy link
Member

findepi commented Oct 22, 2020

Thanks!

@findepi findepi mentioned this pull request Oct 22, 2020
7 tasks
@findepi findepi added this to the 345 milestone Oct 22, 2020
@hashhar hashhar deleted the hashhar/memsql-distributed-tests branch October 23, 2020 04:41
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.

Implement AbstractTestDistributedQueries for MemSQL connector
3 participants