World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#13951] improvement(web): Show full column types in table and view details (#13952)
Ofer Helman2ea8fcf18287
diff --git a/web-v2/web/src/app/catalogs/rightContent/entitiesContent/TableDetailsPage.js b/web-v2/web/src/app/catalogs/rightContent/entitiesContent/TableDetailsPage.jsindex 90ad4a0d2e..9bf4a95855 100644--- a/web-v2/web/src/app/catalogs/rightContent/entitiesContent/TableDetailsPage.js+++ b/web-v2/web/src/app/catalogs/rightContent/entitiesContent/TableDetailsPage.js@@ -36,6 +36,7 @@ import { getCatalogDetails, getCurrentEntityOwner } from '@/lib/store/metalakes'import CreateTableDialog from '../CreateTableDialog'import Loading from '@/components/Loading'import PropertiesContent from '@/components/PropertiesContent'+import { formatColumnType } from '@/lib/utils/columnType'const SetOwnerDialog = dynamic(() => import('@/components/SetOwnerDialog'), {loading: () => <Loading />,@@ -389,7 +390,15 @@ export default function TableDetailsPage({ ...props }) {filters: columnTypeFitlers,onFilter: (value, record) =>typeof record.type === 'string' ? record.type.indexOf(value) === 0 : record.type.type.indexOf(value) === 0,- render: type => <Tag color={columnTypeColor(type)}>{typeof type === 'string' ? type : type.type}</Tag>+ render: type => {+ const formattedType = formatColumnType(type)++ return (+ <Tag color={columnTypeColor(type)} title={formattedType}>+ {formattedType}+ </Tag>+ )+ }},{title: 'Tags',diff --git a/web-v2/web/src/app/catalogs/rightContent/entitiesContent/ViewDetailsPage.js b/web-v2/web/src/app/catalogs/rightContent/entitiesContent/ViewDetailsPage.jsindex 8984156116..8c6bf67f34 100644--- a/web-v2/web/src/app/catalogs/rightContent/entitiesContent/ViewDetailsPage.js+++ b/web-v2/web/src/app/catalogs/rightContent/entitiesContent/ViewDetailsPage.js@@ -47,6 +47,7 @@ import { useAppSelector } from '@/lib/hooks/useStore'import { useSearchParams } from 'next/navigation'import { formatToDateTime, isValidDate } from '@/lib/utils/date'import PropertiesContent from '@/components/PropertiesContent'+import { formatColumnType } from '@/lib/utils/columnType'const { Title, Paragraph } = Typographyconst { Search } = Input@@ -197,7 +198,15 @@ export default function ViewDetailsPage() {filters: columnTypeFilters,onFilter: (value, record) =>typeof record.type === 'string' ? record.type.indexOf(value) === 0 : record.type.type.indexOf(value) === 0,- render: type => <Tag color={columnTypeColor(type)}>{typeof type === 'string' ? type : type.type}</Tag>+ render: type => {+ const formattedType = formatColumnType(type)++ return (+ <Tag color={columnTypeColor(type)} title={formattedType}>+ {formattedType}+ </Tag>+ )+ }},{title: 'Nullable',diff --git a/web-v2/web/src/lib/utils/columnType.js b/web-v2/web/src/lib/utils/columnType.jsnew file mode 100644index 0000000000..e30a1bd6bf--- /dev/null+++ b/web-v2/web/src/lib/utils/columnType.js@@ -0,0 +1,45 @@+/*+ * 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.+ */++const withNotNull = (type, nullable) => (nullable === false ? `${type}, NOT NULL` : type)++// The column type like the server's Type.simpleString(), such as list<string>; struct fields omit NULL and COMMENT.+export const formatColumnType = type => {+ if (type === null || type === undefined || typeof type === 'string') {+ return type ?? ''+ }+ switch (type.type) {+ case 'list':+ return `list<${withNotNull(formatColumnType(type.elementType), type.containsNull)}>`+ case 'map':+ return `map<${formatColumnType(type.keyType)},${withNotNull(formatColumnType(type.valueType), type.valueContainsNull)}>`+ case 'struct':+ return `struct<${(type.fields || [])+ .map(f => `${f.name}: ${formatColumnType(f.type)}${f.nullable === false ? ' NOT NULL' : ''}`)+ .join(',')}>`+ case 'union':+ return `union<${(type.types || []).map(formatColumnType).join(',')}>`+ case 'external':+ return `external(${type.catalogString})`+ case 'unparsed':+ return `unparsed(${type.unparsedType})`+ default:+ return type.type ?? ''+ }+}diff --git a/web-v2/web/src/lib/utils/columnType.test.js b/web-v2/web/src/lib/utils/columnType.test.jsnew file mode 100644index 0000000000..5e94483bae--- /dev/null+++ b/web-v2/web/src/lib/utils/columnType.test.js@@ -0,0 +1,61 @@+/*+ * 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 { formatColumnType } from './columnType'++describe('formatColumnType', () => {+ it.each([+ ['a primitive type', 'string', 'string'],+ ['a list', { type: 'list', containsNull: true, elementType: 'string' }, 'list<string>'],+ [+ 'a list of non-null elements',+ { type: 'list', containsNull: false, elementType: 'integer' },+ 'list<integer, NOT NULL>'+ ],+ [+ 'a map of lists',+ {+ type: 'map',+ keyType: 'string',+ valueContainsNull: true,+ valueType: { type: 'list', containsNull: true, elementType: 'long' }+ },+ 'map<string,list<long>>'+ ],+ [+ 'a struct',+ {+ type: 'struct',+ fields: [+ { name: 'id', type: 'long', nullable: false },+ { name: 'tags', type: { type: 'list', containsNull: true, elementType: 'string' }, nullable: true }+ ]+ },+ 'struct<id: long NOT NULL,tags: list<string>>'+ ],+ ['a union', { type: 'union', types: ['integer', 'string'] }, 'union<integer,string>'],+ ['an external type', { type: 'external', catalogString: 'FixedSizeList(4)' }, 'external(FixedSizeList(4))'],+ ['an unparsed type', { type: 'unparsed', unparsedType: 'geo' }, 'unparsed(geo)'],+ ['a missing type', undefined, ''],+ ['an object without a type field', {}, '']+ ])('formats %s', (_, type, expected) => {+ expect(formatColumnType(type)).toBe(expected)+ })+})diff --git a/web/web/src/components/ColumnTypeChip.js b/web/web/src/components/ColumnTypeChip.jsindex f68293d120..51fdb876e7 100644--- a/web/web/src/components/ColumnTypeChip.js+++ b/web/web/src/components/ColumnTypeChip.js@@ -22,13 +22,14 @@ import { ColumnTypeColorEnum } from '@/lib/enums/columnTypeEnum.js'import colors from '@/lib/theme/colors'import { alpha } from '@/lib/utils/color'import { isString } from 'lodash-es'+import { formatColumnType } from '@/lib/utils/columnType'const ColumnTypeChip = props => {const { type = '' } = props- const formatType = type && isString(type) ? type.replace(/\(.*\)/, '') : type+ const formatType = isString(type) ? type.replace(/\(.*\)/, '') : type?.type- const label = isString(type) ? type : `${type?.type}`+ const label = formatColumnType(type)const columnTypeColor = ColumnTypeColorEnum[formatType] || 'secondary'const color = colors[columnTypeColor]?.main || '#8592A3'@@ -37,7 +38,14 @@ const ColumnTypeChip = props => {return (<>{label ? (- <Chip size='small' label={label} sx={{ backgroundColor: bgColor }} color={columnTypeColor} variant='outlined' />+ <Chip+ size='small'+ label={label}+ title={label}+ sx={{ backgroundColor: bgColor }}+ color={columnTypeColor}+ variant='outlined'+ />) : null}</>)diff --git a/web/web/src/lib/utils/columnType.js b/web/web/src/lib/utils/columnType.jsnew file mode 100644index 0000000000..e30a1bd6bf--- /dev/null+++ b/web/web/src/lib/utils/columnType.js@@ -0,0 +1,45 @@+/*+ * 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.+ */++const withNotNull = (type, nullable) => (nullable === false ? `${type}, NOT NULL` : type)++// The column type like the server's Type.simpleString(), such as list<string>; struct fields omit NULL and COMMENT.+export const formatColumnType = type => {+ if (type === null || type === undefined || typeof type === 'string') {+ return type ?? ''+ }+ switch (type.type) {+ case 'list':+ return `list<${withNotNull(formatColumnType(type.elementType), type.containsNull)}>`+ case 'map':+ return `map<${formatColumnType(type.keyType)},${withNotNull(formatColumnType(type.valueType), type.valueContainsNull)}>`+ case 'struct':+ return `struct<${(type.fields || [])+ .map(f => `${f.name}: ${formatColumnType(f.type)}${f.nullable === false ? ' NOT NULL' : ''}`)+ .join(',')}>`+ case 'union':+ return `union<${(type.types || []).map(formatColumnType).join(',')}>`+ case 'external':+ return `external(${type.catalogString})`+ case 'unparsed':+ return `unparsed(${type.unparsedType})`+ default:+ return type.type ?? ''+ }+}diff --git a/web/web/src/lib/utils/columnType.test.js b/web/web/src/lib/utils/columnType.test.jsnew file mode 100644index 0000000000..5e94483bae--- /dev/null+++ b/web/web/src/lib/utils/columnType.test.js@@ -0,0 +1,61 @@+/*+ * 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 { formatColumnType } from './columnType'++describe('formatColumnType', () => {+ it.each([+ ['a primitive type', 'string', 'string'],+ ['a list', { type: 'list', containsNull: true, elementType: 'string' }, 'list<string>'],+ [+ 'a list of non-null elements',+ { type: 'list', containsNull: false, elementType: 'integer' },+ 'list<integer, NOT NULL>'+ ],+ [+ 'a map of lists',+ {+ type: 'map',+ keyType: 'string',+ valueContainsNull: true,+ valueType: { type: 'list', containsNull: true, elementType: 'long' }+ },+ 'map<string,list<long>>'+ ],+ [+ 'a struct',+ {+ type: 'struct',+ fields: [+ { name: 'id', type: 'long', nullable: false },+ { name: 'tags', type: { type: 'list', containsNull: true, elementType: 'string' }, nullable: true }+ ]+ },+ 'struct<id: long NOT NULL,tags: list<string>>'+ ],+ ['a union', { type: 'union', types: ['integer', 'string'] }, 'union<integer,string>'],+ ['an external type', { type: 'external', catalogString: 'FixedSizeList(4)' }, 'external(FixedSizeList(4))'],+ ['an unparsed type', { type: 'unparsed', unparsedType: 'geo' }, 'unparsed(geo)'],+ ['a missing type', undefined, ''],+ ['an object without a type field', {}, '']+ ])('formats %s', (_, type, expected) => {+ expect(formatColumnType(type)).toBe(expected)+ })+})