abhishekrb19 commented on code in PR #17382:
URL: https://github.com/apache/druid/pull/17382#discussion_r1807565799


##########
sql/src/main/java/org/apache/druid/sql/http/ExplainPlanInformation.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.druid.sql.http;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonParser;
+import com.fasterxml.jackson.databind.DeserializationContext;
+import com.fasterxml.jackson.databind.JsonDeserializer;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import org.apache.druid.sql.calcite.planner.ExplainAttributes;
+
+import java.io.IOException;
+import java.util.Objects;
+
+/**
+ * Class that encapsulates the information of a single plan for an {@code 
EXPLAIN PLAN FOR} query.
+ * <p>
+ * Similar to {@link #getAttributes()}, it's possible to provide more 
structure to {@link #getPlan()},
+ * at least for the native query explain, but there's currently no use case 
for it.
+ * </p>
+ */
+public class ExplainPlanInformation
+{
+  @JsonProperty("PLAN")
+  private final String plan;
+
+  @JsonProperty("RESOURCES")
+  private final String resources;
+
+  @JsonProperty("ATTRIBUTES")
+  @JsonDeserialize(using = ExplainAttributesDeserializer.class)
+  private final ExplainAttributes attributes;
+
+  @JsonCreator
+  public ExplainPlanInformation(
+      @JsonProperty("PLAN") final String plan,
+      @JsonProperty("RESOURCES") final String resources,
+      @JsonProperty("ATTRIBUTES") final ExplainAttributes attributes
+  )
+  {
+    this.plan = plan;
+    this.resources = resources;
+    this.attributes = attributes;
+  }
+
+  public String getPlan()
+  {
+    return plan;
+  }
+
+  public String getResources()
+  {
+    return resources;
+  }
+
+  public ExplainAttributes getAttributes()
+  {
+    return attributes;
+  }
+
+  private static class ExplainAttributesDeserializer extends 
JsonDeserializer<ExplainAttributes>

Review Comment:
   The explain plan response contains objects encoded as strings, so jackson 
needs a way to convert the Json string into individual attributes. Other option 
is to add a `@JsonCreator` String constructor in `ExplainAttributes` itself 
besides the existing constructor, which would essentially do the same thing as 
`ExplainAttributesDeserializer#deserialize`.
   
   For now, I have added a comment for the deserializer here since this is 
needed only for `ExplainPlan`. Please let me know if you prefer one approach or 
the other.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to