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


##########
indexing-service/src/main/java/org/apache/druid/indexing/scheduledbatch/ScheduledBatchSupervisorSpec.java:
##########
@@ -0,0 +1,200 @@
+/*
+ * 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.indexing.scheduledbatch;
+
+import com.fasterxml.jackson.annotation.JacksonInject;
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.apache.druid.common.config.Configs;
+import org.apache.druid.error.DruidException;
+import org.apache.druid.error.InvalidInput;
+import org.apache.druid.indexing.overlord.supervisor.SupervisorSpec;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.sql.calcite.planner.ExplainAttributes;
+import org.apache.druid.sql.client.BrokerClient;
+import org.apache.druid.sql.http.ExplainPlan;
+import org.apache.druid.sql.http.SqlQuery;
+
+import javax.annotation.Nullable;
+import java.util.Collections;
+import java.util.List;
+import java.util.UUID;
+
+public class ScheduledBatchSupervisorSpec implements SupervisorSpec
+{
+  public static final String TYPE = "scheduled_batch";
+  public static final String ID_PREFIX = "scheduled_batch__";
+
+  private static final Logger log = new Logger(ScheduledBatchSupervisor.class);
+
+  @JsonProperty
+  private final SqlQuery spec;
+  @JsonProperty
+  private final boolean suspended;
+  @JsonProperty
+  private final CronSchedulerConfig schedulerConfig;
+
+  /**
+   * Note that both {@link #dataSource} and {@link #id} are optional JSON 
fields present in the spec.
+   * They are only used internally because we use and persist the user-facing 
spec in the metadata store. So these
+   * additional fields are required for jackson deserialization.
+   * It would be better to have separate user-facing and domain-specific DTOs 
for this purpose and map them, but
+   * that'll entail a larger change.
+   */
+  @JsonProperty
+  private final String dataSource;
+  @JsonProperty
+  private final String id;
+
+  private final ObjectMapper objectMapper;
+  private final ScheduledBatchScheduler batchScheduler;
+  private final BrokerClient brokerClient;
+
+  @JsonCreator
+  public ScheduledBatchSupervisorSpec(
+      @JsonProperty("spec") final SqlQuery spec,
+      @JsonProperty("schedulerConfig") final CronSchedulerConfig 
schedulerConfig,
+      @JsonProperty("suspended") @Nullable Boolean suspended,
+      @JsonProperty("id") @Nullable final String id,
+      @JsonProperty("dataSource") @Nullable final String dataSource,
+      @JacksonInject ObjectMapper objectMapper,
+      @JacksonInject ScheduledBatchScheduler batchScheduler,
+      @JacksonInject BrokerClient brokerClient
+  )
+  {
+    this.spec = spec;
+    this.schedulerConfig = schedulerConfig;
+    this.suspended = Configs.valueOrDefault(suspended, false);
+    this.objectMapper = objectMapper;
+    this.batchScheduler = batchScheduler;
+    this.brokerClient = brokerClient;
+
+    this.dataSource = dataSource != null ? dataSource : 
getDatasourceFromQuery();

Review Comment:
   Hmm, I prefer determining the datasource from the broker client for these 
reasons:
   
   1. It avoids redundant information, as the datasource is already present in 
the SQL query. Asking the user to specify it again seems unnecessary, even if 
it's part of the supervisor interface.
   2. Running an explain plan on the query is nice, as we're able to validate 
the spec immediately and provide feedback right away.
   



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