Skip to content

Commit

Permalink
Support Geography.
Browse files Browse the repository at this point in the history
  • Loading branch information
Tang8330 committed Feb 12, 2024
1 parent 891a9c8 commit cbecfc7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/cdc/util/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func parseField(field debezium.Field, value interface{}) interface{} {
}
case debezium.GeometryType, debezium.GeographyType:
geometryString, err := parseGeometry(value)
fmt.Println("err", err)
if err == nil {
return geometryString
}
Expand Down
33 changes: 33 additions & 0 deletions lib/cdc/util/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,39 @@ func TestParseField(t *testing.T) {
expectedValue: "123.45",
expectedDecimal: true,
},
{
name: "geometry (no srid)",
field: debezium.Field{
DebeziumType: string(debezium.GeometryType),
},
value: map[string]interface{}{
"srid": nil,
"wkb": "AQEAAAAAAAAAAADwPwAAAAAAABRA",
},
expectedValue: `{"type":"Feature","geometry":{"type":"Point","coordinates":[1,5]},"properties":null}`,
},
{
name: "geometry (w/ srid)",
field: debezium.Field{
DebeziumType: string(debezium.GeometryType),
},
value: map[string]interface{}{
"srid": 4326,
"wkb": "AQEAACDmEAAAAAAAAAAA8D8AAAAAAAAYQA==",
},
expectedValue: `{"type":"Feature","geometry":{"type":"Point","coordinates":[1,6]},"properties":null}`,
},
{
name: "geography (w/ srid)",
field: debezium.Field{
DebeziumType: string(debezium.GeographyType),
},
value: map[string]interface{}{
"srid": 4326,
"wkb": "AQEAACDmEAAAAAAAAADAXkAAAAAAAIBDwA==",
},
expectedValue: `{"type":"Feature","geometry":{"type":"Point","coordinates":[123,-39]},"properties":null}`,
},
}

for _, testCase := range testCases {
Expand Down

0 comments on commit cbecfc7

Please sign in to comment.