Skip to content
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

Merged
merged 25 commits into from
May 23, 2021
Merged

Conversation

hughhhh
Copy link
Member

@hughhhh hughhhh commented May 19, 2021

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 into encrypted_extra JSON which is needed for validate and add endpoints.

curl "http://localhost:9001/api/v1/database/available/"

{
  "databases": [
   // ...
    {
      "engine": "bigquery",
      "name": "Google BigQuery",
      "parameters": {
        "properties": {
          "credentials_info": {
            "description": "credentials.json file for BigQuery",
            "type": "string",
            "x-encrypted": true
          }
        },
        "type": "object"
      }
  ]
}

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TEST PLAN

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@codecov
Copy link

codecov bot commented May 19, 2021

Codecov Report

Merging #14721 (42e7247) into master (d71b8b3) will decrease coverage by 0.07%.
The diff coverage is 82.14%.

Impacted file tree graph

@@            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              
Flag Coverage Δ
hive 81.37% <82.14%> (-0.01%) ⬇️
javascript 72.41% <ø> (ø)
mysql 81.64% <82.14%> (-0.01%) ⬇️
postgres 81.66% <82.14%> (-0.01%) ⬇️
presto ?
python 82.03% <82.14%> (-0.16%) ⬇️
sqlite 81.27% <78.57%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/models/core.py 89.70% <ø> (-0.27%) ⬇️
superset/databases/commands/validate.py 75.00% <66.66%> (-1.00%) ⬇️
superset/db_engine_specs/bigquery.py 90.83% <76.47%> (-5.04%) ⬇️
superset/databases/api.py 92.39% <100.00%> (-0.03%) ⬇️
superset/databases/schemas.py 99.57% <100.00%> (+0.02%) ⬆️
superset/db_engine_specs/base.py 88.30% <100.00%> (ø)
superset/db_engine_specs/gsheets.py 78.94% <0.00%> (-21.06%) ⬇️
superset/db_engine_specs/presto.py 84.42% <0.00%> (-5.48%) ⬇️
superset/connectors/sqla/models.py 88.53% <0.00%> (-1.44%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d71b8b3...42e7247. Read the comment docs.

@hughhhh hughhhh changed the title save bg form feat: Create BigQuery Parameters for DatabaseModal May 21, 2021
@@ -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(
Copy link
Member Author

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

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

Copy link
Member

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.

@hughhhh hughhhh marked this pull request as ready for review May 21, 2021 02:05
@hughhhh hughhhh requested a review from betodealmeida May 21, 2021 02:06
@@ -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", "{}"),
Copy link
Member

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.

@@ -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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

@@ -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)
Copy link
Member

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.

Comment on lines 57 to 62
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
Copy link
Member

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 Show resolved Hide resolved
@classmethod
def get_parameters_from_uri(cls, _: str) -> Any:
# BigQuery doesn't have parameters
return None
Copy link
Member

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.

Copy link
Member

@betodealmeida betodealmeida left a 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/commands/validate.py Show resolved Hide resolved
Comment on lines 280 to 283
if hasattr(engine_spec, "build_sqlalchemy_uri"):
data["sqlalchemy_uri"] = engine_spec.build_sqlalchemy_uri( # type: ignore
parameters, encrypted_extra
)
Copy link
Member

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.

Copy link
Member

@betodealmeida betodealmeida left a 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

superset/databases/api.py Outdated Show resolved Hide resolved
superset/db_engine_specs/bigquery.py Outdated Show resolved Hide resolved
superset/db_engine_specs/bigquery.py Outdated Show resolved Hide resolved
superset/db_engine_specs/bigquery.py Outdated Show resolved Hide resolved
hughhhh and others added 5 commits May 23, 2021 09:36
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>
@hughhhh hughhhh merged commit 6d33432 into master May 23, 2021
amitmiran137 pushed a commit to nielsen-oss/superset that referenced this pull request May 25, 2021
* 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)
  ...
cccs-RyanS pushed a commit to CybercentreCanada/superset that referenced this pull request Dec 17, 2021
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 29, 2021
cccs-rc pushed a commit to CybercentreCanada/superset that referenced this pull request Mar 6, 2024
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.3.0 labels Mar 12, 2024
@mistercrunch mistercrunch deleted the hugh-bg-form-3 branch March 26, 2024 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 1.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants