Compare commits

...

4 Commits

Author SHA1 Message Date
Đỗ Trọng Hải
45354994a6 build(deps): update @rjsf deps to v6 (#41955)
Signed-off-by: hainenber <dotronghai96@gmail.com>
2026-07-18 10:54:40 +07:00
Abhishek Kumbhar
0f61d9a3fb fix(bigquery): ensure BigQuery client uses project from engine URI (#41975) 2026-07-17 20:05:34 -07:00
Evan Rusackas
b432f8c917 fix(docs): use modern driver package for CrateDB (#42125)
Co-authored-by: Andreas Motl <andreas.motl@crate.io>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-18 10:05:09 +07:00
Igor Shargin
25f6c6c80b fix(pivot-table): add bottom border to last grouped row (#36081)
Co-authored-by: Evan <evan@preset.io>
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Evan Rusackas <evan@rusackas.com>
2026-07-17 19:26:55 -07:00
16 changed files with 565 additions and 15 deletions

View File

@@ -10,7 +10,6 @@ updates:
- package-ecosystem: "npm"
ignore:
- dependency-name: "@rjsf/*"
# TODO: remove below entries once the application supports React >= 19.0.0
- dependency-name: "react"
update-types: ["version-update:semver-major"]
@@ -49,6 +48,23 @@ updates:
labels:
- npm
- dependabot
groups:
rjsf:
patterns:
- "@rjsf/*"
typescript-eslint:
patterns:
- "@typescript-eslint/*"
- "typescript-eslint"
babel:
patterns:
- "@babel/*"
deckgl:
patterns:
- "@deck.gl/*"
lumagl:
patterns:
- "@luma.gl/*"
open-pull-requests-limit: 30
versioning-strategy: increase
cooldown:

View File

@@ -737,6 +737,7 @@ See `superset/mcp_service/PRODUCTION.md` for deployment guides.
---
- [38358](https://github.com/apache/superset/pull/38358): Switched CrateDB PyPI package from `crate[sqlalchemy]` to `sqlalchemy-cratedb`.
- [35621](https://github.com/apache/superset/pull/35621): The default hash algorithm has changed from MD5 to SHA-256 for improved security and FedRAMP compliance. This affects cache keys for thumbnails, dashboard digests, chart digests, and filter option names. Existing cached data will be invalidated upon upgrade. To opt out of this change and maintain backward compatibility, set `HASH_ALGORITHM = "md5"` in your `superset_config.py`.
- [35062](https://github.com/apache/superset/pull/35062): Changed the function signature of `setupExtensions` to `setupCodeOverrides` with options as arguments.

View File

@@ -3672,7 +3672,7 @@
"drivers": [
{
"name": "crate",
"pypi_package": "crate[sqlalchemy]",
"pypi_package": "sqlalchemy-cratedb",
"connection_string": "crate://{host}:{port}",
"is_recommended": true
}

View File

@@ -75,7 +75,7 @@ module.exports = {
// @ant-design/colors and @ant-design/fast-color are allowed through because
// @ant-design/icons >= 6.3 deep-imports the ESM build of @ant-design/colors
// from its CJS output, so babel-jest must transform those files.
'node_modules/(?!@ant-design/(colors|fast-color)|@formatjs/.*|d3-(array|interpolate|color|time|scale|time-format|format)|internmap|@mapbox/tiny-sdf|remark-gfm|(?!@ngrx|(?!deck.gl)|d3-scale)|markdown-table|micromark-*.|decode-named-character-reference|character-entities|mdast-util-*.|unist-util-*.|ccount|escape-string-regexp|nanoid|uuid|@rjsf/*.|@x0k/.*|echarts|zrender|fetch-mock|pretty-ms|parse-ms|ol|@babel/runtime|@emotion|cheerio|cheerio/lib|parse5|dom-serializer|entities|htmlparser2|rehype-sanitize|hast-util-sanitize|unified|unist-.*|hast-.*|rehype-.*|remark-.*|mdast-.*|micromark-.*|parse-entities|property-information|space-separated-tokens|comma-separated-tokens|bail|devlop|zwitch|longest-streak|geostyler|geostyler-.*|(?!geostyler)lodash|react-error-boundary|react-json-tree|react-base16-styling|lodash-es|rbush|quickselect|react-diff-viewer-continued|storybook/*.|json-stringify-pretty-compact)',
'node_modules/(?!@ant-design/(colors|fast-color)|@formatjs/.*|d3-(array|interpolate|color|time|scale|time-format|format)|internmap|@mapbox/tiny-sdf|remark-gfm|(?!@ngrx|(?!deck.gl)|d3-scale)|markdown-table|micromark-*.|decode-named-character-reference|character-entities|mdast-util-*.|unist-util-*.|ccount|escape-string-regexp|nanoid|uuid|@rjsf/*.|@x0k/.*|echarts|zrender|fetch-mock|pretty-ms|parse-ms|ol|@babel/runtime|@emotion|cheerio|cheerio/lib|parse5|dom-serializer|entities|htmlparser2|rehype-sanitize|hast-util-sanitize|unified|unist-.*|hast-.*|rehype-.*|remark-.*|mdast-.*|micromark-.*|parse-entities|property-information|space-separated-tokens|comma-separated-tokens|bail|devlop|zwitch|longest-streak|geostyler|geostyler-.*|(?!geostyler)lodash|react-error-boundary|react-json-tree|react-base16-styling|lodash-es|rbush|quickselect|react-diff-viewer-continued|storybook/*.|json-stringify-pretty-compact|@x0k/json-schema-merge)',
],
preset: 'ts-jest',
transform: {

View File

@@ -20373,9 +20373,9 @@
"license": "Apache-2.0"
},
"node_modules/fast-equals": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/fast-equals/-/fast-equals-6.0.0.tgz",
"integrity": "sha512-PFhhIGgdM79r5Uztdj9Zb6Tt1zKafqVfdMGwVca1z5z6fbX7DmsySSuJd8HiP6I1j505DCS83cLxo5rmSNeVEA==",
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/fast-equals/-/fast-equals-6.0.2.tgz",
"integrity": "sha512-sAjhj9ZhOxYCGiNMnZLaucOqf5ZeFnHNoKoAZiD9thhJ0N8RP85qJK759/97C/3L7NzzmGVB5uiX9AUpySZmUQ==",
"license": "MIT",
"engines": {
"node": ">=6.0.0"
@@ -44218,6 +44218,10 @@
"license": "Apache-2.0",
"devDependencies": {
"@babel/types": "^7.29.7",
"@testing-library/dom": "^9.3.4",
"@testing-library/jest-dom": "*",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "*",
"@types/jest": "^30.0.0",
"jest": "^30.4.2"
},

View File

@@ -38,6 +38,10 @@
},
"devDependencies": {
"@babel/types": "^7.29.7",
"@testing-library/dom": "^9.3.4",
"@testing-library/jest-dom": "*",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "*",
"@types/jest": "^30.0.0",
"jest": "^30.4.2"
}

View File

@@ -122,6 +122,10 @@ export const Styles = styled.div<{ isDashboardEditMode: boolean }>`
vertical-align: baseline;
}
table.pvtTable tbody tr th.pvtRowLabel.pvtRowLabelLast {
border-bottom: 1px solid ${theme.colorSplit};
}
.pvtTotal,
.pvtGrandTotal {
font-weight: ${theme.fontWeightStrong};

View File

@@ -133,6 +133,7 @@ interface PivotSettings {
maxColVisible?: number;
rowAttrSpans?: number[][];
colAttrSpans?: number[][];
visibleRowCount?: number;
}
const parseLabel = (value: unknown): string | number => {
@@ -804,6 +805,7 @@ export function TableRenderer(props: TableRendererProps) {
maxColVisible: Math.max(...visibleColKeys.map((k: string[]) => k.length)),
rowAttrSpans: calcAttrSpans(visibleRowKeys, rowAttrs.length),
colAttrSpans: calcAttrSpans(visibleColKeys, colAttrs.length),
visibleRowCount: visibleRowKeys.length + (colTotals ? 1 : 0),
allowRenderHtml,
...basePivotSettings,
};
@@ -1228,6 +1230,7 @@ export function TableRenderer(props: TableRendererProps) {
rowTotalCallbacks,
namesMapping,
allowRenderHtml: settingsAllowRenderHtml,
visibleRowCount,
} = settings;
const {
@@ -1264,6 +1267,11 @@ export function TableRenderer(props: TableRendererProps) {
}
const rowSpan = rowAttrSpans![rowIdx][i];
if (rowSpan > 0) {
const isLastRow = rowIdx + rowSpan === visibleRowCount;
let cellClassName = valueCellClassName;
if (isLastRow) {
cellClassName += ' pvtRowLabelLast';
}
const flatRowKeySlice = flatKey(rowKey.slice(0, i + 1));
const colSpan =
1 + (i === settingsRowAttrs.length - 1 ? colIncrSpan : 0);
@@ -1298,7 +1306,7 @@ export function TableRenderer(props: TableRendererProps) {
return (
<th
key={`rowKeyLabel-${i}`}
className={valueCellClassName}
className={cellClassName}
style={rowHeaderStyle}
rowSpan={rowSpan}
colSpan={colSpan}

View File

@@ -0,0 +1,158 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import '@testing-library/jest-dom';
import { render } from '@testing-library/react';
import PivotTableChart from '../src/PivotTableChart';
import transformProps from '../src/plugin/transformProps';
import testData from './testData';
import { ProviderWrapper } from './testHelpers';
test('applies pvtRowLabelLast class to last data row when colTotals is disabled', () => {
const transformedProps = {
...transformProps(testData.withoutColTotals),
margin: 32,
legacy_order_by: null,
order_desc: false,
};
const { container } = render(
ProviderWrapper({
children: <PivotTableChart {...transformedProps} />,
}),
);
const tableBody = container.querySelector('tbody');
const dataRows = Array.from(tableBody?.querySelectorAll('tr') ?? []).filter(
row => !row.classList.contains('pvtRowTotals'),
);
// Get the last data row
const lastDataRow = dataRows[dataRows.length - 1];
expect(lastDataRow).toBeInTheDocument();
// Check if any cell in the last data row has pvtRowLabelLast class
const lastRowCells = lastDataRow.querySelectorAll('th.pvtRowLabel');
const hasLastClass = Array.from(lastRowCells).some(cell =>
cell.classList.contains('pvtRowLabelLast'),
);
expect(hasLastClass).toBe(true);
});
test('does not apply pvtRowLabelLast class to last data row when colTotals is enabled', () => {
const transformedProps = {
...transformProps(testData.withColTotals),
margin: 32,
legacy_order_by: null,
order_desc: false,
};
const { container } = render(
ProviderWrapper({
children: <PivotTableChart {...transformedProps} />,
}),
);
const tableBody = container.querySelector('tbody');
const dataRows = Array.from(tableBody?.querySelectorAll('tr') ?? []).filter(
row => !row.classList.contains('pvtRowTotals'),
);
// Get the last data row (before totals row)
const lastDataRow = dataRows[dataRows.length - 1];
expect(lastDataRow).toBeInTheDocument();
// Check if any cell in the last data row has pvtRowLabelLast class
const lastRowCells = lastDataRow.querySelectorAll('th.pvtRowLabel');
const hasLastClass = Array.from(lastRowCells).some(cell =>
cell.classList.contains('pvtRowLabelLast'),
);
// Should NOT have the class because totals row will have the border
expect(hasLastClass).toBe(false);
// Verify totals row exists
const totalsRow = container.querySelector('tr.pvtRowTotals');
expect(totalsRow).toBeInTheDocument();
});
test('applies pvtRowLabelLast to the spanning outer <th> that bottoms out the table', () => {
// Two row dimensions ([country, city]) so the "Spain" outer <th> spans two
// data rows (rowSpan 2). This is the merged-cell case #36031 is about; the
// existing flat fixtures (every rowSpan 1) never exercise it.
const transformedProps = {
...transformProps(testData.groupedRowsWithoutColTotals),
margin: 32,
legacy_order_by: null,
order_desc: false,
};
const { container } = render(
ProviderWrapper({
children: <PivotTableChart {...transformedProps} />,
}),
);
// Find the outer row-label <th> that spans multiple data rows.
const spanningLabels = Array.from(
container.querySelectorAll('tbody th.pvtRowLabel'),
).filter(cell => Number(cell.getAttribute('rowspan')) >= 2);
// Sanity check: the fixture actually produced a merged cell.
expect(spanningLabels.length).toBeGreaterThan(0);
const spanningCell = spanningLabels[spanningLabels.length - 1];
expect(spanningCell).toHaveTextContent('Spain');
expect(spanningCell.getAttribute('rowspan')).toBe('2');
// The spanning cell bottoms out the table (rowIdx + rowSpan === visibleRowCount)
// so it must carry the border class.
expect(spanningCell).toHaveClass('pvtRowLabelLast');
});
test('withholds pvtRowLabelLast from the spanning <th> when colTotals owns the bottom', () => {
const transformedProps = {
...transformProps(testData.groupedRowsWithColTotals),
margin: 32,
legacy_order_by: null,
order_desc: false,
};
const { container } = render(
ProviderWrapper({
children: <PivotTableChart {...transformedProps} />,
}),
);
const spanningLabels = Array.from(
container.querySelectorAll('tbody th.pvtRowLabel'),
).filter(cell => Number(cell.getAttribute('rowspan')) >= 2);
expect(spanningLabels.length).toBeGreaterThan(0);
const spanningCell = spanningLabels[spanningLabels.length - 1];
expect(spanningCell).toHaveTextContent('Spain');
// The totals row now bottoms out the table, so no row-label <th> should get
// the border class.
const anyLabelHasLastClass = Array.from(
container.querySelectorAll('tbody th.pvtRowLabel'),
).some(cell => cell.classList.contains('pvtRowLabelLast'));
expect(anyLabelHasLastClass).toBe(false);
// The totals row owns the bottom edge instead.
const totalsRow = container.querySelector('tr.pvtRowTotals');
expect(totalsRow).toBeInTheDocument();
});

View File

@@ -0,0 +1,232 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import {
ChartDataResponseResult,
ChartProps,
DatasourceType,
VizType,
QueryFormData,
} from '@superset-ui/core';
import { supersetTheme } from '@apache-superset/core/theme';
import { GenericDataType } from '@apache-superset/core/common';
const basicFormData: QueryFormData = {
datasource: '1__table',
viz_type: VizType.PivotTable,
groupbyRows: ['country'],
groupbyColumns: ['city'],
metrics: ['SUM(sales)'],
metricsLayout: 'COLUMNS',
rowOrder: 'key_a_to_z',
colOrder: 'key_a_to_z',
aggregateFunction: 'Sum',
rowSubTotals: false,
colTotals: true,
colSubTotals: false,
rowTotals: true,
valueFormat: 'SMART_NUMBER',
dateFormat: 'smart_date',
transposePivot: false,
combineMetric: false,
rowSubtotalPosition: false,
colSubtotalPosition: false,
};
const basicChartProps = {
width: 800,
height: 600,
datasource: {
id: 1,
name: 'test_dataset',
type: DatasourceType.Table,
columns: [],
metrics: [],
columnFormats: {},
verboseMap: {},
},
hooks: {},
initialValues: {},
queriesData: [
{
data: {
columns: [],
records: [],
},
},
],
formData: basicFormData,
theme: supersetTheme,
};
const basicQueryResult: ChartDataResponseResult = {
annotation_data: null,
cache_key: null,
cached_dttm: null,
cache_timeout: null,
data: [],
colnames: [],
coltypes: [],
error: null,
is_cached: false,
query: 'SELECT ...',
rowcount: 100,
sql_rowcount: 100,
stacktrace: null,
status: 'success',
from_dttm: null,
to_dttm: null,
queried_dttm: null,
};
// Shared test data
const pivotData = [
{ country: 'France', city: 'Paris', 'SUM(sales)': 1000 },
{ country: 'Germany', city: 'Berlin', 'SUM(sales)': 2000 },
{ country: 'Spain', city: 'Madrid', 'SUM(sales)': 1500 },
{ country: 'Italy', city: 'Rome', 'SUM(sales)': 3000 },
{ country: 'UK', city: 'London', 'SUM(sales)': 2500 },
];
// Shared query result structure
const basicQueriesData = [
{
...basicQueryResult,
colnames: ['country', 'city', 'SUM(sales)'],
coltypes: [
GenericDataType.String,
GenericDataType.String,
GenericDataType.Numeric,
],
data: pivotData,
},
];
/**
* Pivot table data with colTotals enabled
*/
const withColTotals = {
...new ChartProps({
...basicChartProps,
formData: {
...basicFormData,
colTotals: true,
rowTotals: true,
rowSubTotals: false,
colSubTotals: false,
},
}),
queriesData: basicQueriesData,
};
/**
* Pivot table data without colTotals
*/
const withoutColTotals = {
...new ChartProps({
...basicChartProps,
formData: {
...basicFormData,
colTotals: false,
rowTotals: false,
rowSubTotals: false,
colSubTotals: false,
},
}),
queriesData: basicQueriesData,
};
/**
* Two-dimension rows data so an outer row-label <th> spans multiple data rows.
* Grouped by [country, city] with "Spain" (last alphabetically) owning two
* cities, so the "Spain" <th> has rowSpan >= 2 and bottoms out the table.
*
* visibleRowKeys order (rowOrder key_a_to_z):
* 0: [France, Paris]
* 1: [Germany, Berlin]
* 2: [Spain, Barcelona]
* 3: [Spain, Madrid]
*/
const groupedRowsData = [
{ country: 'France', city: 'Paris', 'SUM(sales)': 1000 },
{ country: 'Germany', city: 'Berlin', 'SUM(sales)': 2000 },
{ country: 'Spain', city: 'Barcelona', 'SUM(sales)': 1200 },
{ country: 'Spain', city: 'Madrid', 'SUM(sales)': 1500 },
];
const groupedRowsQueriesData = [
{
...basicQueryResult,
colnames: ['country', 'city', 'SUM(sales)'],
coltypes: [
GenericDataType.String,
GenericDataType.String,
GenericDataType.Numeric,
],
data: groupedRowsData,
},
];
const groupedRowsFormData: QueryFormData = {
...basicFormData,
groupbyRows: ['country', 'city'],
groupbyColumns: [],
};
/**
* Two row dimensions, colTotals disabled: the bottom-most spanning <th>
* ("Spain", rowSpan 2) should own the bottom edge.
*/
const groupedRowsWithoutColTotals = {
...new ChartProps({
...basicChartProps,
formData: {
...groupedRowsFormData,
colTotals: false,
rowTotals: false,
rowSubTotals: false,
colSubTotals: false,
},
}),
queriesData: groupedRowsQueriesData,
};
/**
* Two row dimensions, colTotals enabled: the totals row owns the bottom edge,
* so no row-label <th> (spanning or otherwise) gets pvtRowLabelLast.
*/
const groupedRowsWithColTotals = {
...new ChartProps({
...basicChartProps,
formData: {
...groupedRowsFormData,
colTotals: true,
rowTotals: false,
rowSubTotals: false,
colSubTotals: false,
},
}),
queriesData: groupedRowsQueriesData,
};
export default {
withColTotals,
withoutColTotals,
groupedRowsWithoutColTotals,
groupedRowsWithColTotals,
};

View File

@@ -0,0 +1,37 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import {
supersetTheme,
ThemeProvider,
EmotionCacheProvider,
createEmotionCache,
} from '@apache-superset/core/theme';
const emotionCache = createEmotionCache({
key: 'test',
});
export function ProviderWrapper(props: any) {
const { children, theme = supersetTheme } = props;
return (
<EmotionCacheProvider value={emotionCache}>
<ThemeProvider theme={theme}>{children}</ThemeProvider>
</EmotionCacheProvider>
);
}

View File

@@ -0,0 +1,9 @@
{
"compilerOptions": {
"composite": false,
"emitDeclarationOnly": false,
"rootDir": "../../../"
},
"extends": "../../../tsconfig.json",
"include": ["**/*", "../types/**/*", "../../../types/**/*"]
}

View File

@@ -18,8 +18,8 @@
*/
import { FunctionComponent, useState, useRef, ChangeEvent } from 'react';
import SchemaForm, { FormProps } from '@rjsf/core';
import { FormValidation } from '@rjsf/utils';
import SchemaForm from '@rjsf/core';
import { type FormValidation } from '@rjsf/utils';
import validator from '@rjsf/validator-ajv8';
import { t } from '@apache-superset/core/translation';
import { styled } from '@apache-superset/core/theme';
@@ -74,10 +74,13 @@ const getValidationRules = () => scheduledQueriesConf?.VALIDATION || [];
const getValidator = () => {
const rules: any = getValidationRules();
return (formData: Record<string, any>, errors: FormValidation) => {
return (
formData: Record<string, any> | undefined,
errors: FormValidation,
) => {
rules.forEach((rule: any) => {
const test = validators[rule.name as keyof typeof validators];
const args = rule.arguments.map((name: string) => formData[name]);
const args = rule.arguments.map((name: string) => formData?.[name]);
const container = rule.container || rule.arguments.slice(-1)[0];
if (!test(args[0], args[1])) {
errors[container]?.addError(rule.message);
@@ -160,7 +163,7 @@ const ScheduleQueryButton: FunctionComponent<ScheduleQueryButtonProps> = ({
const onScheduleSubmit = ({
formData,
}: {
formData?: Omit<FormProps<Record<string, any>>, 'schema'>;
formData?: Record<string, any>;
}) => {
const query = {
label,

View File

@@ -728,15 +728,17 @@ class BigQueryEngineSpec(BaseEngineSpec): # pylint: disable=too-many-public-met
"Could not import libraries needed to connect to BigQuery."
)
project: str | None = engine.url.host or None
if credentials_info := engine.dialect.credentials_info:
credentials = service_account.Credentials.from_service_account_info(
credentials_info
)
return bigquery.Client(credentials=credentials)
return bigquery.Client(credentials=credentials, project=project)
try:
credentials = google.auth.default()[0]
return bigquery.Client(credentials=credentials)
return bigquery.Client(credentials=credentials, project=project)
except google.auth.exceptions.DefaultCredentialsError as ex:
raise SupersetDBAPIConnectionError(
"The database credentials could not be found."

View File

@@ -49,7 +49,7 @@ class CrateEngineSpec(BaseEngineSpec):
"drivers": [
{
"name": "crate",
"pypi_package": "crate[sqlalchemy]",
"pypi_package": "sqlalchemy-cratedb",
"connection_string": "crate://{host}:{port}",
"is_recommended": True,
},

View File

@@ -430,6 +430,78 @@ def test_get_default_catalog(mocker: MockerFixture) -> None:
assert BigQueryEngineSpec.get_default_catalog(database) == "project"
@pytest.mark.parametrize(
("sqlalchemy_uri", "schema", "expected_project"),
[
("bigquery://uri-project", None, "uri-project"),
("bigquery:///uri-project", None, "uri-project"),
("bigquery://", "dataset_name", None),
],
)
def test_get_client_resolves_uri_project_with_service_account_credentials(
mocker: MockerFixture,
sqlalchemy_uri: str,
schema: str | None,
expected_project: str | None,
) -> None:
"""Test that service-account clients use the project from the engine URI."""
from superset.db_engine_specs.bigquery import BigQueryEngineSpec
credentials_info = {"project_id": "credential-project"}
credentials = mock.Mock()
engine = mock.MagicMock()
engine.url = BigQueryEngineSpec.adjust_engine_params(
make_url(sqlalchemy_uri), {}, schema=schema
)[0]
engine.dialect.credentials_info = credentials_info
create_credentials = mocker.patch(
"superset.db_engine_specs.bigquery.service_account.Credentials."
"from_service_account_info",
return_value=credentials,
)
client = mocker.patch("superset.db_engine_specs.bigquery.bigquery.Client")
BigQueryEngineSpec._get_client(engine, mock.Mock())
create_credentials.assert_called_once_with(credentials_info)
client.assert_called_once_with(credentials=credentials, project=expected_project)
@pytest.mark.parametrize(
("sqlalchemy_uri", "schema", "expected_project"),
[
("bigquery://uri-project", None, "uri-project"),
("bigquery:///uri-project", None, "uri-project"),
("bigquery://", "dataset_name", None),
],
)
def test_get_client_resolves_uri_project_with_application_default_credentials(
mocker: MockerFixture,
sqlalchemy_uri: str,
schema: str | None,
expected_project: str | None,
) -> None:
"""Test that ADC clients use the project from the engine URI."""
from superset.db_engine_specs.bigquery import BigQueryEngineSpec
credentials = mock.Mock()
engine = mock.MagicMock()
engine.url = BigQueryEngineSpec.adjust_engine_params(
make_url(sqlalchemy_uri), {}, schema=schema
)[0]
engine.dialect.credentials_info = None
get_default_credentials = mocker.patch(
"superset.db_engine_specs.bigquery.google.auth.default",
return_value=(credentials, "credential-project"),
)
client = mocker.patch("superset.db_engine_specs.bigquery.bigquery.Client")
BigQueryEngineSpec._get_client(engine, mock.Mock())
get_default_credentials.assert_called_once_with()
client.assert_called_once_with(credentials=credentials, project=expected_project)
def test_get_time_partition_column_uses_catalog_in_table_reference(
mocker: MockerFixture,
) -> None: