mchades commented on code in PR #12624:
URL: https://github.com/apache/gravitino/pull/12624#discussion_r3863962265


##########
common/src/test/java/org/apache/gravitino/dto/semantic/TestSemanticModelDefinitionDTO.java:
##########
@@ -0,0 +1,350 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.dto.semantic;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.json.JsonUtils;
+import org.apache.gravitino.semantic.AIContext;
+import org.apache.gravitino.semantic.AIContextObject;
+import org.apache.gravitino.semantic.CustomExtension;
+import org.apache.gravitino.semantic.DataType;
+import org.apache.gravitino.semantic.Dataset;
+import org.apache.gravitino.semantic.DialectExpression;
+import org.apache.gravitino.semantic.Dialects;
+import org.apache.gravitino.semantic.Dimension;
+import org.apache.gravitino.semantic.Expression;
+import org.apache.gravitino.semantic.Field;
+import org.apache.gravitino.semantic.Metric;
+import org.apache.gravitino.semantic.Relationship;
+import org.apache.gravitino.semantic.SemanticModelDefinition;
+import org.junit.jupiter.api.Test;
+
+public class TestSemanticModelDefinitionDTO {
+
+  private final ObjectMapper objectMapper = JsonUtils.objectMapper();
+  private final ObjectMapper persistenceMapper = JsonUtils.anyFieldMapper();
+
+  @Test
+  public void testDefinitionConversionAndJsonRoundTrip() throws 
JsonProcessingException {
+    SemanticModelDefinition definition = definition();
+    SemanticModelDefinitionDTO dto = 
SemanticModelDefinitionDTO.fromDefinition(definition);
+
+    String json = persistenceMapper.writeValueAsString(dto);
+    JsonNode root = persistenceMapper.readTree(json);
+    JsonNode dataset = root.path("datasets").get(0);
+    JsonNode field = dataset.path("fields").get(0);
+    JsonNode relationship = root.path("relationships").get(0);
+
+    assertTrue(root.has("ai_context"));
+    assertTrue(root.has("custom_extensions"));
+    assertFalse(root.has("aiContext"));
+    assertFalse(json.contains("customExtensions"));

Review Comment:
   Replaced the raw `String.contains(...)` field-name checks with assertions 
against parsed `JsonNode` objects, including checks for the expected camelCase 
fields and the absence of the old snake_case fields.



##########
common/src/test/java/org/apache/gravitino/dto/semantic/TestSemanticModelDefinitionDTO.java:
##########
@@ -0,0 +1,350 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.dto.semantic;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.json.JsonUtils;
+import org.apache.gravitino.semantic.AIContext;
+import org.apache.gravitino.semantic.AIContextObject;
+import org.apache.gravitino.semantic.CustomExtension;
+import org.apache.gravitino.semantic.DataType;
+import org.apache.gravitino.semantic.Dataset;
+import org.apache.gravitino.semantic.DialectExpression;
+import org.apache.gravitino.semantic.Dialects;
+import org.apache.gravitino.semantic.Dimension;
+import org.apache.gravitino.semantic.Expression;
+import org.apache.gravitino.semantic.Field;
+import org.apache.gravitino.semantic.Metric;
+import org.apache.gravitino.semantic.Relationship;
+import org.apache.gravitino.semantic.SemanticModelDefinition;
+import org.junit.jupiter.api.Test;
+
+public class TestSemanticModelDefinitionDTO {
+
+  private final ObjectMapper objectMapper = JsonUtils.objectMapper();
+  private final ObjectMapper persistenceMapper = JsonUtils.anyFieldMapper();
+
+  @Test
+  public void testDefinitionConversionAndJsonRoundTrip() throws 
JsonProcessingException {
+    SemanticModelDefinition definition = definition();
+    SemanticModelDefinitionDTO dto = 
SemanticModelDefinitionDTO.fromDefinition(definition);
+
+    String json = persistenceMapper.writeValueAsString(dto);
+    JsonNode root = persistenceMapper.readTree(json);
+    JsonNode dataset = root.path("datasets").get(0);
+    JsonNode field = dataset.path("fields").get(0);
+    JsonNode relationship = root.path("relationships").get(0);
+
+    assertTrue(root.has("ai_context"));
+    assertTrue(root.has("custom_extensions"));
+    assertFalse(root.has("aiContext"));
+    assertFalse(json.contains("customExtensions"));
+    assertEquals(List.of("sales", "mart"), 
stringValues(dataset.path("source").path("namespace")));
+    assertEquals("orders", dataset.path("source").path("name").textValue());
+    assertTrue(dataset.has("primary_key"));
+    assertTrue(dataset.has("unique_keys"));
+    assertTrue(dataset.has("ai_context"));
+    assertEquals("DateTimeTz", field.path("datatype").textValue());
+    assertTrue(field.path("dimension").path("is_time").booleanValue());
+    assertEquals(
+        "ANSI_SQL", 
field.path("expression").path("dialects").get(0).path("dialect").textValue());
+    assertTrue(relationship.has("from_columns"));
+    assertTrue(relationship.has("to_columns"));
+    assertEquals("example", 
root.path("custom_extensions").get(0).path("vendor_name").textValue());
+
+    JsonNode aiContext = root.path("ai_context");
+    assertEquals(
+        List.of(
+            "instructions", "synonyms", "examples", "priority", 
"semantic_hints", "nullable_hint"),
+        fieldNames(aiContext));
+    assertEquals(List.of("first", "second"), 
fieldNames(aiContext.path("semantic_hints")));
+    assertTrue(aiContext.path("nullable_hint").isNull());
+
+    SemanticModelDefinitionDTO deserialized =
+        persistenceMapper.readValue(json, SemanticModelDefinitionDTO.class);
+    assertEquals(dto, deserialized);
+    assertEquals(definition, deserialized.toDefinition());
+    assertEquals(json, persistenceMapper.writeValueAsString(deserialized));
+  }
+
+  @Test
+  public void testAIContextUnionAndUnknownPropertyOrder() throws 
JsonProcessingException {
+    AIContextDTO textContext = AIContextDTO.fromAIContext(AIContext.of(""));
+    String textJson = objectMapper.writeValueAsString(textContext);
+    assertEquals("\"\"", textJson);
+    assertEquals(
+        AIContext.of(""), objectMapper.readValue(textJson, 
AIContextDTO.class).toAIContext());
+
+    String objectJson =
+        "{\"instructions\":\"Use governed data\","
+            + "\"first_unknown\":{\"alpha\":1,\"beta\":2},"
+            + "\"synonyms\":[\"governed\"],"
+            + "\"second_unknown\":[true,null],"
+            + "\"precise\":0.123456789012345678901234567890}";
+    AIContextDTO objectContext = objectMapper.readValue(objectJson, 
AIContextDTO.class);
+
+    assertNull(objectContext.getText());
+    assertEquals(
+        List.of("first_unknown", "second_unknown", "precise"),
+        new 
ArrayList<>(objectContext.getObject().getAdditionalProperties().keySet()));
+    assertEquals(
+        new BigDecimal("0.123456789012345678901234567890"),
+        objectContext.getObject().getAdditionalProperties().get("precise"));
+    assertEquals(
+        List.of("alpha", "beta"),
+        new ArrayList<>(
+            ((Map<?, ?>) 
objectContext.getObject().getAdditionalProperties().get("first_unknown"))
+                .keySet()));
+    assertEquals(
+        BigInteger.ONE,
+        ((Map<?, ?>) 
objectContext.getObject().getAdditionalProperties().get("first_unknown"))
+            .get("alpha"));
+
+    AIContextDTO converted = 
AIContextDTO.fromAIContext(objectContext.toAIContext());
+    assertEquals(
+        List.of("first_unknown", "second_unknown", "precise"),
+        new 
ArrayList<>(converted.getObject().getAdditionalProperties().keySet()));
+    assertEquals(
+        List.of("instructions", "synonyms", "first_unknown", "second_unknown", 
"precise"),
+        
fieldNames(objectMapper.readTree(objectMapper.writeValueAsString(converted))));
+    assertEquals(
+        objectContext.getObject().getAdditionalProperties(),
+        converted.getObject().getAdditionalProperties());
+    assertTrue(
+        
objectMapper.writeValueAsString(converted).contains("0.123456789012345678901234567890"));
+
+    assertThrows(
+        JsonProcessingException.class, () -> objectMapper.readValue("42", 
AIContextDTO.class));
+  }
+
+  @Test
+  public void testAbsentAndEmptyArraysRemainDistinct() throws 
JsonProcessingException {
+    Dataset absentDataset =
+        Dataset.builder()
+            .withName("absent")
+            .withSource(NameIdentifier.of("sales", "mart", "absent"))
+            .build();
+    SemanticModelDefinition absentDefinition =
+        SemanticModelDefinition.builder().withDatasets(new Dataset[] 
{absentDataset}).build();
+    SemanticModelDefinitionDTO absent = 
SemanticModelDefinitionDTO.fromDefinition(absentDefinition);
+    String absentJson = objectMapper.writeValueAsString(absent);
+
+    assertFalse(absentJson.contains("fields"));
+    assertFalse(absentJson.contains("relationships"));

Review Comment:
   The absent-field checks now inspect the parsed object at the exact JSON 
level, and the decimal round-trip assertion compares the deserialized 
`BigDecimal` value instead of searching the serialized string.



##########
common/src/main/java/org/apache/gravitino/dto/semantic/AIContextObjectDTO.java:
##########
@@ -0,0 +1,222 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.dto.semantic;
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import org.apache.gravitino.semantic.AIContextObject;
+
+/** DTO for structured Semantic Model AI context. */
+@Getter
+@EqualsAndHashCode
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+@Builder(setterPrefix = "with")
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({"instructions", "synonyms", "examples"})
+@JsonDeserialize(using = AIContextObjectDTO.Deserializer.class)
+public class AIContextObjectDTO {
+
+  @Nullable
+  @JsonProperty("instructions")
+  private String instructions;
+
+  @Nullable
+  @JsonProperty("synonyms")
+  private String[] synonyms;
+
+  @Nullable
+  @JsonProperty("examples")
+  private String[] examples;
+
+  @JsonIgnore
+  @Getter(AccessLevel.NONE)
+  @Builder.Default
+  private Map<String, Object> additionalProperties = new LinkedHashMap<>();
+
+  /**
+   * Creates a structured AI context DTO from an API model.
+   *
+   * @param aiContextObject The API AI context object.
+   * @return The structured AI context DTO.
+   */
+  public static AIContextObjectDTO fromAIContextObject(AIContextObject 
aiContextObject) {
+    return builder()
+        .withInstructions(aiContextObject.instructions())
+        .withSynonyms(aiContextObject.synonyms())
+        .withExamples(aiContextObject.examples())
+        .withAdditionalProperties(new 
LinkedHashMap<>(aiContextObject.additionalProperties()))
+        .build();
+  }
+
+  /**
+   * Converts this DTO to an API AI context object.
+   *
+   * @return The API AI context object.
+   */
+  public AIContextObject toAIContextObject() {
+    return AIContextObject.builder()
+        .withInstructions(instructions)
+        .withSynonyms(synonyms)
+        .withExamples(examples)
+        .withAdditionalProperties(
+            additionalProperties == null ? Collections.emptyMap() : 
additionalProperties)
+        .build();
+  }
+
+  /**
+   * Returns unknown AI-context properties in their input order.
+   *
+   * @return The additional properties.
+   */
+  @JsonAnyGetter
+  public Map<String, Object> getAdditionalProperties() {
+    return additionalProperties == null ? Collections.emptyMap() : 
additionalProperties;
+  }
+
+  /** Deserializes structured AI context while retaining unknown JSON values 
and their order. */
+  public static final class Deserializer extends 
JsonDeserializer<AIContextObjectDTO> {
+
+    @Override
+    public AIContextObjectDTO deserialize(JsonParser parser, 
DeserializationContext context)
+        throws IOException {
+      if (!parser.hasToken(JsonToken.START_OBJECT)) {
+        throw JsonMappingException.from(parser, "Structured AI context must be 
an object");
+      }

Review Comment:
   The object-shape error now includes `parser.currentToken()`, for example: 
`Structured AI context must be an object, but found VALUE_NUMBER_INT`.



##########
common/src/main/java/org/apache/gravitino/dto/semantic/AIContextObjectDTO.java:
##########
@@ -0,0 +1,222 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.dto.semantic;
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.annotation.JsonPropertyOrder;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Nullable;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import org.apache.gravitino.semantic.AIContextObject;
+
+/** DTO for structured Semantic Model AI context. */
+@Getter
+@EqualsAndHashCode
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+@Builder(setterPrefix = "with")
+@JsonInclude(JsonInclude.Include.NON_NULL)
+@JsonPropertyOrder({"instructions", "synonyms", "examples"})
+@JsonDeserialize(using = AIContextObjectDTO.Deserializer.class)
+public class AIContextObjectDTO {
+
+  @Nullable
+  @JsonProperty("instructions")
+  private String instructions;
+
+  @Nullable
+  @JsonProperty("synonyms")
+  private String[] synonyms;
+
+  @Nullable
+  @JsonProperty("examples")
+  private String[] examples;
+
+  @JsonIgnore
+  @Getter(AccessLevel.NONE)
+  @Builder.Default
+  private Map<String, Object> additionalProperties = new LinkedHashMap<>();
+
+  /**
+   * Creates a structured AI context DTO from an API model.
+   *
+   * @param aiContextObject The API AI context object.
+   * @return The structured AI context DTO.
+   */
+  public static AIContextObjectDTO fromAIContextObject(AIContextObject 
aiContextObject) {
+    return builder()
+        .withInstructions(aiContextObject.instructions())
+        .withSynonyms(aiContextObject.synonyms())
+        .withExamples(aiContextObject.examples())
+        .withAdditionalProperties(new 
LinkedHashMap<>(aiContextObject.additionalProperties()))
+        .build();
+  }
+
+  /**
+   * Converts this DTO to an API AI context object.
+   *
+   * @return The API AI context object.
+   */
+  public AIContextObject toAIContextObject() {
+    return AIContextObject.builder()
+        .withInstructions(instructions)
+        .withSynonyms(synonyms)
+        .withExamples(examples)
+        .withAdditionalProperties(
+            additionalProperties == null ? Collections.emptyMap() : 
additionalProperties)
+        .build();
+  }
+
+  /**
+   * Returns unknown AI-context properties in their input order.
+   *
+   * @return The additional properties.
+   */
+  @JsonAnyGetter
+  public Map<String, Object> getAdditionalProperties() {
+    return additionalProperties == null ? Collections.emptyMap() : 
additionalProperties;
+  }
+
+  /** Deserializes structured AI context while retaining unknown JSON values 
and their order. */
+  public static final class Deserializer extends 
JsonDeserializer<AIContextObjectDTO> {
+
+    @Override
+    public AIContextObjectDTO deserialize(JsonParser parser, 
DeserializationContext context)
+        throws IOException {
+      if (!parser.hasToken(JsonToken.START_OBJECT)) {
+        throw JsonMappingException.from(parser, "Structured AI context must be 
an object");
+      }
+
+      String instructions = null;
+      String[] synonyms = null;
+      String[] examples = null;
+      Map<String, Object> additionalProperties = new LinkedHashMap<>();
+      while (parser.nextToken() != JsonToken.END_OBJECT) {
+        if (!parser.hasToken(JsonToken.FIELD_NAME)) {
+          throw JsonMappingException.from(parser, "Expected an AI context 
property name");
+        }

Review Comment:
   The property-name validation now reports `Expected an AI context property 
name, but found <token>` using `parser.currentToken()`.



##########
common/src/main/java/org/apache/gravitino/dto/semantic/SemanticDTOUtils.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.dto.semantic;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import java.io.IOException;
+import java.util.function.Function;
+import java.util.function.IntFunction;
+import javax.annotation.Nullable;
+import org.apache.gravitino.semantic.DataType;
+
+final class SemanticDTOUtils {
+
+  private SemanticDTOUtils() {}
+
+  @Nullable
+  static <S, T> T[] convertArray(
+      @Nullable S[] values, Function<S, T> converter, IntFunction<T[]> 
arrayFactory) {
+    if (values == null) {
+      return null;
+    }
+
+    T[] converted = arrayFactory.apply(values.length);
+    for (int index = 0; index < values.length; index++) {
+      converted[index] = values[index] == null ? null : 
converter.apply(values[index]);
+    }
+    return converted;
+  }
+
+  static final class DataTypeSerializer extends JsonSerializer<DataType> {
+
+    @Override
+    public void serialize(DataType value, JsonGenerator generator, 
SerializerProvider serializers)
+        throws IOException {
+      generator.writeString(dataTypeName(value));
+    }
+  }
+
+  static final class DataTypeDeserializer extends JsonDeserializer<DataType> {
+
+    @Override
+    public DataType deserialize(JsonParser parser, DeserializationContext 
context)
+        throws IOException {
+      String value = requireString(parser, "DataType");
+      switch (value) {
+        case "String":
+          return DataType.STRING;
+        case "Integer":
+          return DataType.INTEGER;
+        case "Decimal":
+          return DataType.DECIMAL;
+        case "Float":
+          return DataType.FLOAT;
+        case "Boolean":
+          return DataType.BOOLEAN;
+        case "Date":
+          return DataType.DATE;
+        case "Time":
+          return DataType.TIME;
+        case "DateTime":
+          return DataType.DATE_TIME;
+        case "DateTimeTz":
+          return DataType.DATE_TIME_TZ;
+        case "Opaque":
+          return DataType.OPAQUE;
+        default:
+          throw JsonMappingException.from(parser, "Unknown Semantic Model data 
type: " + value);

Review Comment:
   Unknown values now include all supported, case-sensitive Ossie wire names. 
For example, `string` is rejected with `Unknown Semantic Model data type: 
string. Supported values: String, Integer, Decimal, Float, Boolean, Date, Time, 
DateTime, DateTimeTz, Opaque`, while `String` maps to `DataType.STRING`. Tests 
cover every mapping and invalid inputs.



##########
common/src/main/java/org/apache/gravitino/dto/semantic/AIContextDTO.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.dto.semantic;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.core.JsonToken;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.JsonMappingException;
+import com.fasterxml.jackson.databind.JsonSerializer;
+import com.fasterxml.jackson.databind.SerializerProvider;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.google.common.base.Preconditions;
+import java.io.IOException;
+import javax.annotation.Nullable;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import org.apache.gravitino.semantic.AIContext;
+
+/** DTO for the string-or-object Semantic Model AI context union. */
+@Getter
+@EqualsAndHashCode
+@JsonSerialize(using = AIContextDTO.Serializer.class)
+@JsonDeserialize(using = AIContextDTO.Deserializer.class)
+public class AIContextDTO {
+
+  @Nullable private final String text;
+  @Nullable private final AIContextObjectDTO object;
+
+  private AIContextDTO(@Nullable String text, @Nullable AIContextObjectDTO 
object) {
+    this.text = text;
+    this.object = object;
+  }
+
+  /**
+   * Creates a builder for an AI context DTO.
+   *
+   * @return A new builder.
+   */
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  /**
+   * Creates an AI context DTO from an API model.
+   *
+   * @param aiContext The API AI context.
+   * @return The AI context DTO.
+   */
+  public static AIContextDTO fromAIContext(AIContext aiContext) {
+    if (aiContext.isText()) {
+      return builder().withText(aiContext.text()).build();
+    }
+    return 
builder().withObject(AIContextObjectDTO.fromAIContextObject(aiContext.object())).build();
+  }
+
+  /**
+   * Converts this DTO to an API AI context.
+   *
+   * @return The API AI context.
+   */
+  public AIContext toAIContext() {
+    if (text != null) {
+      return AIContext.of(text);
+    }
+    Preconditions.checkArgument(object != null, "AI context object must not be 
null");
+    return AIContext.of(object.toAIContextObject());
+  }
+
+  /** Builder for {@link AIContextDTO}. */
+  public static final class Builder {

Review Comment:
   Replaced the manual builder with Lombok `@Builder(setterPrefix = "with")` on 
the private constructor. The constructor enforces that exactly one of `text` or 
`object` is set, so the generated builder cannot bypass the union invariant.



##########
common/src/main/java/org/apache/gravitino/dto/semantic/DimensionDTO.java:
##########
@@ -0,0 +1,63 @@
+/*
+ * 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.
+ */
+package org.apache.gravitino.dto.semantic;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import javax.annotation.Nullable;
+import lombok.AccessLevel;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import org.apache.gravitino.semantic.Dimension;
+
+/** DTO for Semantic Model dimension metadata. */
+@Getter
+@EqualsAndHashCode
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+@AllArgsConstructor(access = AccessLevel.PRIVATE)
+@Builder(setterPrefix = "with")
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class DimensionDTO {
+
+  @Nullable
+  @JsonProperty("is_time")

Review Comment:
   Aligned the declared JSON fields with the Gravitino camelCase convention, 
including `isTime`, `aiContext`, `primaryKey`, `uniqueKeys`, 
`customExtensions`, `fromColumns`, `toColumns`, and `vendorName`. Custom keys 
stored in `additionalProperties` remain unchanged.



-- 
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]

Reply via email to