diff --git a/src/main/antlr4/imports/column_definitions.g4 b/src/main/antlr4/imports/column_definitions.g4 index 735635502..e859850f8 100644 --- a/src/main/antlr4/imports/column_definitions.g4 +++ b/src/main/antlr4/imports/column_definitions.g4 @@ -20,11 +20,12 @@ data_type: // from http://dev.mysql.com/doc/refman/5.1/en/create-table.html generic_type: // types from which we're going to ignore any flags/length - col_type=(BIT | BINARY) length? - | col_type=(DATE | TIME | TIMESTAMP | DATETIME | YEAR | TINYBLOB | MEDIUMBLOB | LONGBLOB | BLOB ) + col_type=(BIT | BINARY | YEAR) length? + | col_type=(DATE | TIME | TIMESTAMP | DATETIME | TINYBLOB | MEDIUMBLOB | LONGBLOB | BLOB | BOOLEAN | BOOL ) | col_type=VARBINARY length ; + signed_type: // we need the UNSIGNED flag here col_type=(TINYINT | INT1 | SMALLINT | INT2 | MEDIUMINT | INT3 | INT | INTEGER | INT4 | BIGINT | INT8 ) length? diff --git a/src/main/antlr4/imports/generate_tokens.rb b/src/main/antlr4/imports/generate_tokens.rb index 2e6934db4..7df77d75c 100644 --- a/src/main/antlr4/imports/generate_tokens.rb +++ b/src/main/antlr4/imports/generate_tokens.rb @@ -158,6 +158,9 @@ NULL NO ACTION + +BOOL +BOOLEAN ) tokens_allowed_in_names = [] diff --git a/src/main/antlr4/imports/mysql_literal_tokens.g4 b/src/main/antlr4/imports/mysql_literal_tokens.g4 index ca6bb8b9c..ffec76c4d 100644 --- a/src/main/antlr4/imports/mysql_literal_tokens.g4 +++ b/src/main/antlr4/imports/mysql_literal_tokens.g4 @@ -1,6 +1,6 @@ grammar mysql_literal_tokens; -tokens_available_for_names: (ACTION | AFTER | AUTO_INCREMENT | AVG_ROW_LENGTH | BEGIN | BIT | BTREE | CHARSET | CHECKSUM | COLUMN_FORMAT | COMMENT | COMPACT | COMPRESSED | CONNECTION | DATA | DATE | DATETIME | DELAY_KEY_WRITE | DIRECTORY | DISABLE | DISK | DYNAMIC | ENABLE | ENGINE | ENUM | FIRST | FIXED | FULL | HASH | INSERT_METHOD | KEY_BLOCK_SIZE | LAST | MAX_ROWS | MEMORY | MIN_ROWS | MODIFY | NO | OFFLINE | ONLINE | PACK_KEYS | PARSER | PARTIAL | PASSWORD | REDUNDANT | ROW_FORMAT | SIMPLE | STORAGE | TABLESPACE | TEMPORARY | TEXT | TIME | TIMESTAMP | YEAR); +tokens_available_for_names: (ACTION | AFTER | AUTO_INCREMENT | AVG_ROW_LENGTH | BEGIN | BIT | BOOL | BOOLEAN | BTREE | CHARSET | CHECKSUM | COLUMN_FORMAT | COMMENT | COMPACT | COMPRESSED | CONNECTION | DATA | DATE | DATETIME | DELAY_KEY_WRITE | DIRECTORY | DISABLE | DISK | DYNAMIC | ENABLE | ENGINE | ENUM | FIRST | FIXED | FULL | HASH | INSERT_METHOD | KEY_BLOCK_SIZE | LAST | MAX_ROWS | MEMORY | MIN_ROWS | MODIFY | NO | OFFLINE | ONLINE | PACK_KEYS | PARSER | PARTIAL | PASSWORD | REDUNDANT | ROW_FORMAT | SIMPLE | STORAGE | TABLESPACE | TEMPORARY | TEXT | TIME | TIMESTAMP | YEAR); INT1: I N T '1'; @@ -21,6 +21,8 @@ BIGINT: B I G I N T; BINARY: B I N A R Y; BIT: B I T; BLOB: B L O B; +BOOL: B O O L; +BOOLEAN: B O O L E A N; BTREE: B T R E E; BY: B Y; CASCADE: C A S C A D E; diff --git a/src/main/java/com/zendesk/maxwell/schema/columndef/ColumnDef.java b/src/main/java/com/zendesk/maxwell/schema/columndef/ColumnDef.java index c052be882..381261b01 100644 --- a/src/main/java/com/zendesk/maxwell/schema/columndef/ColumnDef.java +++ b/src/main/java/com/zendesk/maxwell/schema/columndef/ColumnDef.java @@ -32,6 +32,10 @@ public static ColumnDef build(String tableName, String name, String encoding, St type = unalias_type(type); switch(type) { + case "bool": + case "boolean": + type = "tinyint"; + // fallthrough case "tinyint": case "smallint": case "mediumint": @@ -51,6 +55,9 @@ public static ColumnDef build(String tableName, String name, String encoding, St case "mediumblob": case "longblob": return new StringColumnDef(tableName, name, type, pos, "binary"); + case "real": + type = "double"; + // fall through case "float": case "double": return new FloatColumnDef(tableName, name, type, pos); diff --git a/src/main/java/com/zendesk/maxwell/schema/ddl/SchemaChange.java b/src/main/java/com/zendesk/maxwell/schema/ddl/SchemaChange.java index 8a0c8b7fc..c10d4044e 100644 --- a/src/main/java/com/zendesk/maxwell/schema/ddl/SchemaChange.java +++ b/src/main/java/com/zendesk/maxwell/schema/ddl/SchemaChange.java @@ -35,6 +35,8 @@ public abstract class SchemaChange { SQL_BLACKLIST.add(Pattern.compile("^ANALYZE\\s+TABLE", Pattern.CASE_INSENSITIVE)); SQL_BLACKLIST.add(Pattern.compile("^SET\\s+PASSWORD", Pattern.CASE_INSENSITIVE)); SQL_BLACKLIST.add(Pattern.compile("^(CREATE|DROP|RENAME)\\s+USER", Pattern.CASE_INSENSITIVE)); + + SQL_BLACKLIST.add(Pattern.compile("^TRUNCATE\\s+TABLE", Pattern.CASE_INSENSITIVE)); } private static boolean matchesBlacklist(String sql) { diff --git a/src/test/java/com/zendesk/maxwell/schema/ddl/DDLIntegrationTest.java b/src/test/java/com/zendesk/maxwell/schema/ddl/DDLIntegrationTest.java index e80c819cf..8bf6bf00f 100644 --- a/src/test/java/com/zendesk/maxwell/schema/ddl/DDLIntegrationTest.java +++ b/src/test/java/com/zendesk/maxwell/schema/ddl/DDLIntegrationTest.java @@ -144,7 +144,32 @@ public void testIntX() throws Exception { }; testIntegration(sql); + } + + @Test + public void testYearWithLength() throws Exception { + String sql[] = { + "create TABLE `test_year` ( id year(4) )" + }; + testIntegration(sql); } + @Test + public void testBooleans() throws Exception { + String sql[] = { + "create TABLE `test_boolean` ( b1 bool, b2 boolean )" + }; + + testIntegration(sql); + } + + @Test + public void testReals() throws Exception { + String sql[] = { + "create TABLE `test_reals` ( r1 REAL, b2 REAL (2,2) )" + }; + + testIntegration(sql); + } }