feat(SIP-95): new endpoint for table metadata (#28122)

This commit is contained in:
Beto Dealmeida
2024-04-25 12:23:49 -04:00
committed by GitHub
parent 52f8734662
commit 6cf681df68
71 changed files with 1048 additions and 513 deletions

View File

@@ -30,7 +30,7 @@ from superset.db_engine_specs.base import (
from superset.db_engine_specs.mysql import MySQLEngineSpec
from superset.db_engine_specs.sqlite import SqliteEngineSpec
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
from superset.sql_parse import ParsedQuery
from superset.sql_parse import ParsedQuery, Table
from superset.utils.database import get_example_database
from tests.integration_tests.db_engine_specs.base_tests import TestDbEngineSpec
from tests.integration_tests.test_app import app
@@ -238,7 +238,7 @@ class TestDbEngineSpecs(TestDbEngineSpec):
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_column_datatype_to_string(self):
example_db = get_example_database()
sqla_table = example_db.get_table("energy_usage")
sqla_table = example_db.get_table(Table("energy_usage"))
dialect = example_db.get_dialect()
# TODO: fix column type conversion for presto.
@@ -540,8 +540,7 @@ def test_get_indexes():
BaseEngineSpec.get_indexes(
database=mock.Mock(),
inspector=inspector,
table_name="bar",
schema="foo",
table=Table("bar", "foo"),
)
== indexes
)

View File

@@ -165,8 +165,7 @@ class TestBigQueryDbEngineSpec(TestDbEngineSpec):
BigQueryEngineSpec.get_indexes(
database,
inspector,
table_name,
schema,
Table(table_name, schema),
)
== []
)
@@ -184,8 +183,7 @@ class TestBigQueryDbEngineSpec(TestDbEngineSpec):
assert BigQueryEngineSpec.get_indexes(
database,
inspector,
table_name,
schema,
Table(table_name, schema),
) == [
{
"name": "partition",
@@ -207,8 +205,7 @@ class TestBigQueryDbEngineSpec(TestDbEngineSpec):
assert BigQueryEngineSpec.get_indexes(
database,
inspector,
table_name,
schema,
Table(table_name, schema),
) == [
{
"name": "partition",

View File

@@ -23,7 +23,7 @@ from sqlalchemy.sql import select
from superset.db_engine_specs.hive import HiveEngineSpec, upload_to_s3
from superset.exceptions import SupersetException
from superset.sql_parse import Table, ParsedQuery
from superset.sql_parse import ParsedQuery, Table
from tests.integration_tests.test_app import app
@@ -328,7 +328,10 @@ def test_where_latest_partition(mock_method):
columns = [{"name": "ds"}, {"name": "hour"}]
with app.app_context():
result = HiveEngineSpec.where_latest_partition(
"test_table", "test_schema", database, select(), columns
database,
Table("test_table", "test_schema"),
select(),
columns,
)
query_result = str(result.compile(compile_kwargs={"literal_binds": True}))
assert "SELECT \nWHERE ds = '01-01-19' AND hour = 1" == query_result
@@ -341,7 +344,10 @@ def test_where_latest_partition_super_method_exception(mock_method):
columns = [{"name": "ds"}, {"name": "hour"}]
with app.app_context():
result = HiveEngineSpec.where_latest_partition(
"test_table", "test_schema", database, select(), columns
database,
Table("test_table", "test_schema"),
select(),
columns,
)
assert result is None
mock_method.assert_called()
@@ -353,7 +359,9 @@ def test_where_latest_partition_no_columns_no_values(mock_method):
db = mock.Mock()
with app.app_context():
result = HiveEngineSpec.where_latest_partition(
"test_table", "test_schema", db, select()
db,
Table("test_table", "test_schema"),
select(),
)
assert result is None

View File

@@ -530,7 +530,7 @@ def test_get_catalog_names(app_context: AppContext) -> None:
if database.backend != "postgresql":
return
with database.get_inspector_with_context() as inspector:
with database.get_inspector() as inspector:
assert PostgresEngineSpec.get_catalog_names(database, inspector) == [
"postgres",
"superset",

View File

@@ -82,7 +82,7 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
row = mock.Mock()
row.Column, row.Type, row.Null = column
inspector.bind.execute.return_value.fetchall = mock.Mock(return_value=[row])
results = PrestoEngineSpec.get_columns(inspector, "", "")
results = PrestoEngineSpec.get_columns(inspector, Table("", ""))
self.assertEqual(len(expected_results), len(results))
for expected_result, result in zip(expected_results, results):
self.assertEqual(expected_result[0], result["column_name"])
@@ -573,7 +573,10 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
db.get_df = mock.Mock(return_value=df)
columns = [{"name": "ds"}, {"name": "hour"}]
result = PrestoEngineSpec.where_latest_partition(
"test_table", "test_schema", db, select(), columns
db,
Table("test_table", "test_schema"),
select(),
columns,
)
query_result = str(result.compile(compile_kwargs={"literal_binds": True}))
self.assertEqual("SELECT \nWHERE ds = '01-01-19' AND hour = 1", query_result)
@@ -802,7 +805,7 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
return_value=["a", "b"]
)
table_name = "table_name"
result = PrestoEngineSpec._show_columns(inspector, table_name, None)
result = PrestoEngineSpec._show_columns(inspector, Table(table_name))
assert result == ["a", "b"]
inspector.bind.execute.assert_called_once_with(
f'SHOW COLUMNS FROM "{table_name}"'
@@ -818,7 +821,7 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
)
table_name = "table_name"
schema = "schema"
result = PrestoEngineSpec._show_columns(inspector, table_name, schema)
result = PrestoEngineSpec._show_columns(inspector, Table(table_name, schema))
assert result == ["a", "b"]
inspector.bind.execute.assert_called_once_with(
f'SHOW COLUMNS FROM "{schema}"."{table_name}"'
@@ -846,9 +849,16 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
{"col1": "val1"},
{"col2": "val2"},
]
PrestoEngineSpec.select_star(database, table_name, engine, cols=cols)
PrestoEngineSpec.select_star(database, Table(table_name), engine, cols=cols)
mock_select_star.assert_called_once_with(
database, table_name, engine, None, 100, False, True, True, cols
database,
Table(table_name),
engine,
100,
False,
True,
True,
cols,
)
@mock.patch("superset.db_engine_specs.presto.is_feature_enabled")
@@ -869,13 +879,16 @@ class TestPrestoDbEngineSpec(TestDbEngineSpec):
{"column_name": ".val2."},
]
PrestoEngineSpec.select_star(
database, table_name, engine, show_cols=True, cols=cols
database,
Table(table_name),
engine,
show_cols=True,
cols=cols,
)
mock_select_star.assert_called_once_with(
database,
table_name,
Table(table_name),
engine,
None,
100,
True,
True,
@@ -1172,7 +1185,7 @@ def test_get_catalog_names(app_context: AppContext) -> None:
if database.backend != "presto":
return
with database.get_inspector_with_context() as inspector:
with database.get_inspector() as inspector:
assert PrestoEngineSpec.get_catalog_names(database, inspector) == [
"jmx",
"memory",