Skip to content

Convert TestMemSqlTypeMapping to use SqlDataTypeTest#7202

Closed
Atema wants to merge 7 commits intotrinodb:masterfrom
Atema:convert-testmemsqltypemapping
Closed

Convert TestMemSqlTypeMapping to use SqlDataTypeTest#7202
Atema wants to merge 7 commits intotrinodb:masterfrom
Atema:convert-testmemsqltypemapping

Conversation

@Atema
Copy link
Copy Markdown
Contributor

@Atema Atema commented Mar 7, 2021

Hej, we* did our best to resolve issue #6393 by converting the test in class testMemSqlTypeMapping to use SqlDataTypeTest instead of DataTypeTest.

We have succeeded on most methods, with one exception being the Real type (both in testBasicType() and testFloat(), which resulted in the exception below. I don't know where exactly it stems from, but I believe it may be worth further investigation.

[ERROR]   TestMemSqlTypeMapping.testBasicTypes:112 [Rows]
Expecting:
  <>
to contain exactly in any order:
  <[(found)]>
but could not find the following elements:
  <(found)>

[ERROR]   TestMemSqlTypeMapping.testFloat:119 [Rows]
Expecting:
  <>
to contain exactly in any order:
  <[(found)]>
but could not find the following elements:
  <(found)>

Let me know if you have any questions/comments.

* We are a group of five students (me, @caillouc, @hallon-heyman, @linnea-bonnevier, and @aoutir) who worked on this issue as a university assignment. All of us have sent in the CLA, and the ownership of the contributed code is personal.

Fixes #6393

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 7, 2021

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@trino.io. For more information, see https://github.com/trinodb/cla.

@Atema Atema requested a review from findepi March 7, 2021 22:17
@findepi
Copy link
Copy Markdown
Member

findepi commented Mar 9, 2021

Very cool!

I guess your intention is to keep those contributions somewhat separate (instead of squashing into single commit, with Co-Authored-By).

You can also prefer to put up 5 separate PRs. Of course they would be conflicts, so we would need to review them one by one.

Or, I review this as is, let me know your preference.

@Atema
Copy link
Copy Markdown
Contributor Author

Atema commented Mar 9, 2021

All of us are fine with reviewing as a whole, and squashing the commits together!

@findepi findepi requested a review from hashhar March 9, 2021 11:35
@findepi findepi changed the title Convert TestMemSqlTypeMapping to use SqlDataTypeTest (#6393) Convert TestMemSqlTypeMapping to use SqlDataTypeTest Mar 9, 2021
@findepi
Copy link
Copy Markdown
Member

findepi commented Mar 10, 2021

@martint can you please help with the CLA verification here?

Copy link
Copy Markdown
Member

@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.

Looks good to me. Requested a few changes in decimalTests (test for NULL is missing) and rest of it are editorial comments.

The SqlDataTypeTest failure with REAL seems concerning but it's not the tests fault, most likely some issue with toWriteMapping used for REAL (or MemSQL itself).

.addRoundTrip(decimalDataType(38, 0), new BigDecimal("27182818284590452353602874713526624977"))
.addRoundTrip(decimalDataType(38, 0), new BigDecimal("-27182818284590452353602874713526624977"));
return SqlDataTypeTest.create()
.addRoundTrip("decimal(3, 0)", "CAST('193' AS decimal(3, 0))", createDecimalType(3, 0), "CAST('193' AS decimal(3, 0))")
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.

Can you add a test where we try writing NULL into a decimal(3, 0) and another where we write NULL into a decimal(38, 0)?

.addRoundTrip("char(1)", "'a'", createCharType(1), "CAST('a' AS char(1))")
.addRoundTrip("char(8)", "'abc'", createCharType(8), "CAST('abc' AS char(8))")
.addRoundTrip("char(8)", "'12345678'", createCharType(8), "CAST('12345678' AS char(8))")
.addRoundTrip("char(255)", String.format("'%s'", "a".repeat(255)), createCharType(255), String.format("CAST('%s' AS char(255))", "a".repeat(255)));
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.

nit: Add static import for String.format.

.addRoundTrip(varcharDataType(20000, CHARACTER_SET_UTF8), sampleUnicodeText)
String sampleUnicodeText = "'\u653b\u6bbb\u6a5f\u52d5\u968a'";
SqlDataTypeTest.create()
.addRoundTrip("tinytext " + CHARACTER_SET_UTF8, sampleUnicodeText, createVarcharType(255), "CAST(" + sampleUnicodeText + "AS varchar(255))")
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.

nit: missing whitespace before AS inside quotes.

Suggested change
.addRoundTrip("tinytext " + CHARACTER_SET_UTF8, sampleUnicodeText, createVarcharType(255), "CAST(" + sampleUnicodeText + "AS varchar(255))")
.addRoundTrip("tinytext " + CHARACTER_SET_UTF8, sampleUnicodeText, createVarcharType(255), "CAST(" + sampleUnicodeText + " AS varchar(255))")

.addRoundTrip(dateDataType, dateOfLocalTimeChangeForwardAtMidnightInJvmZone)
.addRoundTrip(dateDataType, dateOfLocalTimeChangeForwardAtMidnightInSomeZone)
.addRoundTrip(dateDataType, dateOfLocalTimeChangeBackwardAtMidnightInSomeZone);
for (String timeZoneId : ImmutableList.of(UTC_KEY.getId(), jvmZone.getId(), someZone.getId())) {
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.

This loop works but for future reference take a look at PostgresqlTypeMappingTest to see how it uses DataProvider. The benefit is that if a test fails you can know exactly which timezone it failed for rather than having to guess which iteration of the loop it failed in.

No change requested since it's pre-existing. Can be a follow up.

return new CreateAndInsertDataSetup(memSqlServer::execute, tableNamePrefix);
}

private static DataType<LocalDate> memSqlDateDataType(Function<LocalDate, String> toLiteral)
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.

Thank you for cleaning up.

.addRoundTrip("smallint", "32456", SMALLINT, "SMALLINT '32456'")
.addRoundTrip("tinyint", "125", TINYINT, "TINYINT '125'")
.addRoundTrip("double", "123.45", DOUBLE, "DOUBLE '123.45'")
// TODO: Real doesn't work with SqlDataTypeTest (see below)
Copy link
Copy Markdown
Member

@hashhar hashhar Mar 11, 2021

Choose a reason for hiding this comment

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

Suggested change
// TODO: Real doesn't work with SqlDataTypeTest (see below)
// TODO: fails in SqlDataTypeTest#verifyPredicate

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.

Same change in the comment in testFloat too.

.addRoundTrip(memSqlFloatDataType(), null)
.execute(getQueryRunner(), memSqlCreateAndInsert("tpch.memsql_test_float"));

// TODO: Changing to SqlDataTypeTest with Real does not work: assertion in SqlDataTypeTest.verifyPredicate() fails
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.

Remove the commented code. And move the TODO to the start of the function.

- Remove commented code & change comment
- Add whitespae before AS
- Add static String.format
- Add NULL cases for decimal
@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 13, 2021

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@trino.io. For more information, see https://github.com/trinodb/cla.

@Atema
Copy link
Copy Markdown
Contributor Author

Atema commented Mar 13, 2021

@hashhar Thanks for the comments. I've pushed the requested changes

@Atema Atema requested a review from hashhar March 13, 2021 11:32
Copy link
Copy Markdown
Member

@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.

Looks good to be merged % the REAL data-type issue with verifyPredicate.

The issue with REAL type mapping is pre-existing so we can tackle that in a follow-up IMO.

.addRoundTrip(varcharDataType(sampleUnicodeText.length(), CHARACTER_SET_UTF8), sampleUnicodeText)
.addRoundTrip(varcharDataType(32, CHARACTER_SET_UTF8), sampleUnicodeText)
.addRoundTrip(varcharDataType(20000, CHARACTER_SET_UTF8), sampleUnicodeText)
String sampleUnicodeText = "'\u653b\u6bbb\u6a5f\u52d5\u968a'";
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.

nit: rename it to sampleUnicodeLiteral since the ' are not actually part of the tested text.

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Mar 13, 2021

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@trino.io. For more information, see https://github.com/trinodb/cla.

@findepi
Copy link
Copy Markdown
Member

findepi commented Mar 15, 2021

@martint can you please help with the CLA verification here?

@findepi
Copy link
Copy Markdown
Member

findepi commented Mar 23, 2021

@martint can you please help with the CLA here?

@ebyhr
Copy link
Copy Markdown
Member

ebyhr commented Sep 25, 2021

@cla-bot check

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Sep 25, 2021

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@trino.io. For more information, see https://github.com/trinodb/cla.

@cla-bot
Copy link
Copy Markdown

cla-bot bot commented Sep 25, 2021

The cla-bot has been summoned, and re-checked this pull request!

@ebyhr
Copy link
Copy Markdown
Member

ebyhr commented Nov 19, 2021

The SqlDataTypeTest failure with REAL seems concerning but it's not the tests fault, most likely some issue with toWriteMapping used for REAL (or MemSQL itself).

Confirmed that it's product bug in MySQL and MemSQL connectors. Filed #9998

@ebyhr
Copy link
Copy Markdown
Member

ebyhr commented Dec 28, 2021

Merged this commit in #10296. Thanks!

@ebyhr ebyhr closed this Dec 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Convert TestMemSqlTypeMapping to use SqlDataTypeTest

9 participants