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.
|
|
|
||
| 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.
@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.
Though I think ideally we'd have all these methods in BaseEngineSpec and we'd check if parameters_schema is not None.
| 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.
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.
|
|
||
| if issubclass(engine_spec, BasicParametersMixin): | ||
| payload["parameters"] = engine_spec.parameters_json_schema() | ||
| if hasattr(engine_spec, "parameters_json_schema") or hasattr( |
| 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.
Same here, we need to try to deserialize from JSON like above.
| 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.
Let's move this and EncryptedField outside, since other specs will also use them. We can have them in superset/databases/schemas.py.
| @classmethod | ||
| def get_parameters_from_uri(cls, _: str) -> Any: | ||
| # BigQuery doesn't have parameters | ||
| return None |
There was a problem hiding this comment.
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.
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
betodealmeida
left a comment
There was a problem hiding this comment.
Just a comment on superset/databases/schemas.py that needs to be addresses.
| 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.
This needs to replace lines 273-278, and inside the if block.
betodealmeida
left a comment
There was a problem hiding this comment.
Looks great, excited to see this working with the new FE! I left just a few nits
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
Co-authored-by: Beto Dealmeida <roberto@dealmeida.net>
* 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
BigQueryParametersSchemawith credential_json as a encrypted_extra field. This allows the frontend to know that this field should merged intoencrypted_extraJSON which is needed for validate and add endpoints.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TEST PLAN
ADDITIONAL INFORMATION