World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#11922] improvement(web-v2): Show AWS Glue properties on the catalog edit page (#13706)
dennismdejongdc1b861a17bf
diff --git a/web-v2/web/src/app/catalogs/rightContent/CreateCatalogDialog.js b/web-v2/web/src/app/catalogs/rightContent/CreateCatalogDialog.jsindex 92dfeb5dfe..3ab2eab3d1 100644--- a/web-v2/web/src/app/catalogs/rightContent/CreateCatalogDialog.js+++ b/web-v2/web/src/app/catalogs/rightContent/CreateCatalogDialog.js@@ -44,6 +44,7 @@ import {sensitiveCatalogPropertyKeys} from '@/config/catalog'import { nameRegex } from '@/lib/utils/regex'+import { buildCatalogProperties, isCatalogPropertyHidden, isCatalogRequiredField } from '@/lib/utils/catalogProperties'import { useResetFormOnCloseModal } from '@/lib/hooks/use-reset'import { genUpdates } from '@/lib/utils'import { cn } from '@/lib/utils/tailwind'@@ -78,12 +79,7 @@ export default function CreateCatalogDialog({ ...props }) {const dispatch = useAppDispatch()const isShowTestConnect = ['fileset', 'model'].includes(catalogType) || currentProvider === 'lakehouse-generic'- const isRequiredField = prop => {- return (- prop.required ||- (prop.key === 'warehouse' && currentProvider === 'lakehouse-iceberg' && ['hive', 'jdbc'].includes(catalogBackend))- )- }+ const isRequiredField = prop => isCatalogRequiredField(prop, { currentProvider, catalogBackend })const defaultValues = {name: '',@@ -113,22 +109,14 @@ export default function CreateCatalogDialog({ ...props }) {setCurrentStep)- const isHidden = prop => {- const { parentField, hide, key } = prop-- // In edit mode, hide props not present in the loaded catalog response- if (editCatalog && cacheData?.properties && !(key in cacheData.properties)) {- return true- }- switch (parentField) {- case 'catalog-backend':- return catalogBackend && hide && hide.includes(catalogBackend)- case 'authentication.type':- return !authType || (hide && hide.includes(authType))- default:- return !(!editCatalog || ['region', 'location'].includes(key) || isRequiredField(prop))- }- }+ const isHidden = prop =>+ isCatalogPropertyHidden(prop, {+ editCatalog,+ catalogProperties: cacheData?.properties,+ catalogBackend,+ authType,+ currentProvider+ })const handScroll = () => {if (scrollRef.current) {@@ -252,17 +240,12 @@ export default function CreateCatalogDialog({ ...props }) {type: catalogType,provider: values.provider,comment: values.comment,- properties: [...values.properties, ...defaultProps].reduce((acc, item) => {- if (item.key === 'location' || item.key.startsWith('location-')) {- if (item.value) {- acc[item.key] = item.prefix ? item.prefix + item.value : item.value- }- } else {- acc[item.key] = values[item.key] || (item.value instanceof Array ? item.value.join(',') : item.value)- }-- return acc- }, {})+ properties: buildCatalogProperties({+ values,+ defaultProps,+ editCatalog: Boolean(editCatalog),+ catalogProperties: cacheData?.properties || {}+ })}}@@ -543,7 +526,7 @@ export default function CreateCatalogDialog({ ...props }) {{prop.select ? (<Selectdata-refer={`catalog-props-${prop.key}`}- disabled={editCatalog && prop.required}+ disabled={editCatalog && (prop.required || prop.immutable)}placeholder={prop.description ? prop.description : ''}>{prop.select?.map(item => (@@ -556,7 +539,7 @@ export default function CreateCatalogDialog({ ...props }) {<Inputdata-refer={`catalog-props-${prop.key}`}placeholder={prop.description ? prop.description : ''}- disabled={prop.disabled}+ disabled={prop.disabled || (editCatalog && prop.immutable)}type={sensitiveCatalogPropertyKeys.includes(prop.key) ? 'password' : 'text'}/>)}diff --git a/web-v2/web/src/config/catalog.js b/web-v2/web/src/config/catalog.jsindex 41c8881a43..0b934a9e7d 100644--- a/web-v2/web/src/config/catalog.js+++ b/web-v2/web/src/config/catalog.js@@ -380,6 +380,8 @@ export const providerBase = {label: 'AWS Glue Catalog ID',key: 'aws-glue-catalog-id',value: '',+ alwaysVisible: true,+ immutable: true,description: "12-digit AWS account ID; defaults to caller's account"},{@@ -398,6 +400,7 @@ export const providerBase = {label: 'AWS Glue Endpoint',key: 'aws-glue-endpoint',value: '',+ alwaysVisible: true,description: 'Custom endpoint URL, e.g. http://localhost:4566 for LocalStack'},{@@ -405,12 +408,14 @@ export const providerBase = {key: 'default-table-format',value: 'hive',select: ['hive', 'iceberg'],+ alwaysVisible: true,description: 'Default format for createTable()'},{label: 'Table Format Filter',key: 'table-format-filter',value: 'all',+ alwaysVisible: true,description: 'Comma-separated formats exposed by listTables()'}]diff --git a/web-v2/web/src/lib/utils/catalogProperties.js b/web-v2/web/src/lib/utils/catalogProperties.jsnew file mode 100644index 0000000000..97823187ca--- /dev/null+++ b/web-v2/web/src/lib/utils/catalogProperties.js@@ -0,0 +1,143 @@+/*+ * 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.+ */++/**+ * A property is required when it is flagged as such, or when it is the warehouse of a Hive/JDBC+ * backed Iceberg catalog.+ *+ * @param {object} prop property definition from `providerBase[provider].defaultProps`+ * @param {object} context current dialog state+ * @param {string} context.currentProvider selected catalog provider+ * @param {string} context.catalogBackend selected `catalog-backend` value+ * @returns {boolean} whether the property must be filled in+ */+export const isCatalogRequiredField = (prop, { currentProvider, catalogBackend } = {}) => {+ return Boolean(+ prop.required ||+ (prop.key === 'warehouse' && currentProvider === 'lakehouse-iceberg' && ['hive', 'jdbc'].includes(catalogBackend))+ )+}++/**+ * Decides whether a catalog property field is hidden in the create/edit dialog.+ *+ * In edit mode only the fields the catalog reports are rendered, plus the required ones and the+ * `region`/`location` fields, so the dialog does not lose properties it cannot round-trip. Fields+ * declared with `alwaysVisible` (e.g. optional connector properties that were never set) stay+ * visible even when the catalog response omits them.+ *+ * @param {object} prop property definition from `providerBase[provider].defaultProps`+ * @param {object} context current dialog state+ * @param {boolean} context.editCatalog whether the dialog edits an existing catalog+ * @param {object} context.catalogProperties properties loaded from the edited catalog+ * @param {string} context.catalogBackend selected `catalog-backend` value+ * @param {string} context.authType selected `authentication.type` value+ * @param {string} context.currentProvider selected catalog provider+ * @returns {boolean} whether the property field is hidden+ */+export const isCatalogPropertyHidden = (prop, context = {}) => {+ const { editCatalog, catalogProperties, catalogBackend, authType, currentProvider } = context+ const { parentField, hide, key } = prop++ // In edit mode, hide props not present in the loaded catalog response. Fields flagged+ // `alwaysVisible` opt out so the dialog can still render optional properties the catalog omits,+ // but they keep honoring parent-dependent hiding below.+ if (editCatalog && catalogProperties && !(key in catalogProperties) && !prop.alwaysVisible) {+ return true+ }++ // Visibility driven by another field always wins.+ if (parentField === 'catalog-backend') {+ return Boolean(catalogBackend && hide && hide.includes(catalogBackend))+ }++ if (parentField === 'authentication.type') {+ return Boolean(!authType || (hide && hide.includes(authType)))+ }++ if (editCatalog && prop.alwaysVisible) {+ return false+ }++ // Outside edit mode every field is rendered; in edit mode only required/region/location survive.+ return Boolean(+ editCatalog &&+ !['region', 'location'].includes(key) &&+ !isCatalogRequiredField(prop, { currentProvider, catalogBackend })+ )+}++/**+ * Merges the dialog's free-form property rows with the declared default properties into the+ * `properties` map sent to the server. Default properties are applied last so they win on conflicts.+ *+ * @param {object} args+ * @param {object} args.values current form values, including the free-form `properties` rows+ * @param {Array<object>} args.defaultProps default properties rendered as dedicated form fields+ * @param {boolean} args.editCatalog whether the dialog edits an existing catalog+ * @param {object} args.catalogProperties properties loaded from the edited catalog+ * @returns {object} the `properties` map to submit+ */+export const buildCatalogProperties = ({+ values = {},+ defaultProps = [],+ editCatalog = false,+ catalogProperties = {}+}) => {+ const properties = {}++ const appendProperty = (item, isDefaultProp) => {+ const { key } = item++ if (key === 'location' || key.startsWith('location-')) {+ if (item.value) {+ properties[key] = item.prefix ? item.prefix + item.value : item.value+ }++ return+ }++ const defaultValue = item.value instanceof Array ? item.value.join(',') : item.value+ const value = values[key] || defaultValue++ if (isDefaultProp && editCatalog) {+ // Optional, editable alwaysVisible fields are rendered even when the catalog omits them.+ // Leave them out when the user clears them so an existing property is removed instead of+ // being written back as an empty string.+ if (item.alwaysVisible && !item.required && !item.immutable && !item.disabled) {+ if (values[key] === '' || values[key] == null) {+ return+ }+ }++ // Keep fields the catalog does not report absent until the user gives them a value, otherwise+ // saving an unrelated change would write empty or default-valued properties.+ if (!(key in catalogProperties) && (value === '' || value == null || value === defaultValue)) {+ return+ }+ }++ properties[key] = value+ }++ ;(values.properties || []).forEach(item => appendProperty(item, false))+ defaultProps.forEach(item => appendProperty(item, true))++ return properties+}diff --git a/web-v2/web/src/lib/utils/catalogProperties.test.js b/web-v2/web/src/lib/utils/catalogProperties.test.jsnew file mode 100644index 0000000000..10fbed3026--- /dev/null+++ b/web-v2/web/src/lib/utils/catalogProperties.test.js@@ -0,0 +1,253 @@+/*+ * 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 { describe, expect, it } from 'vitest'+import { buildCatalogProperties, isCatalogPropertyHidden, isCatalogRequiredField } from '@/lib/utils/catalogProperties'+import { providerBase } from '@/config/catalog'++const glueProps = providerBase.glue.defaultProps+const prop = key => glueProps.find(item => item.key === key)++describe('isCatalogRequiredField', () => {+ it('treats props flagged as required as required', () => {+ expect(isCatalogRequiredField(prop('aws-region'), { currentProvider: 'glue' })).toBe(true)+ })++ it('requires the warehouse of hive and jdbc backed Iceberg catalogs', () => {+ const warehouse = { key: 'warehouse', required: false }++ expect(isCatalogRequiredField(warehouse, { currentProvider: 'lakehouse-iceberg', catalogBackend: 'jdbc' })).toBe(+ true+ )+ expect(isCatalogRequiredField(warehouse, { currentProvider: 'lakehouse-iceberg', catalogBackend: 'hive' })).toBe(+ true+ )+ expect(isCatalogRequiredField(warehouse, { currentProvider: 'lakehouse-iceberg', catalogBackend: 'rest' })).toBe(+ false+ )+ expect(isCatalogRequiredField(warehouse, { currentProvider: 'glue' })).toBe(false)+ })+})++describe('isCatalogPropertyHidden', () => {+ it('renders every field while creating a catalog', () => {+ const context = { editCatalog: false, catalogProperties: {} }++ glueProps.forEach(item => {+ expect(isCatalogPropertyHidden(item, context)).toBe(false)+ })+ })++ it('keeps optional Glue properties visible on the edit dialog when the catalog omits them', () => {+ const context = { editCatalog: true, catalogProperties: { 'aws-region': 'us-east-1', warehouse: 's3://b/w' } }++ expect(isCatalogPropertyHidden(prop('aws-glue-catalog-id'), context)).toBe(false)+ expect(isCatalogPropertyHidden(prop('aws-glue-endpoint'), context)).toBe(false)+ expect(isCatalogPropertyHidden(prop('default-table-format'), context)).toBe(false)+ expect(isCatalogPropertyHidden(prop('table-format-filter'), context)).toBe(false)+ })++ it('hides optional properties the catalog does not report and that are not flagged alwaysVisible', () => {+ const context = { editCatalog: true, catalogProperties: { 'aws-region': 'us-east-1' } }++ expect(isCatalogPropertyHidden(prop('aws-access-key-id'), context)).toBe(true)+ expect(isCatalogPropertyHidden(prop('aws-secret-access-key'), context)).toBe(true)+ })++ it('keeps required, region and location properties visible on the edit dialog', () => {+ const context = {+ editCatalog: true,+ catalogProperties: { 'aws-region': 'us-east-1', 'jdbc-url': 'jdbc:mysql://h:3306', location: 's3://b/w' }+ }++ expect(isCatalogPropertyHidden(prop('aws-region'), context)).toBe(false)+ expect(isCatalogPropertyHidden({ key: 'location' }, context)).toBe(false)+ expect(isCatalogPropertyHidden({ key: 'jdbc-url', required: true }, context)).toBe(false)+ expect(isCatalogPropertyHidden({ key: 'jdbc-database' }, context)).toBe(true)++ // A location the catalog does not report stays hidden, required or not.+ expect(isCatalogPropertyHidden({ key: 'location' }, { editCatalog: true, catalogProperties: {} })).toBe(true)+ })++ it('hides alwaysVisible properties whose visibility depends on another field', () => {+ const jdbcDriver = {+ key: 'jdbc-driver',+ required: true,+ alwaysVisible: true,+ parentField: 'catalog-backend',+ hide: ['hive', 'rest']+ }++ expect(+ isCatalogPropertyHidden(jdbcDriver, { editCatalog: true, catalogProperties: {}, catalogBackend: 'hive' })+ ).toBe(true)+ expect(+ isCatalogPropertyHidden(jdbcDriver, { editCatalog: true, catalogProperties: {}, catalogBackend: 'jdbc' })+ ).toBe(false)+ })++ it('hides required parent-dependent properties the catalog does not report', () => {+ const jdbcUser = {+ key: 'jdbc-user',+ required: true,+ parentField: 'catalog-backend',+ hide: ['hive', 'rest']+ }++ const context = {+ editCatalog: true,+ catalogProperties: { 'catalog-backend': 'jdbc', 'jdbc-url': 'jdbc:mysql://h:3306' },+ catalogBackend: 'jdbc'+ }++ // A JDBC-backed catalog may omit the credentials from the response. The empty required field+ // must stay hidden so it cannot block saving an unrelated change.+ expect(isCatalogPropertyHidden(jdbcUser, context)).toBe(true)+ })++ it('hides fields depending on the selected catalog backend', () => {+ const jdbcDriver = {+ key: 'jdbc-driver',+ required: true,+ parentField: 'catalog-backend',+ hide: ['hive', 'rest']+ }++ expect(+ isCatalogPropertyHidden(jdbcDriver, { editCatalog: false, catalogProperties: {}, catalogBackend: 'jdbc' })+ ).toBe(false)+ expect(+ isCatalogPropertyHidden(jdbcDriver, { editCatalog: false, catalogProperties: {}, catalogBackend: 'hive' })+ ).toBe(true)+ })++ it('hides Kerberos fields when the authentication type is simple', () => {+ const kerberosKeytab = {+ key: 'authentication.kerberos.keytab-uri',+ parentField: 'authentication.type',+ hide: ['simple']+ }++ expect(isCatalogPropertyHidden(kerberosKeytab, { editCatalog: false, authType: 'simple' })).toBe(true)+ expect(isCatalogPropertyHidden(kerberosKeytab, { editCatalog: false, authType: 'Kerberos' })).toBe(false)+ expect(isCatalogPropertyHidden(kerberosKeytab, { editCatalog: false, authType: undefined })).toBe(true)+ })+})++describe('buildCatalogProperties', () => {+ const visibleGlueProps = glueProps.filter(+ item => !isCatalogPropertyHidden(item, { editCatalog: true, catalogProperties: {} })+ )++ it('submits the declared default properties while creating a catalog', () => {+ const properties = buildCatalogProperties({+ values: { provider: 'glue' },+ defaultProps: visibleGlueProps,+ editCatalog: false+ })++ expect(properties).toMatchObject({ 'default-table-format': 'hive', 'table-format-filter': 'all' })+ })++ it('keeps alwaysVisible properties out of the request when the catalog omits them and they are untouched', () => {+ const properties = buildCatalogProperties({+ values: { 'aws-region': 'us-east-1', warehouse: 's3://b/w' },+ defaultProps: visibleGlueProps,+ editCatalog: true,+ catalogProperties: { 'aws-region': 'us-east-1', warehouse: 's3://b/w' }+ })++ expect(properties).not.toHaveProperty('aws-glue-catalog-id')+ expect(properties).not.toHaveProperty('aws-glue-endpoint')+ expect(properties).not.toHaveProperty('default-table-format')+ expect(properties).not.toHaveProperty('table-format-filter')+ })++ it('submits alwaysVisible properties the user sets on the edit dialog', () => {+ const properties = buildCatalogProperties({+ values: {+ 'aws-region': 'us-east-1',+ warehouse: 's3://b/w',+ 'aws-glue-endpoint': 'http://localhost:4566',+ 'default-table-format': 'iceberg'+ },+ defaultProps: visibleGlueProps,+ editCatalog: true,+ catalogProperties: { 'aws-region': 'us-east-1', warehouse: 's3://b/w' }+ })++ expect(properties).toMatchObject({+ 'aws-glue-endpoint': 'http://localhost:4566',+ 'default-table-format': 'iceberg'+ })++ // Untouched fields still holding their declared default are left out of the request.+ expect(properties).not.toHaveProperty('table-format-filter')+ })++ it('omits cleared optional alwaysVisible properties so the update removes them', () => {+ const catalogProperties = {+ 'aws-region': 'us-east-1',+ warehouse: 's3://b/w',+ 'aws-glue-endpoint': 'http://localhost:4566'+ }++ const properties = buildCatalogProperties({+ values: { 'aws-region': 'us-east-1', warehouse: 's3://b/w', 'aws-glue-endpoint': '' },+ defaultProps: visibleGlueProps,+ editCatalog: true,+ catalogProperties+ })++ // Leaving the endpoint empty must produce a removeProperty update, not setProperty with ''.+ expect(properties).not.toHaveProperty('aws-glue-endpoint')+ })++ it('round-trips properties the catalog already reports', () => {+ const catalogProperties = { 'aws-glue-endpoint': 'http://localhost:4566', 'default-table-format': 'iceberg' }++ const values = providerBase.glue.defaultProps.reduce((acc, item) => {+ if (!isCatalogPropertyHidden(item, { editCatalog: true, catalogProperties })) {+ acc[item.key] = catalogProperties[item.key] ?? item.value+ }++ return acc+ }, {})++ const properties = buildCatalogProperties({+ values,+ defaultProps: visibleGlueProps,+ editCatalog: true,+ catalogProperties+ })++ expect(properties).toMatchObject(catalogProperties)+ })++ it('keeps the free-form property rows and the location handling', () => {+ const properties = buildCatalogProperties({+ values: { properties: [{ key: 'custom-key', value: 'custom-value' }] },+ defaultProps: [{ key: 'location', value: 'warehouse/schema', prefix: 's3://bucket/' }],+ editCatalog: true,+ catalogProperties: {}+ })++ expect(properties).toEqual({ 'custom-key': 'custom-value', location: 's3://bucket/warehouse/schema' })+ })+})