mchades commented on code in PR #12900:
URL: https://github.com/apache/gravitino/pull/12900#discussion_r4278633487
##########
web-v2/web/src/lib/store/metalakes/index.js:
##########
@@ -3086,6 +3298,40 @@ export const appMetalakesSlice = createSlice({
toast.error(action.error.message)
}
})
+ builder.addCase(fetchSemanticModels.pending, (state, action) => {
+ const key = semanticModelSchemaKey(action.meta.arg)
+ state.semanticModelRequests[key] = { requestId: action.meta.requestId }
+ state.semanticModelListRequestId = action.meta.requestId
+ })
+ builder.addCase(fetchSemanticModels.fulfilled, (state, action) => {
+ if (action.payload.stale) return
+ const request = state.semanticModelRequests[action.payload.schemaKey]
+ if (request && request.requestId !== action.meta.requestId) return
+ if (request) request.semanticModels = action.payload.semanticModels
+ if (!state.semanticModelListRequestId ||
state.semanticModelListRequestId === action.meta.requestId) {
+ state.semanticModels = action.payload.semanticModels
+ }
+ })
+ builder.addCase(fetchSemanticModels.rejected, (state, action) => {
+ if (action.error.name !== 'CanceledError' &&
!action.error.message.includes('CanceledError')) {
+ toast.error(action.error.message)
+ }
+ })
+ builder.addCase(getSemanticModelDetails.fulfilled, (state, action) => {
+ if (action.payload.init) {
+ state.activatedDetails = action.payload.semanticModel
+ }
Review Comment:
[P1] Ignore detail responses for a previously selected model
This reducer accepts every detail response with init=true. I held model A's
GET, navigated to B, waited for B to load, then released A: the URL/title still
identified B, but the page showed A's metadata. The focused editor takes its
definition from this shared state and submits to the model in the current URL,
so saving can overwrite B with A's definition. Guard detail responses and their
follow-up loading/tag updates against the active entity/request, including
navigation to another entity type. A regression with controlled response
ordering and the real thunk/reducer also fails.
##########
web-v2/web/src/app/catalogs/rightContent/entitiesContent/SemanticModelExtensions.js:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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 { useState } from 'react'
+import { Button, Typography } from 'antd'
+import SemanticMetadataSection from './SemanticMetadataSection'
+
+function ExtensionData({ data }) {
+ const [raw, setRaw] = useState(false)
+ let formatted
+ try {
+ const parsed = JSON.parse(data)
+ if (parsed && typeof parsed === 'object') formatted =
JSON.stringify(parsed, null, 2)
Review Comment:
[P2] Preserve numeric literals when formatting vendor JSON
`JSON.parse` converts vendor numbers to JavaScript doubles before
`stringify` formats them. In the actual viewer,
`{"external_id":9007199254740993,"threshold":0.10000000000000000001}` is
displayed by default with `external_id: 9007199254740992` and `threshold: 0.1`.
The raw toggle retains the original, but the formatted view presents different
values as metadata. Use a lossless formatter or fall back to raw display when
precision cannot be preserved; cover large integers and precise decimals.
##########
web-v2/web/src/app/catalogs/rightContent/CreateSemanticModelDialog.js:
##########
@@ -0,0 +1,279 @@
+/*
+ * 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.
+ */
+
+'use client'
+
+import React, { useEffect, useRef, useState } from 'react'
+import { Form, Input, Modal, Spin, Typography } from 'antd'
+import { useScrolling } from 'react-use'
+import RenderPropertiesFormItem from '@/components/EntityPropertiesFormItem'
+import { validateMessages, dialogContentMaxHeigth, mismatchName } from
'@/config'
+import { nameRegex } from '@/lib/utils/regex'
+import { useResetFormOnCloseModal } from '@/lib/hooks/use-reset'
+import { cn } from '@/lib/utils/tailwind'
+import { useAppDispatch } from '@/lib/hooks/useStore'
+import {
+ formatSemanticModelDefinition,
+ genSemanticModelUpdates,
+ parseSemanticModelDefinition
+} from '@/lib/utils/semanticModel'
+import { createSemanticModel, updateSemanticModel, getSemanticModelDetails }
from '@/lib/store/metalakes'
+
+const { Paragraph } = Typography
+const { TextArea } = Input
+
+const definitionPlaceholder = `{
+ "datasets": [
+ {
+ "name": "orders",
+ "source": { "namespace": ["sales", "mart"], "name": "orders" },
+ "fields": []
+ }
+ ]
+}`
+
+const defaultValues = {
+ name: '',
+ comment: '',
+ definition: '',
+ properties: []
+}
+
+export default function CreateSemanticModelDialog({ ...props }) {
+ const { open, setOpen, metalake, catalog, schema, editSemanticModel, onSaved
} = props
+ const [confirmLoading, setConfirmLoading] = useState(false)
+ const [isLoading, setIsLoading] = useState(false)
+ const [cacheData, setCacheData] = useState()
+ const scrollRef = useRef(null)
+ const loadedRef = useRef(false)
+ const scrolling = useScrolling(scrollRef)
+ const [bottomShadow, setBottomShadow] = useState(false)
+ const [topShadow, setTopShadow] = useState(false)
+ const [form] = Form.useForm()
+ const dispatch = useAppDispatch()
+
+ useResetFormOnCloseModal({
+ form,
+ open
+ })
+
+ const handScroll = () => {
+ if (scrollRef.current) {
+ const { scrollTop, scrollHeight, clientHeight } = scrollRef.current
+ if (scrollHeight > clientHeight + scrollTop) {
+ setTopShadow(true)
+ setBottomShadow(scrollTop > 0)
+ } else if (scrollHeight === clientHeight + scrollTop) {
+ setTopShadow(false)
+ setBottomShadow(scrollTop > 0)
+ }
+ }
+ }
+
+ useEffect(() => {
+ scrollRef.current && handScroll()
+ }, [scrolling])
+
+ useEffect(() => {
+ if (open && editSemanticModel && !loadedRef.current) {
+ loadedRef.current = true
+
+ const initLoad = async () => {
+ setIsLoading(true)
+ try {
+ const { payload } = await dispatch(
+ getSemanticModelDetails({ metalake, catalog, schema,
semanticModel: editSemanticModel })
+ )
+ const loaded = payload?.semanticModel
+ setCacheData(loaded)
+ form.setFieldValue('name', loaded?.name)
+ form.setFieldValue('comment', loaded?.comment)
+ form.setFieldValue('definition',
formatSemanticModelDefinition(loaded?.definition))
+ let index = 0
+ Object.entries(loaded?.properties || {}).forEach(([key, value]) => {
+ form.setFieldValue(['properties', index, 'key'], key)
+ form.setFieldValue(['properties', index, 'value'], value)
+ index++
+ })
+ setIsLoading(false)
+ } catch (e) {
+ setIsLoading(false)
+ }
+ }
+ initLoad()
+ }
+
+ // Reset loadedRef when dialog closes
+ if (!open) {
+ loadedRef.current = false
+ }
+ }, [open, editSemanticModel, metalake, catalog, schema])
+
+ const validateDefinition = (rule, value) => {
+ const { errors } = parseSemanticModelDefinition(value)
+
+ return errors.length
+ ? Promise.reject(
+ <ul className='list-disc pl-4'>
+ {errors.map(error => (
+ <li key={error}>{error}</li>
+ ))}
+ </ul>
+ )
+ : Promise.resolve()
+ }
+
+ const handleSubmit = e => {
+ e.preventDefault()
+ form
+ .validateFields()
+ .then(async values => {
+ const { definition } = parseSemanticModelDefinition(values.definition)
+
+ setConfirmLoading(true)
+
+ const submitData = {
+ name: values.name.trim(),
+ comment: values.comment,
+ definition,
+ properties: Object.fromEntries((values.properties || []).map(({ key,
value }) => [key, value]))
+ }
+
+ let result
+ if (editSemanticModel) {
+ const updates = genSemanticModelUpdates(cacheData, submitData)
+ if (updates.length) {
+ result = await dispatch(
+ updateSemanticModel({
+ metalake,
+ catalog,
+ schema,
+ semanticModel: editSemanticModel,
+ data: { updates }
+ })
+ )
+ }
+ } else {
+ result = await dispatch(createSemanticModel({ data: submitData,
metalake, catalog, schema }))
+ }
+
+ if (!result?.payload?.err && !result?.error) {
+ setOpen(false)
+ if (result) await onSaved?.(result.payload)
+ }
+ })
+ .catch(info => {
+ if (info?.errorFields?.length) {
+ form.scrollToField(info.errorFields[0].name)
+ } else {
+ console.error(info)
+ }
+ })
+ .finally(() => setConfirmLoading(false))
+ }
+
+ const handleCancel = () => {
+ setOpen(false)
+ }
+
+ return (
+ <>
+ <Modal
+ title={!editSemanticModel ? 'Create Semantic Model' : 'Edit Semantic
Model'}
+ open={open}
+ onOk={handleSubmit}
+ okText='Submit'
+ okButtonProps={{
+ 'data-refer': 'handle-submit-semantic-model',
+ disabled: isLoading || (!!editSemanticModel && !cacheData)
+ }}
+ maskClosable={false}
+ keyboard={false}
+ width={800}
+ confirmLoading={confirmLoading}
+ onCancel={handleCancel}
+ >
+ <Paragraph type='secondary'>
+ {!editSemanticModel
+ ? 'Create a new semantic model.'
+ : `Edit the semantic model ${editSemanticModel}. The definition is
replaced as a whole.`}
+ </Paragraph>
+ <div
+ className={cn('relative', {
+ 'after:absolute after:-bottom-10 after:left-0 after:right-0
after:h-10 after:shadow-[0px_-10px_8px_-8px_rgba(5,5,5,0.1)]':
+ topShadow,
+ 'before:absolute before:-top-10 before:left-0 before:right-0
before:h-10 before:z-10 before:shadow-[0px_10px_8px_-8px_rgba(5,5,5,0.1)]':
+ bottomShadow
+ })}
+ >
+ <div className='overflow-auto' style={{ maxHeight:
`${dialogContentMaxHeigth}px` }} ref={scrollRef}>
+ <Spin spinning={isLoading}>
+ <Form
+ form={form}
+ initialValues={defaultValues}
+ layout='vertical'
+ name='semanticModelForm'
+ validateMessages={validateMessages}
+ >
+ <Form.Item
+ name='name'
+ label='Semantic Model Name'
+ rules={[{ required: true }, { type: 'string', max: 64 }, {
pattern: new RegExp(nameRegex) }]}
Review Comment:
I rechecked this routing concern against the real server: importing a
document named ossie, GET .../semantic-models/ossie, and DELETE
.../semantic-models/ossie all succeed. The REST resource and Jersey version are
unchanged on 41c8e2b. The route-shadowing premise of this comment was
incorrect; please remove the ossie-specific rejection added for it, while
retaining normal name validation.
--
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]