aminghadersohi commented on code in PR #43870: URL: https://github.com/apache/superset/pull/43870#discussion_r4165362486
########## superset-frontend/src/components/Datasource/components/DatasourceEditor/components/PartitionFilterMapping/utils.ts: ########## @@ -0,0 +1,510 @@ +/** + * 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 { t } from '@apache-superset/core/translation'; +import type { + PartitionMappingColumn, + PartitionMappingDatasource, + PartitionMappingIssue, + PartitionRowState, +} from './types'; + +/** + * Jinja delimiters. + * + * A transform is evaluated in a different context and at a different time from + * the chart query, so a template would not render the same way -- the backend + * rejects one outright. Shared so the check that declines to preview a Jinja + * transform and the check that blocks saving it cannot drift apart. + */ +const JINJA_PATTERN = /\{\{|\{%|\{#/; + +/** + * The column whose filters are mirrored. + * + * `partition_mapped_column` is an explicit override; `null` means "follow the + * default datetime column", so re-pointing that column moves the mapping with + * it. Mirrors `SqlaTable.partition_filter_mapping_summary` on the backend. + */ +export function resolveMappedColumn( + datasource: PartitionMappingDatasource, +): string | null { + if (!datasource.partition_column) { + return null; + } + return datasource.partition_mapped_column || datasource.main_dttm_col || null; +} + +/** Whether the mapped column came from `main_dttm_col` rather than an override. */ +export function mappedColumnIsImplicit( + datasource: PartitionMappingDatasource, +): boolean { + return Boolean( + datasource.partition_column && + !datasource.partition_mapped_column && + datasource.main_dttm_col, + ); +} + +/** + * Whether the mapping will actually mirror anything. + * + * Drives the choice between the green "filters will automatically apply" + * message and the warning that nothing is mirrored yet, so "non-blank text in + * the box" is not a good enough test: a transform with no `:value` to + * substitute, or one carrying Jinja, is as inert as an empty one and the + * backend's own summary reports it inactive. Claiming otherwise tells an owner + * their queries are pruning when they are not. + * + * Shares `transformCanPreview`'s conditions rather than restating them, and is + * necessary rather than sufficient for the same reason: an unparseable + * expression or a non-deterministic function needs a SQL parser to spot, so the + * server stays the authority -- `valueTransformIssues` surfaces what it says at + * the transform field itself. + */ +export function mappingIsActive( + datasource: PartitionMappingDatasource, + columns: PartitionMappingColumn[], +): boolean { + const mappedColumnName = resolveMappedColumn(datasource); + if (!mappedColumnName || mappedColumnName === datasource.partition_column) { + return false; + } + const mappedColumn = columns.find( + column => column.column_name === mappedColumnName, + ); + return transformCanPreview( Review Comment: `lint-frontend` and `pre-commit` fail here: oxlint `no-use-before-define`, because `transformCanPreview` is declared below this call. Move its declaration above `mappingIsActive`. That moves ~25 lines, so it doesn't fit a suggestion. ########## tests/integration_tests/datasets/api_tests.py: ########## @@ -802,6 +802,7 @@ def test_info_security_dataset(self): "can_get_or_create_dataset", "can_warm_up_cache", "can_get_drill_info", + "can_partition_mapping_preview", Review Comment: All three Python legs fail `test_info_security_dataset` on this line. Preview is remapped to `"write"` in `method_permission_name`, so `can_partition_mapping_preview` never exists. ```suggestion ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
