Skip to content
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

Support MySQL point #815

Merged
merged 1 commit into from
Sep 30, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
import com.altinity.clickhouse.sink.connector.ClickHouseSinkConnectorConfigVariables;
import com.clickhouse.data.ClickHouseDataType;
import com.clickhouse.data.value.ClickHouseDoubleValue;
import com.clickhouse.data.value.ClickHouseGeoPointValue;
import com.google.common.io.BaseEncoding;
import io.debezium.data.*;
import io.debezium.data.Enum;
import io.debezium.data.EnumSet;
import io.debezium.data.geometry.Geometry;
import io.debezium.data.geometry.Point;
import io.debezium.time.*;
import io.debezium.time.Date;
import org.apache.commons.lang3.tuple.MutablePair;
Expand Down Expand Up @@ -89,6 +91,9 @@ public class ClickHouseDataTypeMapper {
// Geometry -> Geometry
dataTypesMap.put(new MutablePair<>(Schema.Type.STRUCT, Geometry.LOGICAL_NAME), ClickHouseDataType.String);

// Point -> Point
dataTypesMap.put(new MutablePair<>(Schema.Type.STRUCT, Point.LOGICAL_NAME), ClickHouseDataType.Point);

// PostgreSQL UUID -> UUID
dataTypesMap.put(new MutablePair<>(Schema.Type.STRING, Uuid.LOGICAL_NAME), ClickHouseDataType.UUID);

Expand Down Expand Up @@ -237,6 +242,20 @@ else if (value instanceof Long) {
} else {
ps.setString(index, "");
}
} else if (type == Schema.Type.STRUCT && schemaName.equalsIgnoreCase(Point.LOGICAL_NAME)) {
// Handle Point type (ClickHouse expects (longitude, latitude))
if (value instanceof Struct) {
Struct pointValue = (Struct) value;
Object xValue = pointValue.get("x");
Object yValue = pointValue.get("y");

double[] point = {(Double) xValue, (Double) yValue};

ps.setObject(index, ClickHouseGeoPointValue.of(point));
} else {
// If the value is not a valid Struct for a Point, set an empty point
ps.setObject(index, ClickHouseGeoPointValue.ofOrigin());
}
} else if (type == Schema.Type.STRUCT && schemaName.equalsIgnoreCase(VariableScaleDecimal.LOGICAL_NAME)) {
if (value instanceof Struct) {
Struct decimalValue = (Struct) value;
Expand Down
Loading