/** * Converts a value representing a Postgres point for a column, to a Kafka Connect value. * * @param column the JDBC column; never null * @param fieldDefn the Connect field definition for this column; never null * @param data a data for the point column, either coming from the JDBC driver or logical decoding plugin * @return a value which will be used by Connect to represent the actual point value */ protected Object convertPoint(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, Point.createValue(fieldDefn.schema(), 0, 0), (r) -> { final Schema schema = fieldDefn.schema(); if (data instanceof PGpoint) { PGpoint pgPoint = (PGpoint) data; r.deliver(Point.createValue(schema, pgPoint.x, pgPoint.y)); } else if (data instanceof String) { String dataString = data.toString(); try { PGpoint pgPoint = new PGpoint(dataString); r.deliver(Point.createValue(schema, pgPoint.x, pgPoint.y)); } catch (SQLException e) { logger.warn("Error converting the string '{}' to a PGPoint type for the column '{}'", dataString, column); } } else if (data instanceof PgProto.Point) { r.deliver(Point.createValue(schema, ((PgProto.Point) data).getX(), ((PgProto.Point) data).getY())); } }); }
protected List<SchemaAndValueField> schemaAndValuesForGeomTypes() { Schema pointSchema = Point.builder().optional().build(); return Collections.singletonList(new SchemaAndValueField("p", pointSchema, Point.createValue(pointSchema, 1, 1))); }
/** * Convert the a value representing a POINT {@code byte[]} value to a Point value used in a {@link SourceRecord}. * * @param column the column in which the value appears * @param fieldDefn the field definition for the {@link SourceRecord}'s {@link Schema}; never null * @param data the data; may be null * @return the converted value, or null if the conversion could not be made and the column allows nulls * @throws IllegalArgumentException if the value could not be converted but the column does not allow nulls */ protected Object convertPoint(Column column, Field fieldDefn, Object data){ final MySqlGeometry empty = MySqlGeometry.createEmpty(); return convertValue(column, fieldDefn, data, io.debezium.data.geometry.Geometry.createValue(fieldDefn.schema(), empty.getWkb(), empty.getSrid()), (r) -> { if (data instanceof byte[]) { // The binlog utility sends a byte array for any Geometry type, we will use our own binaryParse to parse the byte to WKB, hence // to the suitable class MySqlGeometry mySqlGeometry = MySqlGeometry.fromBytes((byte[]) data); if (mySqlGeometry.isPoint()) { r.deliver(io.debezium.data.geometry.Point.createValue(fieldDefn.schema(), mySqlGeometry.getWkb(), mySqlGeometry.getSrid())); } else { throw new ConnectException("Failed to parse and read a value of type POINT on " + column); } } }); }
/** * Converts a value representing a Postgres point for a column, to a Kafka Connect value. * * @param column the JDBC column; never null * @param fieldDefn the Connect field definition for this column; never null * @param data a data for the point column, either coming from the JDBC driver or logical decoding plugin * @return a value which will be used by Connect to represent the actual point value */ protected Object convertPoint(Column column, Field fieldDefn, Object data) { return convertValue(column, fieldDefn, data, Point.createValue(fieldDefn.schema(), 0, 0), (r) -> { final Schema schema = fieldDefn.schema(); if (data instanceof PGpoint) { PGpoint pgPoint = (PGpoint) data; r.deliver(Point.createValue(schema, pgPoint.x, pgPoint.y)); } else if (data instanceof String) { String dataString = data.toString(); try { PGpoint pgPoint = new PGpoint(dataString); r.deliver(Point.createValue(schema, pgPoint.x, pgPoint.y)); } catch (SQLException e) { logger.warn("Error converting the string '{}' to a PGPoint type for the column '{}'", dataString, column); } } else if (data instanceof PgProto.Point) { r.deliver(Point.createValue(schema, ((PgProto.Point) data).getX(), ((PgProto.Point) data).getY())); } }); }
protected List<SchemaAndValueField> schemaAndValuesForGeomTypes() { Schema pointSchema = Point.builder().optional().build(); return Collections.singletonList(new SchemaAndValueField("p", pointSchema, Point.createValue(pointSchema, 1, 1))); }