@Test public void shouldConvertDDLtoJsonSchema() { final String ddl = "CREATE TABLE `roles` (\n" + "`id` varchar(32) NOT NULL,\n" + "`name` varchar(100) NOT NULL,\n" + "`context` varchar(20) NOT NULL,\n" + "`organization_id` int(11) DEFAULT NULL,\n" + "`client_id` varchar(32) NOT NULL,\n" + "`scope_action_ids` text NOT NULL,\n" + "PRIMARY KEY (`id`),\n" + "FULLTEXT KEY `scope_action_ids_idx` (`scope_action_ids`)\n" + ") ENGINE=InnoDB DEFAULT CHARSET=utf8;"; final String generated = DebeziumMySQLDatashapeStrategy.convertDDLtoJsonSchema(ddl, "roles"); final String expected = "{\n" + " \"$schema\":\"http: " \"title\":\"roles\",\n" + " \"type\":\"object\",\n" + " \"properties\":{\n" + " \"id\":{\n" + " \"type\":\"string\"\n" + " },\n" + " \"name\":{\n" + " \"type\":\"string\"\n" + " },\n" + " \"context\":{\n" + " \"type\":\"string\"\n" + " },\n" + " \"organization_id\":{\n" + " \"type\":\"integer\"\n" + " },\n" + " \"client_id\":{\n" + " \"type\":\"string\"\n" + " },\n" + " \"scope_action_ids\":{\n" + " \"type\":\"string\"\n" + " }\n" + " }\n" + "}"; assertThatJson(generated).isEqualTo(expected); }
static String convertDDLtoJsonSchema(final String ddl, final String tableName) { int firstParentheses = ddl.indexOf('('); final Matcher matcher = PATTERN.matcher(ddl.substring(firstParentheses)); final List<String> properties = new ArrayList<>(); while (matcher.find()) { final String field = matcher.group(1); final String type = getType(matcher.group(2)); properties.add("\"" + field + "\":{\"type\":\"" + type + "\"}"); } return buildJsonSchema(tableName, properties); }
DebeziumMySQLDatashapeStrategy implements DebeziumDatashapeStrategy { static String convertDDLtoJsonSchema(final String ddl, final String tableName) { int firstParentheses = ddl.indexOf('('); final Matcher matcher = PATTERN.matcher(ddl.substring(firstParentheses)); final List<String> properties = new ArrayList<>(); while (matcher.find()) { final String field = matcher.group(1); final String type = getType(matcher.group(2)); properties.add("\"" + field + "\":{\"type\":\"" + type + "\"}"); } return buildJsonSchema(tableName, properties); } }
DebeziumMySQLDatashapeStrategy implements DebeziumDatashapeStrategy { static String convertDDLtoJsonSchema(final String ddl, final String tableName) { int firstParentheses = ddl.indexOf('('); final Matcher matcher = PATTERN.matcher(ddl.substring(firstParentheses)); final List<String> properties = new ArrayList<>(); while (matcher.find()) { final String field = matcher.group(1); final String type = getType(matcher.group(2)); properties.add("\"" + field + "\":{\"type\":\"" + type + "\"}"); } return buildJsonSchema(tableName, properties); }  }
DebeziumMySQLDatashapeStrategy implements DebeziumDatashapeStrategy { static String convertDDLtoJsonSchema(final String ddl, final String tableName) { int firstParentheses = ddl.indexOf('('); final Matcher matcher = PATTERN.matcher(ddl.substring(firstParentheses)); final List<String> properties = new ArrayList<>(); while (matcher.find()) { final String field = matcher.group(1); final String type = getType(matcher.group(2)); properties.add("\"" + field + "\":{\"type\":\"" + type + "\"}"); } return buildJsonSchema(tableName, properties); }  @Override DataShape getDatashape(Map<String, Object> params); }
DebeziumMySQLDatashapeStrategy implements DebeziumDatashapeStrategy { static String convertDDLtoJsonSchema(final String ddl, final String tableName) { int firstParentheses = ddl.indexOf('('); final Matcher matcher = PATTERN.matcher(ddl.substring(firstParentheses)); final List<String> properties = new ArrayList<>(); while (matcher.find()) { final String field = matcher.group(1); final String type = getType(matcher.group(2)); properties.add("\"" + field + "\":{\"type\":\"" + type + "\"}"); } return buildJsonSchema(tableName, properties); }  @Override DataShape getDatashape(Map<String, Object> params);  }