mchades commented on code in PR #14145: URL: https://github.com/apache/gravitino/pull/14145#discussion_r4408770334
########## clients/client-java/src/main/java/org/apache/gravitino/client/GenericSemanticModelMetric.java: ########## @@ -0,0 +1,44 @@ +/* + * 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.client; + +import org.apache.gravitino.Namespace; +import org.apache.gravitino.semantic.Metric; +import org.apache.gravitino.semantic.SemanticModelMetric; + +/** A decoded metric with a catalog-relative namespace. */ +final class GenericSemanticModelMetric implements SemanticModelMetric { Review Comment: Added value-based `equals`, `hashCode`, and `toString` over the namespace and complete metric definition, following the existing client value types. Added regression tests for equality, hash-based collections, and string representation. ########## clients/client-java/src/test/java/org/apache/gravitino/client/TestSemanticModelCatalog.java: ########## @@ -148,6 +154,146 @@ public void testListSemanticModelsUsesShortClientIdentifiers() throws JsonProces actual); } + @ParameterizedTest + @ValueSource(booleans = {false, true}) + void testMetricDiscoveryPreservesNamespacesDefinitionsAndOrder(boolean details) + throws JsonProcessingException { + String schema = "schema /%? 收入"; + String path = metricPath(schema); + Metric metric = definition().metrics()[0]; + NameIdentifier[] fullIdentifiers = { + NameIdentifier.of(Namespace.of(METALAKE_NAME, CATALOG_NAME, schema, "a"), metric.name()), + NameIdentifier.of(Namespace.of(METALAKE_NAME, CATALOG_NAME, schema, "a-b"), metric.name()) + }; + SemanticModelMetricDTO[] infos = + Arrays.stream(fullIdentifiers) + .map( + ident -> + new SemanticModelMetricDTO(ident.namespace(), MetricDTO.fromMetric(metric))) + .toArray(SemanticModelMetricDTO[]::new); + buildMockResource( + Method.GET, + path, + Map.of("details", String.valueOf(details)), + null, + details ? new MetricInfoListResponse(infos) : new EntityListResponse(fullIdentifiers), + SC_OK); + int requestsBefore = mockServer.retrieveRecordedRequests(request()).length; + NameIdentifier[] expected = { + NameIdentifier.of(Namespace.of(schema, "a"), metric.name()), + NameIdentifier.of(Namespace.of(schema, "a-b"), metric.name()) + }; + if (details) { + SemanticModelMetric[] actual = + catalog.asSemanticModelCatalog().listMetricInfos(Namespace.of(schema)); + assertEquals(expected.length, actual.length); + for (int i = 0; i < actual.length; i++) { + assertEquals(expected[i].namespace(), actual[i].namespace()); + assertEquals(metric, actual[i].metric()); + String[] levels = actual[i].namespace().levels(); + levels[0] = "changed"; Review Comment: Removed the redundant mutation check. `Namespace` defensive copying is already covered by `TestNamespace`; the client test retains its namespace, complete-definition, ordering, and request-count assertions. -- 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]
