laserninja commented on code in PR #12900:
URL: https://github.com/apache/gravitino/pull/12900#discussion_r4253956585
##########
web-v2/web/src/lib/store/metalakes/index.js:
##########
@@ -2332,6 +2374,136 @@ export const deleteView = createAsyncThunk(
}
)
+export const fetchSemanticModels = createAsyncThunk(
+ 'appMetalakes/fetchSemanticModels',
+ async ({ init, metalake, catalog, schema }, { getState, dispatch }) => {
+ const [err, res] = await to(getSemanticModelsApi({ metalake, catalog,
schema }, { errorMessageMode: 'none' }))
+
+ if (err || !res) {
+ // The catalog doesn't support semantic models (405), or the server
predates the endpoint and
+ // has no route for it (404). Both mean "this schema has none" — return
empty silently rather
+ // than failing every schema page against an older server.
+ if ([404, 405].includes(err?.response?.status)) {
+ return { semanticModels: [], init }
+ }
+ if (init) {
+ throw new Error(err)
+ }
+ }
+
+ const { identifiers = [] } = res || {}
+
+ const semanticModels = identifiers.map(semanticModelItem => {
+ return {
+ ...semanticModelItem,
+ node: 'semanticModel',
+ id:
`{{${metalake}}}{{${catalog}}}{{${'relational'}}}{{${schema}}}{{${semanticModelItem.name}}}`,
+ key:
`{{${metalake}}}{{${catalog}}}{{${'relational'}}}{{${schema}}}{{${semanticModelItem.name}}}`,
+ path: `?${new URLSearchParams({
+ metalake,
+ catalog,
+ catalogType: 'relational',
+ schema,
+ semanticModel: semanticModelItem.name
+ }).toString()}`,
+ name: semanticModelItem.name,
+ title: semanticModelItem.name,
+ isLeaf: true,
+ children: []
+ }
+ })
+
+ if (
+ init &&
+
getState().metalakes.loadedNodes.includes(`{{${metalake}}}{{${catalog}}}{{${'relational'}}}{{${schema}}}`)
+ ) {
+ const schemaKey =
`{{${metalake}}}{{${catalog}}}{{${'relational'}}}{{${schema}}}`
+ dispatch(
+ setIntoTreeNodes({
+ key: schemaKey,
+ data: mergeWithSemanticModelNodes({
+ tree: getState().metalakes.metalakeTree,
+ key: schemaKey,
+ entities: semanticModels
+ })
+ })
+ )
+ }
+
+ return { semanticModels, init }
+ }
+)
+
+export const getSemanticModelDetails = createAsyncThunk(
+ 'appMetalakes/getSemanticModelDetails',
+ async ({ init, metalake, catalog, schema, semanticModel }) => {
+ const [err, res] = await to(
+ getSemanticModelDetailsApi({ metalake, catalog, schema, semanticModel },
{ errorMessageMode: 'none' })
+ )
+
+ if (err || !res) {
+ // Catalog doesn't support semantic models (HTTP 405) — return empty
result silently
+ if (err?.response?.status === 405) {
+ return { semanticModel: null, init }
+ }
+ throw new Error(err)
Review Comment:
Fixed in 6f82c2c86. Existing `Error` instances are rethrown; other errors
use `err?.message ?? String(err)`. Empty responses get an explicit message.
Added regression tests for detail-load messages and canceled requests, which
remain quiet.
##########
web-v2/web/src/lib/utils/semanticModel.js:
##########
@@ -0,0 +1,259 @@
+/*
+ * 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 { isEqual, isPlainObject } from 'lodash-es'
+
+const SOURCE_NAMESPACE_LENGTH = 2
+const DEFINITION_INDENT = 2
+
+const isNonBlankString = value => typeof value === 'string' && value.trim()
!== ''
+
+const duplicatesOf = names => {
+ const seen = new Set()
+ const duplicates = new Set()
+
+ names.forEach(name => {
+ if (seen.has(name)) {
+ duplicates.add(name)
+ }
+ seen.add(name)
+ })
+
+ return [...duplicates]
+}
+
+const validateSource = (dataset, errors) => {
+ const { name, source } = dataset
+
+ if (!isPlainObject(source)) {
+ errors.push(`Dataset "${name}" must have a source with a namespace and a
name.`)
+
+ return
+ }
+
+ const { namespace } = source
+
+ if (!Array.isArray(namespace) || namespace.length !==
SOURCE_NAMESPACE_LENGTH || !namespace.every(isNonBlankString)) {
+ errors.push(`Dataset "${name}" must have a source namespace of exactly
[catalog, schema].`)
+ }
+
+ if (!isNonBlankString(source.name)) {
+ errors.push(`Dataset "${name}" must have a source with a non-empty name.`)
+ }
+}
+
+const validateDatasets = (datasets, errors) => {
+ datasets.forEach((dataset, index) => {
+ if (!isPlainObject(dataset) || !isNonBlankString(dataset.name)) {
+ errors.push(`datasets[${index}] must have a non-empty name.`)
+
+ return
+ }
+
+ validateSource(dataset, errors)
+
+ const fields = dataset.fields
+ if (fields !== undefined && !Array.isArray(fields)) {
+ errors.push(`Dataset "${dataset.name}" must declare fields as an array.`)
+
+ return
+ }
+
+ const duplicateFields = duplicatesOf((fields || []).map(field =>
field?.name))
Review Comment:
Fixed in 6f82c2c86. Each field must now be an object with a non-blank string
name, and duplicate detection only considers valid names. Added tests for null,
primitive, missing, blank, and numeric names, plus repeated invalid entries
alongside genuine duplicates.
--
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]