Skip to content

Commit 8903fde

Browse files
authored
0.4.2 - Support special characters in collection name (#19)
* Add some test cases * Support collection name having hyphen in it --------- Co-authored-by: Peng Ren
1 parent 37c6ad3 commit 8903fde

15 files changed

+2806
-2511
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ MANIFEST
2727
.vscode/
2828
.idea/
2929

30+
# Test configuration
31+
pytest.ini
32+
3033
# Environments
3134
.env
3235
.envrc

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,10 @@ PyMongoSQL can be used as a database driver in Apache Superset for querying and
536536

537537
This allows seamless integration between MongoDB data and Superset's BI capabilities without requiring data migration to traditional SQL databases.
538538

539+
**Important Note on Collection Names:**
540+
541+
When using collection names containing special characters (`.`, `-`, `:`), you must wrap them in double quotes to prevent Superset's SQL parser from incorrectly interpreting them.
542+
539543
## Contributing
540544

541545
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

pymongosql/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
if TYPE_CHECKING:
77
from .connection import Connection
88

9-
__version__: str = "0.4.1"
9+
__version__: str = "0.4.2"
1010

1111
# Globals https://www.python.org/dev/peps/pep-0249/#globals
1212
apilevel: str = "2.0"

pymongosql/sql/partiql/PartiQLLexer.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ CURRENT_TIMESTAMP: 'CURRENT_TIMESTAMP';
7777
CURRENT_USER: 'CURRENT_USER';
7878
CURSOR: 'CURSOR';
7979
DATE: 'DATE';
80+
DATETIME: 'DATETIME';
8081
DEALLOCATE: 'DEALLOCATE';
8182
DEC: 'DEC';
8283
DECIMAL: 'DECIMAL';
@@ -370,7 +371,7 @@ LITERAL_DECIMAL:
370371
;
371372

372373
IDENTIFIER
373-
: [A-Z$_][A-Z0-9$_]*;
374+
: [A-Z$_][A-Z0-9$_-]*;
374375

375376
IDENTIFIER_QUOTED
376377
: '"' ( ('""') | ~('"') )* '"';

pymongosql/sql/partiql/PartiQLLexer.py

Lines changed: 1452 additions & 1448 deletions
Large diffs are not rendered by default.

pymongosql/sql/partiql/PartiQLParser.g4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ functionCall
723723

724724
// SQL-99 10.4 � <routine name> ::= [ <schema name> <period> ] <qualified identifier>
725725
functionName
726-
: (qualifier+=symbolPrimitive PERIOD)* name=( CHAR_LENGTH | CHARACTER_LENGTH | OCTET_LENGTH | BIT_LENGTH | UPPER | LOWER | SIZE | EXISTS | COUNT ) # FunctionNameReserved
726+
: (qualifier+=symbolPrimitive PERIOD)* name=( CHAR_LENGTH | CHARACTER_LENGTH | OCTET_LENGTH | BIT_LENGTH | UPPER | LOWER | SIZE | EXISTS | COUNT | DATE | DATETIME | SUBSTRING | REPLACE | TRIM ) # FunctionNameReserved
727727
| (qualifier+=symbolPrimitive PERIOD)* name=symbolPrimitive # FunctionNameSymbol
728728
;
729729

pymongosql/sql/partiql/PartiQLParser.py

Lines changed: 1066 additions & 1053 deletions
Large diffs are not rendered by default.

pymongosql/sql/partiql/PartiQLParserListener.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated from PartiQLParser.g4 by ANTLR 4.13.0
1+
# Generated from PartiQLParser.g4 by ANTLR 4.13.1
22
from antlr4 import *
33
if "." in __name__:
44
from .PartiQLParser import PartiQLParser

pymongosql/sql/partiql/PartiQLParserVisitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated from PartiQLParser.g4 by ANTLR 4.13.0
1+
# Generated from PartiQLParser.g4 by ANTLR 4.13.1
22
from antlr4 import *
33
if "." in __name__:
44
from .PartiQLParser import PartiQLParser

pymongosql/sql/query_handler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ def handle_visitor(self, ctx: PartiQLParser.FromClauseContext, parse_result: "Qu
244244

245245
# Regular collection reference
246246
table_text = ctx.tableReference().getText()
247-
collection_name = table_text
247+
# Strip surrounding quotes from collection name (e.g., "user.accounts" -> user.accounts)
248+
collection_name = re.sub(r'^"([^"]+)"$', r"\1", table_text)
248249
parse_result.collection = collection_name
249250
_logger.debug(f"Parsed regular collection: {collection_name}")
250251
return collection_name

0 commit comments

Comments
 (0)