Skip to content

Fix mysql8 signedness decoding #264

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

Merged
merged 2 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
<version>8.0.15</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,34 @@ public TableMapEventData deserialize(ByteArrayInputStream inputStream) throws IO
if (metadataLength > 0) {
metadata = metadataDeserializer.deserialize(
new ByteArrayInputStream(inputStream.read(metadataLength)),
numberOfColumns
numericColumnCount(eventData.getColumnTypes())
);
}
eventData.setEventMetadata(metadata);
return eventData;
}

private int numericColumnCount(byte[] types) {
int count = 0;
for (int i = 0; i < types.length; i++) {
switch (ColumnType.byCode(types[i] & 0xff)) {
case TINY:
case SHORT:
case INT24:
case LONG:
case LONGLONG:
case NEWDECIMAL:
case FLOAT:
case DOUBLE:
count++;
break;
default:
break;
}
}
return count;
}

private int[] readMetadata(ByteArrayInputStream inputStream, byte[] columnTypes) throws IOException {
int[] metadata = new int[columnTypes.length];
for (int i = 0; i < columnTypes.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
*/
public class TableMapEventMetadataDeserializer {

public TableMapEventMetadata deserialize(ByteArrayInputStream inputStream, int numberOfColumns) throws IOException {
public TableMapEventMetadata deserialize(ByteArrayInputStream inputStream, int nIntColumns) throws IOException {
int remainingBytes = inputStream.available();
if (remainingBytes <= 0) {
return null;
Expand All @@ -49,7 +49,7 @@ public TableMapEventMetadata deserialize(ByteArrayInputStream inputStream, int n

switch (fieldType) {
case SIGNEDNESS:
result.setSignedness(readSignedness(inputStream, numberOfColumns));
result.setSignedness(readSignedness(inputStream, nIntColumns));
break;
case DEFAULT_CHARSET:
result.setDefaultCharset(readDefaultCharset(inputStream));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,22 @@ public void execute(Statement statement) throws SQLException {
}
}

@Test
public void testMysql8TableMetadata() throws Exception {
master.execute("create table test_metameta ( " +
"a date, b date, c date, d date, e date, f date, g date, " +
"h date, i date, j int)");
master.execute("insert into test_metameta set j = 5");

final BinaryLogClient binaryLogClient = new BinaryLogClient(
master.hostname, master.port, master.username, master.password
);
binaryLogClient.registerEventListener(eventListener);
binaryLogClient.connect(DEFAULT_TIMEOUT);

eventListener.waitFor(WriteRowsEventData.class, 1, DEFAULT_TIMEOUT);
}

@AfterMethod
public void afterEachTest() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
Expand Down