@@ -168,6 +168,18 @@ def can_handle(self, ctx: Any) -> bool:
168168 """Check if this is a from context"""
169169 return hasattr (ctx , "tableReference" )
170170
171+ @staticmethod
172+ def _strip_collection_quotes (name : str ) -> str :
173+ """Strip surrounding double quotes from collection name if present.
174+
175+ Args:
176+ name: Collection name, potentially quoted
177+
178+ Returns:
179+ Collection name with quotes removed
180+ """
181+ return re .sub (r'^"([^"]+)"$' , r"\1" , name )
182+
171183 def _parse_function_call (self , ctx : Any ) -> Optional [Dict [str , Any ]]:
172184 """
173185 Detect and parse aggregate() function calls in FROM clause.
@@ -196,13 +208,17 @@ def _parse_function_call(self, ctx: Any) -> Optional[Dict[str, Any]]:
196208
197209 # Pattern: [qualifier.]functionName(arg1, arg2)
198210 # We need to match: (optional_collection.)aggregate('...', '...')
199- pattern = r"^(?:(\w+)\.)?aggregate\s*\(\s*'([^']*)'\s*,\s*'([^']*)'\s*\)$"
211+ # Support collection names with double quotes for special characters like hyphens
212+ pattern = r"^(?:(\"[^\"]+\"|\w+)\.)?aggregate\s*\(\s*'([^']*)'\s*,\s*'([^']*)'\s*\)$"
200213 match = re .match (pattern , text , re .IGNORECASE | re .DOTALL )
201214
202215 if not match :
203216 return None
204217
205218 collection = match .group (1 ) # Can be None for unqualified aggregate()
219+ # Strip quotes from collection name if present
220+ if collection :
221+ collection = self ._strip_collection_quotes (collection )
206222 pipeline = match .group (2 )
207223 options = match .group (3 )
208224
@@ -245,7 +261,7 @@ def handle_visitor(self, ctx: PartiQLParser.FromClauseContext, parse_result: "Qu
245261 # Regular collection reference
246262 table_text = ctx .tableReference ().getText ()
247263 # Strip surrounding quotes from collection name (e.g., "user.accounts" -> user.accounts)
248- collection_name = re . sub ( r'^"([^"]+)"$' , r"\1" , table_text )
264+ collection_name = self . _strip_collection_quotes ( table_text )
249265 parse_result .collection = collection_name
250266 _logger .debug (f"Parsed regular collection: { collection_name } " )
251267 return collection_name
0 commit comments