bito-code-review[bot] commented on code in PR #37307: URL: https://github.com/apache/superset/pull/37307#discussion_r2713082930
########## docs/docs/configuration/databases.mdx: ########## @@ -1029,6 +1030,25 @@ The expected connection string is formatted as follows: kylin://<username>:<password>@<hostname>:<port>/<project>?<param1>=<value1>&<param2>=<value2> ``` +#### MongoDB + +##### PyMongoSQL + +[PyMongoSQL](https://pypi.org/project/pymongosql/) is a Python DB API 2.0 (PEP 249) client for MongoDB. + +The connection string for MongoDB is as follows: + +``` +mongodb://{username}:{password}@{host}:{port}/{database}?mode=superset +``` +or for MongoDB Atlas: +``` +mongodb+srv://{username}:{password}@{host}:{port}/{database}?mode=superset Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Invalid connection string</b></div> <div id="fix"> The MongoDB Atlas connection string example incorrectly includes :{port}, but mongodb+srv URIs do not use a port number. This will cause connection failures for Atlas users. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ````suggestion mongodb+srv://{username}:{password}@{host}/{database}?mode=superset ```` </div> </details> </div> <small><i>Code Review Run #3a496b</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset/db_engine_specs/mongodb.py: ########## @@ -0,0 +1,80 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""MongoDB engine spec for Superset. + +Uses PyMongoSQL (https://github.com/passren/PyMongoSQL) as the SQLAlchemy dialect +to enable SQL queries on MongoDB collections. +""" + +from __future__ import annotations + +from datetime import datetime +from typing import Any, Optional, TYPE_CHECKING + +from sqlalchemy import types + +from superset.constants import TimeGrain +from superset.db_engine_specs.base import BaseEngineSpec + +if TYPE_CHECKING: + from superset.models.core import Database + + +class MongoDBEngineSpec(BaseEngineSpec): + """Engine spec for MongoDB using PyMongoSQL dialect.""" + + engine = "mongodb" + engine_name = "MongoDB" + force_column_alias_quotes = False + + _time_grain_expressions = { + None: "{col}", + TimeGrain.SECOND: "{col}", + TimeGrain.MINUTE: "{col}", + TimeGrain.HOUR: "{col}", + TimeGrain.DAY: "{col}", + TimeGrain.WEEK: "{col}", + TimeGrain.MONTH: "{col}", + TimeGrain.QUARTER: "{col}", + TimeGrain.YEAR: "{col}", + TimeGrain.WEEK_ENDING_SATURDAY: "{col}", + TimeGrain.WEEK_ENDING_SUNDAY: "{col}", + TimeGrain.WEEK_STARTING_SUNDAY: "{col}", + TimeGrain.WEEK_STARTING_MONDAY: "{col}", + } Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Incorrect time grain handling</b></div> <div id="fix"> The _time_grain_expressions defines time grains that map to "{col}" without actual truncation, which will not group data correctly when users select time grains in queries. Since PyMongoSQL is based on PartiQL and lacks date functions for truncation, only None should be supported to avoid misleading behavior. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ````suggestion _time_grain_expressions = { None: "{col}", } ```` </div> </details> </div> <small><i>Code Review Run #3a496b</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
