-
Notifications
You must be signed in to change notification settings - Fork 111
Draft: Do not review, add support for specific geometry types #2803
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
Draft
panbhag-ch
wants to merge
23
commits into
main
Choose a base branch
from
mysql-geo-specific
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
58d9ff0
add support for specific geometry types
panbhag-ch 52c0106
fix build errors
panbhag-ch 0203616
fix errors
panbhag-ch aabf81c
Merge branch 'main' into mysql-geo-specific
panbhag-ch 60fd856
fix lint errors
panbhag-ch faac66a
fix lint errors
panbhag-ch afef29f
fix mysql geometry tests
panbhag-ch a517a40
fix mysql geo tst
panbhag-ch 0f6c463
fix error
panbhag-ch 02aff90
fix test
panbhag-ch 650ce5f
fix errors
panbhag-ch 9c8e059
fix test
panbhag-ch 2b26ab8
fix geo test
panbhag-ch 195aa78
fix issues
panbhag-ch 9cc43b8
add logs
panbhag-ch fcd2572
fix s.source.Query
panbhag-ch b88b746
replace Query by GetRows
panbhag-ch 2e1ce95
fix error
panbhag-ch 67b6f69
remove unused vars
panbhag-ch b9adcc5
fix lint errors
panbhag-ch 9a4979c
Merge branch 'main' into mysql-geo-specific
panbhag-ch 85aadff
fix lint error
panbhag-ch fd61d4c
add space in sql
panbhag-ch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,7 +92,26 @@ func qkindFromMysql(field *mysql.Field) (qvalue.QValueKind, error) { | |
case mysql.MYSQL_TYPE_VAR_STRING, mysql.MYSQL_TYPE_STRING: | ||
return qvalue.QValueKindString, nil | ||
case mysql.MYSQL_TYPE_GEOMETRY: | ||
return qvalue.QValueKindGeometry, nil | ||
// Check the column type name to determine specific geometry type | ||
colType := strings.ToLower(string(field.Name)) | ||
switch { | ||
case strings.Contains(colType, "point"): | ||
return qvalue.QValueKindPoint, nil | ||
case strings.Contains(colType, "linestring"): | ||
return qvalue.QValueKindLineString, nil | ||
case strings.Contains(colType, "polygon"): | ||
return qvalue.QValueKindPolygon, nil | ||
case strings.Contains(colType, "multipoint"): | ||
return qvalue.QValueKindMultiPoint, nil | ||
case strings.Contains(colType, "multilinestring"): | ||
return qvalue.QValueKindMultiLineString, nil | ||
case strings.Contains(colType, "multipolygon"): | ||
return qvalue.QValueKindMultiPolygon, nil | ||
case strings.Contains(colType, "geometrycollection"): | ||
return qvalue.QValueKindGeometryCollection, nil | ||
default: | ||
return qvalue.QValueKindGeometry, nil | ||
} | ||
case mysql.MYSQL_TYPE_VECTOR: | ||
return qvalue.QValueKindArrayFloat32, nil | ||
default: | ||
|
@@ -154,8 +173,25 @@ func qkindFromMysqlColumnType(ct string) (qvalue.QValueKind, error) { | |
} | ||
case "vector": | ||
return qvalue.QValueKindArrayFloat32, nil | ||
case "geometry", "point", "polygon", "linestring", "multipoint", "multipolygon", "geomcollection": | ||
return qvalue.QValueKindGeometry, nil | ||
case "geometry", "point", "linestring", "polygon", "multipoint", "multilinestring", "multipolygon", "geometrycollection": | ||
switch ct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Earlier check is on |
||
case "point": | ||
return qvalue.QValueKindPoint, nil | ||
case "linestring": | ||
return qvalue.QValueKindLineString, nil | ||
case "polygon": | ||
return qvalue.QValueKindPolygon, nil | ||
case "multipoint": | ||
return qvalue.QValueKindMultiPoint, nil | ||
case "multilinestring": | ||
return qvalue.QValueKindMultiLineString, nil | ||
case "multipolygon": | ||
return qvalue.QValueKindMultiPolygon, nil | ||
case "geometrycollection": | ||
return qvalue.QValueKindGeometryCollection, nil | ||
default: | ||
return qvalue.QValueKindGeometry, nil | ||
} | ||
default: | ||
return qvalue.QValueKind(""), fmt.Errorf("unknown mysql type %s", ct) | ||
} | ||
|
@@ -213,17 +249,39 @@ func geometryValueFromBytes(wkbData []byte) (string, error) { | |
return wkt, nil | ||
} | ||
|
||
// Helper function to process geometry data and return a QValueGeometry | ||
func processGeometryData(data []byte) qvalue.QValueGeometry { | ||
// Helper function to process geometry data and return a QValue | ||
func processGeometryData(data []byte, qkind qvalue.QValueKind) qvalue.QValue { | ||
var strVal string | ||
// For geometry data, we need to convert from MySQL's binary format to WKT | ||
if len(data) > 4 { | ||
wkt, err := geometryValueFromBytes(data) | ||
if err == nil { | ||
return qvalue.QValueGeometry{Val: wkt} | ||
strVal = wkt | ||
} else { | ||
strVal = string(data) | ||
} | ||
} else { | ||
strVal = string(data) | ||
} | ||
|
||
switch qkind { | ||
case qvalue.QValueKindPoint: | ||
return qvalue.QValuePoint{Val: strVal} | ||
case qvalue.QValueKindLineString: | ||
return qvalue.QValueLineString{Val: strVal} | ||
case qvalue.QValueKindPolygon: | ||
return qvalue.QValuePolygon{Val: strVal} | ||
case qvalue.QValueKindMultiPoint: | ||
return qvalue.QValueMultiPoint{Val: strVal} | ||
case qvalue.QValueKindMultiLineString: | ||
return qvalue.QValueMultiLineString{Val: strVal} | ||
case qvalue.QValueKindMultiPolygon: | ||
return qvalue.QValueMultiPolygon{Val: strVal} | ||
case qvalue.QValueKindGeometryCollection: | ||
return qvalue.QValueGeometryCollection{Val: strVal} | ||
default: | ||
return qvalue.QValueGeometry{Val: strVal} | ||
} | ||
strVal := string(data) | ||
return qvalue.QValueGeometry{Val: strVal} | ||
} | ||
|
||
func QValueFromMysqlFieldValue(qkind qvalue.QValueKind, fv mysql.FieldValue) (qvalue.QValue, error) { | ||
|
@@ -306,8 +364,10 @@ func QValueFromMysqlFieldValue(qkind qvalue.QValueKind, fv mysql.FieldValue) (qv | |
return qvalue.QValueBytes{Val: slices.Clone(v)}, nil | ||
case qvalue.QValueKindJSON: | ||
return qvalue.QValueJSON{Val: string(v)}, nil | ||
case qvalue.QValueKindGeometry: | ||
return processGeometryData(v), nil | ||
case qvalue.QValueKindGeometry, qvalue.QValueKindPoint, qvalue.QValueKindLineString, | ||
qvalue.QValueKindPolygon, qvalue.QValueKindMultiPoint, qvalue.QValueKindMultiLineString, | ||
qvalue.QValueKindMultiPolygon, qvalue.QValueKindGeometryCollection: | ||
return processGeometryData(v, qkind), nil | ||
case qvalue.QValueKindNumeric: | ||
val, err := decimal.NewFromString(unsafeString) | ||
if err != nil { | ||
|
@@ -438,7 +498,7 @@ func QValueFromMysqlRowEvent( | |
return qvalue.QValueJSON{Val: string(val)}, nil | ||
case qvalue.QValueKindGeometry: | ||
// Handle geometry data as binary (WKB format) | ||
return processGeometryData(val), nil | ||
return processGeometryData(val, qkind), nil | ||
case qvalue.QValueKindArrayFloat32: | ||
floats := make([]float32, 0, len(val)/4) | ||
for i := 0; i < len(val); i += 4 { | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HasPrefix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
field.Name is column's name, not column's type. We don't have enough information here to figure it out. May need to make geometry all fall under one
QValueKind
& put SRID as a field forQValueGeometry