-
Notifications
You must be signed in to change notification settings - Fork 14k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Create BigQuery Parameters for DatabaseModal #14721
Conversation
Codecov Report
@@ Coverage Diff @@
## master #14721 +/- ##
==========================================
- Coverage 77.62% 77.54% -0.08%
==========================================
Files 962 962
Lines 49017 49082 +65
Branches 6155 6155
==========================================
+ Hits 38050 38062 +12
- Misses 10763 10816 +53
Partials 204 204
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
superset/databases/api.py
Outdated
@@ -909,11 +909,13 @@ def available(self) -> Response: | |||
"preferred": engine_spec.engine in preferred_databases, | |||
} | |||
|
|||
if issubclass(engine_spec, BasicParametersMixin): | |||
payload["parameters"] = engine_spec.parameters_json_schema() | |||
if hasattr(engine_spec, "parameters_json_schema") or hasattr( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@betodealmeida let me know if this is good enough of a guard statement moving forward to make sure we don't call parameters_json_schema for engines we have implemented yet
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though I think ideally we'd have all these methods in BaseEngineSpec
and we'd check if parameters_schema
is not None
.
@@ -83,7 +83,8 @@ def run(self) -> None: | |||
|
|||
# try to connect | |||
sqlalchemy_uri = engine_spec.build_sqlalchemy_uri( | |||
self._properties["parameters"] # type: ignore | |||
self._properties["parameters"], # type: ignore | |||
self._properties.get("encrypted_extra", "{}"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to deserialize this:
serialized_encrypted_extra = self._properties.get("encrypted_extra", "{}")
try:
encrypted_extra = json.loads(serialized_encrypted_extra)
except json.decoder.JSONDecodeError:
encrypted_extra = {}
Then:
sqlalchemy_uri = engine_spec.build_sqlalchemy_uri(
self._properties["parameters"],
encrypted_extra,
)
You can then pass serialized_encrypted_extra
on line 95 below.
superset/databases/api.py
Outdated
@@ -909,11 +909,13 @@ def available(self) -> Response: | |||
"preferred": engine_spec.engine in preferred_databases, | |||
} | |||
|
|||
if issubclass(engine_spec, BasicParametersMixin): | |||
payload["parameters"] = engine_spec.parameters_json_schema() | |||
if hasattr(engine_spec, "parameters_json_schema") or hasattr( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great!
superset/databases/schemas.py
Outdated
@@ -246,6 +246,8 @@ def build_sqlalchemy_uri( | |||
the constructed SQLAlchemy URI to be passed. | |||
""" | |||
parameters = data.pop("parameters", None) | |||
encrypted_extra = data.get("encrypted_extra", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, we need to try to deserialize from JSON like above.
superset/db_engine_specs/bigquery.py
Outdated
def encrypted_field_properties(self, field: Any, **_) -> Dict[str, Any]: # type: ignore | ||
ret = {} | ||
if isinstance(field, EncryptedField): | ||
if self.openapi_version.major > 2: | ||
ret["x-encrypted-extra"] = True | ||
return ret |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this and EncryptedField
outside, since other specs will also use them. We can have them in superset/databases/schemas.py
.
superset/db_engine_specs/bigquery.py
Outdated
@classmethod | ||
def get_parameters_from_uri(cls, _: str) -> Any: | ||
# BigQuery doesn't have parameters | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally:
get_parameters_from_uri(build_sqlalchemy_uri(parameters)) == parameters
Ie, this should be the opposite of build_sqlalchemy_uri
.
We need to return credentials_info
here so that the edit form can show it to the user. This means that we need to modify get_parameters_from_uri
to also receive encrypted_extra
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment on superset/databases/schemas.py
that needs to be addresses.
superset/databases/schemas.py
Outdated
if hasattr(engine_spec, "build_sqlalchemy_uri"): | ||
data["sqlalchemy_uri"] = engine_spec.build_sqlalchemy_uri( # type: ignore | ||
parameters, encrypted_extra | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to replace lines 273-278, and inside the if
block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, excited to see this working with the new FE! I left just a few nits
Co-authored-by: Beto Dealmeida <[email protected]>
Co-authored-by: Beto Dealmeida <[email protected]>
Co-authored-by: Beto Dealmeida <[email protected]>
Co-authored-by: Beto Dealmeida <[email protected]>
* master: (163 commits) fix(native-filters): Manage default value of filters by superset (apache#14785) fix: Additional ResultSet tests (apache#14741) chore: added BasicParametersMixin to Redshift (apache#14752) fix: make dataset list sort case insensitive (apache#14528) fix: use encodeURIComponent when getting table metadata (apache#14790) fix: ensure engine is outside parameters (apache#14787) database modal should close on connect with tab layout (apache#14771) feat(native-filters): add search all filter options (apache#14710) fix: extra query in Dashboard when native filter enabled (apache#14770) chore: Improves the native filters UI/UX - iteration 2 (apache#14753) fix(native filters): Fix explore state (apache#14779) fix(explore): DndColumnSelect not handling controls with "multi: false" (apache#14737) feat: Create BigQuery Parameters for DatabaseModal (apache#14721) feat: enable user impersonation in GSheets (apache#14767) fix: add DB should not say it's Postgres (apache#14766) Revert "fix(dashboard): multiple query trigger when native filter enabled (apache#14734)" (apache#14762) feat: save database with new dynamic form (apache#14583) fix: save non-parameter DBs (apache#14759) chore: Removes ColorSchemeControl.less (apache#14199) fix(explore): Icons width (apache#14717) ...
SUMMARY
Backend piece for creating BigQuery Database connection form. In this PR, we setup a
BigQueryParametersSchema
with credential_json as a encrypted_extra field. This allows the frontend to know that this field should merged intoencrypted_extra
JSON which is needed for validate and add endpoints.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TEST PLAN
ADDITIONAL INFORMATION