6262from pyiceberg .utils .singleton import Singleton
6363
6464DECIMAL_REGEX = re .compile (r"decimal\((\d+),\s*(\d+)\)" )
65- GEOGRAPHY_REGEX = re .compile (r"""geography(\(([a-zA-Z0-9:]+)( ,\s*([a-zA-Z]+) )?\))?""" )
66- GEOMETRY_REGEX = re .compile (r"""geometry(\(([a-zA-Z0-9:]+)\ ))?""" )
65+ GEOGRAPHY_REGEX = re .compile (r"""geography\s*(?:\(\s*([^,]*?)\s*(?: ,\s*(\w*)\s* )?\))?""" , re . IGNORECASE )
66+ GEOMETRY_REGEX = re .compile (r"""geometry\s*(?:\(\s*([^)]*?)\s*\ ))?""" , re . IGNORECASE )
6767FIXED = "fixed"
6868FIXED_PARSER = ParseNumberFromBrackets (FIXED )
6969
@@ -92,10 +92,13 @@ def _parse_geography_type(geography: Any) -> Tuple[str, GeographyType.EdgeAlgori
9292 if isinstance (geography , str ):
9393 matches = GEOGRAPHY_REGEX .search (geography )
9494 if matches :
95+ crs = None
9596 edge_algorithm = None
96- if matches .group (4 ):
97- edge_algorithm = GeographyType .EdgeAlgorithm (matches .group (4 ))
98- return matches .group (2 ), edge_algorithm
97+ if matches .group (1 ):
98+ crs = matches .group (1 )
99+ if matches .group (2 ):
100+ edge_algorithm = GeographyType .EdgeAlgorithm (matches .group (2 ).lower ())
101+ return crs , edge_algorithm
99102 else :
100103 raise ValidationError (f"Could not parse { geography } into a GeographyType" )
101104 elif isinstance (geography , dict ):
@@ -107,7 +110,10 @@ def _parse_geometry_type(geometry: Any) -> str:
107110 if isinstance (geometry , str ):
108111 matches = GEOMETRY_REGEX .search (geometry )
109112 if matches :
110- return matches .group (2 )
113+ crs = None
114+ if matches .group (1 ):
115+ crs = matches .group (1 )
116+ return crs
111117 else :
112118 raise ValidationError (f"Could not parse { geometry } into a GeometryType" )
113119 elif isinstance (geometry , dict ):
0 commit comments