betodealmeida commented on a change in pull request #14535:
URL: https://github.com/apache/superset/pull/14535#discussion_r633720652
##########
File path: superset/db_engine_specs/base.py
##########
@@ -140,7 +140,7 @@ class LimitMethod: # pylint: disable=too-few-public-methods
FORCE_LIMIT = "force_limit"
-class BaseEngineSpec: # pylint: disable=too-many-public-methods
+class BaseEngineSpec: # pylint:
disable=too-many-public-methods,abstract-method
Review comment:
Nit:
```suggestion
class BaseEngineSpec: # pylint: disable=too-many-public-methods,
abstract-method
```
##########
File path: superset/db_engine_specs/bigquery.py
##########
@@ -282,3 +303,33 @@ def df_to_sql(
to_gbq_kwargs[key] = to_sql_kwargs[key]
pandas_gbq.to_gbq(df, **to_gbq_kwargs)
+
+ @classmethod
+ def build_sqlalchemy_url(cls, parameters: BigQueryParametersType) -> str:
+ project_id = (
+ parameters.get("credentials_json", {})
+ .get("credentials_info", {})
+ .get("project_id")
+ )
+
+ return f"{cls.drivername}://{project_id}"
Review comment:
Also, @eschutho, should we use brackets or triple slashes here? I
remember you had problems with this before.
##########
File path: superset/db_engine_specs/bigquery.py
##########
@@ -282,3 +303,33 @@ def df_to_sql(
to_gbq_kwargs[key] = to_sql_kwargs[key]
pandas_gbq.to_gbq(df, **to_gbq_kwargs)
+
+ @classmethod
+ def build_sqlalchemy_url(cls, parameters: BigQueryParametersType) -> str:
+ project_id = (
+ parameters.get("credentials_json", {})
+ .get("credentials_info", {})
+ .get("project_id")
+ )
+
+ return f"{cls.drivername}://{project_id}"
+
+ @classmethod
+ def get_parameters_from_uri(cls, uri: str) ->
Optional[BigQueryParametersType]:
+ # We might need to add a special case for bigquery since
+ # we are relying on the json credentials
+ return None
+
+ @classmethod
+ def parameters_json_schema(cls) -> Any:
+ """
+ Return configuration parameters as OpenAPI.
+ """
+ spec = APISpec(
+ title="Database Parameters",
+ version="1.0.0",
+ openapi_version="3.0.2",
+ plugins=[MarshmallowPlugin()],
+ )
+ spec.components.schema(cls.__name__, schema=cls.parameters_schema)
+ return spec.to_dict()["components"]["schemas"][cls.__name__]
Review comment:
This can go, right?
```suggestion
```
##########
File path: superset/db_engine_specs/bigquery.py
##########
@@ -39,7 +43,19 @@
)
-class BigQueryEngineSpec(BaseEngineSpec):
+class BigQueryParametersSchema(Schema):
+ credentials_json = fields.Dict(
Review comment:
Should we be more specific here, to leverage Marshmallow validation? The
credentials looks like this:
```json
{
"type": "service_account",
"project_id": "optimal-aurora-285000",
"private_key_id": "a1a0f6e452b06c145878f283fcb2d252759b97a3",
"private_key": "-----BEGIN PRIVATE KEY-----\nXXX\n-----END PRIVATE
KEY-----\n",
"client_email": "[email protected]",
"client_id": "114899578697537931695",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url":
"https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url":
"https://www.googleapis.com/robot/v1/metadata/x509/superset%40optimal-aurora-285000.iam.gserviceaccount.com"
}
```
##########
File path: superset/db_engine_specs/bigquery.py
##########
@@ -39,7 +43,19 @@
)
-class BigQueryEngineSpec(BaseEngineSpec):
+class BigQueryParametersSchema(Schema):
+ credentials_json = fields.Dict(
+ keys=fields.Str(),
+ values=fields.Raw(),
+ description=__("credentials for bigquery"),
Review comment:
```suggestion
description=__("Credentials for BigQuery"),
```
##########
File path: superset/db_engine_specs/bigquery.py
##########
@@ -282,3 +303,33 @@ def df_to_sql(
to_gbq_kwargs[key] = to_sql_kwargs[key]
pandas_gbq.to_gbq(df, **to_gbq_kwargs)
+
+ @classmethod
+ def build_sqlalchemy_url(cls, parameters: BigQueryParametersType) -> str:
+ project_id = (
+ parameters.get("credentials_json", {})
+ .get("credentials_info", {})
+ .get("project_id")
+ )
+
+ return f"{cls.drivername}://{project_id}"
Review comment:
One thing we might consider this is that we would have to pass the
credentials info in two different places: `secure_extra` and `parameters`. We
need to pass it in `secure_extra` so it's stored encrypted in the database (in
the `encrypted_extra` column). But I think this is fine for now.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]