Repository navigation
Description
We are migrating an existing PHP/MySQL web application to Elixir/Phoenix. A part of the application deals with geometry and polygons. After hitting some bumps we got most of it working. We could create and edit clusters (Polygon) in the app. However, once we imported the existing dataset we got errors parsing the Polygon data in mariaex. It seems like whenever the polygon gets too big, the pattern matching for the row parsers fails, and we fail to understand why 😄
So then I cloned the repo here and update the inserts polygon test, and I was able to replicate the error.
Executing this test:
polygon = %Mariaex.Geometry.Polygon{
coordinates: [
[ {0.0, 0.0}, {10.0, 0.0}, {10.0, 10.0}, {0.0, 10.0}, {0.0, 0.0}, {0.0, 0.0}, {10.0, 0.0}, {10.0, 10.0}, {0.0, 10.0}, {0.0, 0.0}, {0.0, 0.0}, {10.0, 0.0}, {10.0, 10.0}, {0.0, 10.0}, {0.0, 0.0}, {0.0, 0.0}, {10.0, 0.0}, {10.0, 10.0}, {0.0, 10.0}, {0.0, 0.0}, {0.0, 0.0}, {10.0, 0.0}, {10.0, 10.0}, {0.0, 10.0}, {0.0, 0.0}, {0.0, 0.0}, {10.0, 0.0}, {10.0, 10.0}, {0.0, 10.0}, {0.0, 0.0} ]
],
srid: 0
}
Results in the following error:
** (FunctionClauseError) no function clause matching in Mariaex.RowParser.decode_geometry/6
The following arguments were given to Mariaex.RowParser.decode_geometry/6:
# 1
<<252, 241, 1, 42, 0, 0, 0, 1, 3, 0, 0, 0, 1, 0, 0, 0, 30, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 64, 0, 0, 0, 0, 0, 0, ...>>
# 2
[]
# 3
0
# 4
[]
# 5
:structs
# 6
Poison
Attempted function clauses (showing 3 out of 3):
defp decode_geometry(<<25::integer()-little()-size(8), srid::integer()-little()-size(32), 1::integer()-little()-size(8), 1::integer()-little()-size(32), x::float()-little()-size(64), y::float()-little()-size(64), rest::bitstring()>>, fields, null_bitfield, acc, datetime, json_library)
defp decode_geometry(<<_len::integer()-little()-size(8), srid::integer()-little()-size(32), 1::integer()-little()-size(8), 2::integer()-little()-size(32), num_points::integer()-little()-size(32), points::binary()-unit(128)-size(num_points), rest::bitstring()>>, fields, null_bitfield, acc, datetime, json_library)
defp decode_geometry(<<_len::integer()-little()-size(8), srid::integer()-little()-size(32), 1::integer()-little()-size(8), 3::integer()-little()-size(32), num_rings::integer()-little()-size(32), rest::bitstring()>>, fields, null_bitfield, acc, datetime, json_library)
Can you hint us in the right direction? It is not always the amount of points that seems to cause the issue, sometimes the precision makes a difference too. We checked the polygons to be valid using the MySQL validation functions but all seems fine.
Thank you in advance!
Activity
pierot commentedon Jun 13, 2018
I have been testing this as well and have found a fix, but I don't understand why ..
The function definition that doesn't match, and should is:
I saw that more complex polygons generates a different bitstring:
Complex:
Generates:
A simpler one:
Generates:
In the complex one adds 2 extra parts a the start
113, 1I created a different definition for
decode_geometrythat catches these parts and makes the extended tests pass.Any ideas?