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

chore: switching out ConnectorRegistry references for DatasourceDAO #20380

Merged
merged 32 commits into from
Jun 21, 2022

Conversation

hughhhh
Copy link
Member

@hughhhh hughhhh commented Jun 14, 2022

SUMMARY

Switching out all references of ConnectorRegistry to DatasourceDAO. In the PR, we are focusing on just removing the references and moving towards allowing other Datasources to power charts.

One issue is the circular dependencies that are blocking us from fully removing the logic to allow the app to run. So i've moved that code out the ConnectorRegistry for now and will prioritize a bigger refactor to stop the import issues in superset moving forward.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • 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

@hughhhh hughhhh changed the title Connreg to datadao 2 chore: switching out ConnectorRegistry references for DatasourceDAO Jun 14, 2022
@@ -82,7 +82,6 @@ def _create_energy_table():
table.metrics.append(
SqlMetric(metric_name="sum__value", expression=f"SUM({col})")
)

Copy link
Member

Choose a reason for hiding this comment

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

nit: We could keep this in here.

# todo(hughhhh): fully remove the datasource config register
for module_name, class_names in module_datasource_map.items():
class_names = [str(s) for s in class_names]
__import__(module_name, fromlist=class_names)
Copy link
Member

Choose a reason for hiding this comment

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

I was thinking that we wouldn't have to init anything to make this work?

Copy link
Member

Choose a reason for hiding this comment

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

We should be able to remove the DEFAULT_MODULE_DS_MAP and ADDITIONAL_MODULE_DS_MAP for SIP68

Copy link
Member Author

Choose a reason for hiding this comment

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

for some reason the app won't without this code being here, can we put that into another ticket?

@@ -407,16 +408,18 @@ def export_dashboards( # pylint: disable=too-many-locals
id_ = target.get("datasetId")
if id_ is None:
continue
datasource = ConnectorRegistry.get_datasource_by_id(session, id_)
datasource = DatasourceDAO.get_datasource(
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.. I don't think we need to use the DatasourceDAO if there's only one type that will be used.


BASE_URL = "https://github.com/apache-superset/examples-data/blob/master/"

misc_dash_slices: Set[str] = set() # slices assembled in a 'Misc Chart' dashboard


def get_table_connector_registry() -> Any:
return ConnectorRegistry.sources["table"]
return DatasourceDAO.sources[DatasourceType.TABLE]
Copy link
Member

Choose a reason for hiding this comment

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

can we use sqlatable lookup directly instead of the DatasourceDAO since it's only one type?

@@ -35,7 +36,7 @@ def get_table(
schema: Optional[str] = None,
):
schema = schema or get_example_default_schema()
table_source = ConnectorRegistry.sources["table"]
table_source = DatasourceDAO.sources[DatasourceType.TABLE]
Copy link
Member

Choose a reason for hiding this comment

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

why not just import SQLATable here directly?

@@ -54,7 +55,7 @@ def create_table_metadata(

table = get_table(table_name, database, schema)
if not table:
table_source = ConnectorRegistry.sources["table"]
table_source = DatasourceDAO.sources[DatasourceType.TABLE]
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

@@ -256,8 +258,8 @@ def test_external_metadata_error_return_400(self, mock_get_datasource):

pytest.raises(
SupersetGenericDBErrorException,
lambda: ConnectorRegistry.get_datasource(
"table", tbl.id, db.session
lambda: DatasourceDAO.get_datasource(
Copy link
Member

Choose a reason for hiding this comment

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

can we query just sqlatable here?

@codecov
Copy link

codecov bot commented Jun 15, 2022

Codecov Report

Merging #20380 (6830f9c) into master (41f33a3) will decrease coverage by 0.10%.
The diff coverage is 61.64%.

❗ Current head 6830f9c differs from pull request most recent head ed31bf1. Consider uploading reports for the commit ed31bf1 to get more accurate results

@@            Coverage Diff             @@
##           master   #20380      +/-   ##
==========================================
- Coverage   66.64%   66.53%   -0.11%     
==========================================
  Files        1729     1738       +9     
  Lines       64904    65062     +158     
  Branches     6842     6897      +55     
==========================================
+ Hits        43257    43292      +35     
- Misses      19897    20017     +120     
- Partials     1750     1753       +3     
Flag Coverage Δ
hive ?
mysql 82.35% <93.10%> (+0.07%) ⬆️
postgres 82.42% <93.10%> (+0.07%) ⬆️
presto ?
python 82.47% <93.10%> (-0.31%) ⬇️
sqlite ?
unit ?

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

Impacted Files Coverage Δ
...art-controls/src/operators/contributionOperator.ts 100.00% <ø> (ø)
...ui-chart-controls/src/operators/flattenOperator.ts 100.00% <ø> (ø)
...ui-chart-controls/src/operators/prophetOperator.ts 100.00% <ø> (ø)
...i-chart-controls/src/operators/resampleOperator.ts 100.00% <ø> (ø)
...art-controls/src/sections/annotationsAndLayers.tsx 100.00% <ø> (ø)
.../shared-controls/components/RadioButtonControl.tsx 0.00% <ø> (ø)
...chart-controls/src/shared-controls/dndControls.tsx 26.92% <0.00%> (-8.98%) ⬇️
...ages/superset-ui-core/src/query/types/Dashboard.ts 100.00% <ø> (ø)
...egacy-plugin-chart-event-flow/src/controlPanel.tsx 14.28% <0.00%> (ø)
.../legacy-plugin-chart-world-map/src/controlPanel.ts 25.00% <0.00%> (-8.34%) ⬇️
... and 164 more

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 41f33a3...ed31bf1. Read the comment docs.

@hughhhh hughhhh force-pushed the connreg-to-datadao_2 branch from d4c13be to fe33b5f Compare June 15, 2022 08:17
@hughhhh hughhhh force-pushed the connreg-to-datadao_2 branch from fe33b5f to 64ecbfe Compare June 15, 2022 08:41
DatasetNotFoundError,
lambda: ConnectorRegistry.get_datasource("table", 9999999, db.session),
DatasourceNotFound,
lambda: DatasourceDAO.get_datasource(db.session, "table", 9999999),
Copy link
Member Author

@hughhhh hughhhh Jun 16, 2022

Choose a reason for hiding this comment

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

These are testing the actual function calls inside the views/datasource.py files which call DatasourceDAO now

https://github.com/apache/superset/pull/20380/files#diff-bea5cc1ab7cb7816bd17972ec665905f07a35f2c4cd77cd962d5db580a8640bcL77

@hughhhh hughhhh merged commit e3e37cb into apache:master Jun 21, 2022
akshatsri pushed a commit to charan1314/superset that referenced this pull request Jul 19, 2022
…pache#20380)

* rename and move dao file

* Update dao.py

* add cachekey

* Update __init__.py

* change reference in query context test

* add utils ref

* more ref changes

* add helpers

* add todo in dashboard.py

* add cachekey

* circular import error in dar.py

* push rest of refs

* fix linting

* fix more linting

* update enum

* remove references for connector registry

* big reafctor

* take value

* fix

* test to see if removing value works

* delete connectregistry

* address concerns

* address comments

* fix merge conflicts

* address concern II

* address concern II

* fix test

Co-authored-by: Phillip Kelley-Dotson <pkelleydotson@yahoo.com>
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 labels Mar 13, 2024
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/XL 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants