Copilot commented on code in PR #10982:
URL: https://github.com/apache/gravitino/pull/10982#discussion_r3208370070


##########
server/src/test/java/org/apache/gravitino/server/web/rest/TestViewOperations.java:
##########
@@ -0,0 +1,425 @@
+/*
+ * 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.server.web.rest;
+
+import static org.apache.gravitino.Configs.CACHE_ENABLED;
+import static org.apache.gravitino.Configs.ENABLE_AUTHORIZATION;
+import static org.apache.gravitino.Configs.TREE_LOCK_CLEAN_INTERVAL;
+import static org.apache.gravitino.Configs.TREE_LOCK_MAX_NODE_IN_MEMORY;
+import static org.apache.gravitino.Configs.TREE_LOCK_MIN_NODE_IN_MEMORY;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import java.io.IOException;
+import java.time.Instant;
+import java.util.Map;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.Application;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.apache.commons.lang3.reflect.FieldUtils;
+import org.apache.gravitino.Audit;
+import org.apache.gravitino.Config;
+import org.apache.gravitino.GravitinoEnv;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.catalog.SchemaDispatcher;
+import org.apache.gravitino.catalog.ViewDispatcher;
+import org.apache.gravitino.dto.rel.ColumnDTO;
+import org.apache.gravitino.dto.rel.SQLRepresentationDTO;
+import org.apache.gravitino.dto.rel.ViewDTO;
+import org.apache.gravitino.dto.requests.ViewCreateRequest;
+import org.apache.gravitino.dto.requests.ViewUpdateRequest;
+import org.apache.gravitino.dto.requests.ViewUpdatesRequest;
+import org.apache.gravitino.dto.responses.DropResponse;
+import org.apache.gravitino.dto.responses.EntityListResponse;
+import org.apache.gravitino.dto.responses.ErrorConstants;
+import org.apache.gravitino.dto.responses.ErrorResponse;
+import org.apache.gravitino.dto.responses.ViewResponse;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.exceptions.NoSuchViewException;
+import org.apache.gravitino.exceptions.ViewAlreadyExistsException;
+import org.apache.gravitino.lock.LockManager;
+import org.apache.gravitino.rel.Column;
+import org.apache.gravitino.rel.Representation;
+import org.apache.gravitino.rel.SQLRepresentation;
+import org.apache.gravitino.rel.View;
+import org.apache.gravitino.rel.ViewChange;
+import org.apache.gravitino.rest.RESTUtils;
+import org.glassfish.jersey.internal.inject.AbstractBinder;
+import org.glassfish.jersey.server.ResourceConfig;
+import org.glassfish.jersey.test.TestProperties;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.mockito.Mockito;
+
+public class TestViewOperations extends BaseOperationsTest {
+
+  private static final String VND_V1_JSON = 
"application/vnd.gravitino.v1+json";
+
+  private static class MockServletRequestFactory extends 
ServletRequestFactoryBase {
+    @Override
+    public HttpServletRequest get() {
+      HttpServletRequest request = mock(HttpServletRequest.class);
+      when(request.getRemoteUser()).thenReturn(null);
+      return request;
+    }
+  }
+
+  private static SchemaDispatcher schemaDispatcher = 
mock(SchemaDispatcher.class);
+  private final ViewDispatcher dispatcher = mock(ViewDispatcher.class);
+  private final String metalake = "metalake";
+  private final String catalog = "catalog1";
+  private final String schema = "default";
+
+  @BeforeAll
+  public static void setup() throws IllegalAccessException {
+    Config config = mock(Config.class);
+    Mockito.doReturn(100000L).when(config).get(TREE_LOCK_MAX_NODE_IN_MEMORY);
+    Mockito.doReturn(1000L).when(config).get(TREE_LOCK_MIN_NODE_IN_MEMORY);
+    Mockito.doReturn(36000L).when(config).get(TREE_LOCK_CLEAN_INTERVAL);
+    Mockito.doReturn(false).when(config).get(CACHE_ENABLED);
+    Mockito.doReturn(false).when(config).get(ENABLE_AUTHORIZATION);
+    FieldUtils.writeField(GravitinoEnv.getInstance(), "config", config, true);
+    FieldUtils.writeField(GravitinoEnv.getInstance(), "lockManager", new 
LockManager(config), true);
+    Mockito.doReturn(true).when(schemaDispatcher).schemaExists(any());
+  }

Review Comment:
   `schemaDispatcher` is mocked and stubbed in `setup()` but never used/bound 
into the Jersey `ResourceConfig`. This dead setup can confuse the test intent 
and makes future refactors riskier; remove the unused mock/stubbing or bind it 
if ViewOperations actually depends on schema existence checks.



##########
common/src/main/java/org/apache/gravitino/dto/rel/SQLRepresentationDTO.java:
##########
@@ -18,53 +18,133 @@
  */
 package org.apache.gravitino.dto.rel;
 
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
+import com.google.common.base.Preconditions;
+import java.util.Objects;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.gravitino.rel.Representation;
-import org.apache.gravitino.rel.SQLRepresentation;
 
-/** DTO for SQL representation. */
-@Getter
-@EqualsAndHashCode(callSuper = true)
-public class SQLRepresentationDTO extends RepresentationDTO {
+/**
+ * A DTO mirroring {@link org.apache.gravitino.rel.SQLRepresentation}. 
Represents a SQL-based view
+ * definition for a particular dialect.
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public final class SQLRepresentationDTO extends RepresentationDTO {
+
+  @JsonProperty("type")
+  private final String type = Representation.TYPE_SQL;
 
   @JsonProperty("dialect")
   private String dialect;
 
   @JsonProperty("sql")
   private String sql;
 
-  private SQLRepresentationDTO() {}
+  private SQLRepresentationDTO() {
+    super();
+  }
+
+  private SQLRepresentationDTO(String dialect, String sql) {
+    this.dialect = dialect;
+    this.sql = sql;
+  }
 
   /**
-   * Creates a SQL representation DTO.
+   * Creates a new {@link Builder}.
    *
-   * @param dialect SQL dialect.
-   * @param sql SQL body.
+   * @return A new builder instance.
    */
-  public SQLRepresentationDTO(String dialect, String sql) {
-    this.dialect = dialect;
-    this.sql = sql;
+  public static Builder builder() {
+    return new Builder();
   }
 
   @Override
   public String type() {
-    return Representation.TYPE_SQL;
+    return type;
   }
 
-  @Override
-  public SQLRepresentation toRepresentation() {
-    return 
SQLRepresentation.builder().withDialect(dialect).withSql(sql).build();
+  /**
+   * Returns the SQL dialect of this representation.
+   *
+   * @return The dialect identifier.
+   */
+  public String dialect() {
+    return dialect;
   }
 
   /**
-   * Creates SQL representation DTO from SQL representation.
+   * Returns the SQL text of this representation.
    *
-   * @param representation SQL representation.
-   * @return SQL representation DTO.
+   * @return The SQL text.
    */
-  public static SQLRepresentationDTO fromSQLRepresentation(SQLRepresentation 
representation) {
-    return new SQLRepresentationDTO(representation.dialect(), 
representation.sql());
+  public String sql() {
+    return sql;
+  }

Review Comment:
   `SQLRepresentationDTO` no longer exposes the previously available 
JavaBean-style accessors/constructors (e.g., `getDialect()`/`getSql()`, public 
ctor, `fromSQLRepresentation(...)`). If this DTO is part of a published client 
surface, consider keeping deprecated compatibility methods (delegating to 
`dialect()`/`sql()` or the builder) to avoid breaking existing consumers.



##########
common/src/main/java/org/apache/gravitino/dto/rel/SQLRepresentationDTO.java:
##########
@@ -18,53 +18,133 @@
  */
 package org.apache.gravitino.dto.rel;
 
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
 import com.fasterxml.jackson.annotation.JsonProperty;
-import lombok.EqualsAndHashCode;
-import lombok.Getter;
+import com.google.common.base.Preconditions;
+import java.util.Objects;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.gravitino.rel.Representation;
-import org.apache.gravitino.rel.SQLRepresentation;
 
-/** DTO for SQL representation. */
-@Getter
-@EqualsAndHashCode(callSuper = true)
-public class SQLRepresentationDTO extends RepresentationDTO {
+/**
+ * A DTO mirroring {@link org.apache.gravitino.rel.SQLRepresentation}. 
Represents a SQL-based view
+ * definition for a particular dialect.
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public final class SQLRepresentationDTO extends RepresentationDTO {
+
+  @JsonProperty("type")
+  private final String type = Representation.TYPE_SQL;
 
   @JsonProperty("dialect")
   private String dialect;
 
   @JsonProperty("sql")
   private String sql;
 
-  private SQLRepresentationDTO() {}
+  private SQLRepresentationDTO() {
+    super();
+  }
+
+  private SQLRepresentationDTO(String dialect, String sql) {
+    this.dialect = dialect;
+    this.sql = sql;
+  }
 
   /**
-   * Creates a SQL representation DTO.
+   * Creates a new {@link Builder}.
    *
-   * @param dialect SQL dialect.
-   * @param sql SQL body.
+   * @return A new builder instance.
    */
-  public SQLRepresentationDTO(String dialect, String sql) {
-    this.dialect = dialect;
-    this.sql = sql;
+  public static Builder builder() {
+    return new Builder();
   }
 
   @Override
   public String type() {
-    return Representation.TYPE_SQL;
+    return type;
   }
 
-  @Override
-  public SQLRepresentation toRepresentation() {
-    return 
SQLRepresentation.builder().withDialect(dialect).withSql(sql).build();
+  /**
+   * Returns the SQL dialect of this representation.
+   *
+   * @return The dialect identifier.
+   */
+  public String dialect() {
+    return dialect;
   }
 
   /**
-   * Creates SQL representation DTO from SQL representation.
+   * Returns the SQL text of this representation.
    *
-   * @param representation SQL representation.
-   * @return SQL representation DTO.
+   * @return The SQL text.
    */
-  public static SQLRepresentationDTO fromSQLRepresentation(SQLRepresentation 
representation) {
-    return new SQLRepresentationDTO(representation.dialect(), 
representation.sql());
+  public String sql() {
+    return sql;
+  }
+
+  @Override
+  public void validate() throws IllegalArgumentException {
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(dialect), "\"dialect\" field is required and 
cannot be empty");
+    Preconditions.checkArgument(
+        StringUtils.isNotBlank(sql), "\"sql\" field is required and cannot be 
empty");
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof SQLRepresentationDTO)) return false;
+    SQLRepresentationDTO that = (SQLRepresentationDTO) o;
+    return Objects.equals(dialect, that.dialect) && Objects.equals(sql, 
that.sql);
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hash(dialect, sql);
+  }
+
+  @Override
+  public String toString() {
+    return "SQLRepresentationDTO{" + "dialect='" + dialect + '\'' + ", sql='" 
+ sql + '\'' + '}';
+  }
+
+  /** Builder for {@link SQLRepresentationDTO}. */
+  public static final class Builder {
+
+    private String dialect;
+    private String sql;
+
+    private Builder() {}
+
+    /**
+     * Sets the dialect.
+     *
+     * @param dialect The dialect identifier.
+     * @return This builder.
+     */
+    public Builder withDialect(String dialect) {
+      this.dialect = dialect;
+      return this;
+    }
+
+    /**
+     * Sets the SQL text.
+     *
+     * @param sql The SQL text.
+     * @return This builder.
+     */
+    public Builder withSql(String sql) {
+      this.sql = sql;
+      return this;
+    }
+
+    /**
+     * Builds a new {@link SQLRepresentationDTO}.
+     *
+     * @return The constructed instance.
+     */
+    public SQLRepresentationDTO build() {

Review Comment:
   `SQLRepresentationDTO.Builder.build()` currently returns an instance even 
when `dialect`/`sql` are null or blank; the first failure will happen later in 
`validate()` or during conversion. Other DTO builders in this codebase (e.g., 
`ColumnDTO.Builder`) enforce required fields in `build()`—doing the same here 
would provide earlier, clearer failures.
   



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