zachjsh commented on code in PR #13627:
URL: https://github.com/apache/druid/pull/13627#discussion_r1066584622


##########
server/src/main/java/org/apache/druid/catalog/model/table/BaseInputSourceDefn.java:
##########
@@ -0,0 +1,278 @@
+/*
+ * 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.catalog.model.table;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.druid.catalog.model.ColumnSpec;
+import org.apache.druid.catalog.model.Columns;
+import org.apache.druid.catalog.model.TableDefnRegistry;
+import org.apache.druid.data.input.InputFormat;
+import org.apache.druid.data.input.InputSource;
+import org.apache.druid.java.util.common.IAE;
+import org.apache.druid.utils.CollectionUtils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Base class for input source definitions.
+ *
+ * @see {@link FormattedInputSourceDefn} for the base class for (most) input 
formats
+ * which take an input format.
+ */
+public abstract class BaseInputSourceDefn implements InputSourceDefn
+{
+  /**
+   * The "from-scratch" table function for this input source. The parameters
+   * are those defined by the subclass, and the apply simply turns around and
+   * asks the input source definition to do the conversion.
+   */
+  public class AdHocTableFunction extends BaseTableFunction
+  {
+    public AdHocTableFunction(List<ParameterDefn> parameters)
+    {
+      super(parameters);
+    }
+
+    @Override
+    public ExternalTableSpec apply(
+        final String fnName,
+        final Map<String, Object> args,
+        final List<ColumnSpec> columns,
+        final ObjectMapper jsonMapper
+    )
+    {
+      requireSchema(fnName, columns);
+      return convertArgsToTable(args, columns, jsonMapper);
+    }
+  }
+
+  /**
+   * The "partial" table function that starts with a catalog external table 
spec, then
+   * uses SQL function arguments to "complete" (i.e. fill in) the missing 
properties to
+   * produce a complete table which is then converted to an external table 
which Calcite
+   * can use.
+   * <p>
+   * The set of parameters depends on the input source and on whether or not 
the catalog
+   * spec provides a format.
+   */
+  public class PartialTableFunction extends BaseTableFunction
+  {
+    private final ResolvedExternalTable table;
+
+    public PartialTableFunction(final ResolvedExternalTable table, 
List<ParameterDefn> params)
+    {
+      super(params);
+      this.table = table;
+    }
+
+    @Override
+    public ExternalTableSpec apply(
+        final String fnName,
+        final Map<String, Object> args,
+        final List<ColumnSpec> columns,
+        final ObjectMapper jsonMapper
+    )
+    {
+      if 
(CollectionUtils.isNullOrEmpty(table.resolvedTable().spec().columns())) {
+        requireSchema(fnName, columns);
+      }
+      return convertCompletedTable(table, args, columns);
+    }
+  }
+
+  /**
+   * The one and only from-scratch table function for this input source. The
+   * function is defined a bind time, not construction time, since it typically
+   * needs visibility to the set of available input formats.
+   */
+  private AdHocTableFunction adHocTableFn;
+
+  /**
+   * Overridden by each subclass to return the input source class to be
+   * used for JSON conversions.
+   */
+  protected abstract Class<? extends InputSource> inputSourceClass();
+
+  @Override
+  public void bind(TableDefnRegistry registry)
+  {
+    this.adHocTableFn = defineAdHocTableFunction();
+  }
+
+  @Override
+  public void validate(ResolvedExternalTable table)
+  {
+    convertTableToSource(table);
+  }
+
+  /**
+   * Overridden by each subclass to define the parameters needed by each
+   * input source.
+   */
+  protected abstract AdHocTableFunction defineAdHocTableFunction();
+
+  @Override
+  public TableFunction adHocTableFn()
+  {
+    return adHocTableFn;
+  }
+
+  /**
+   * Define a table "from scratch" using SQL function arguments.
+   */
+  protected ExternalTableSpec convertArgsToTable(

Review Comment:
   This this be moved into the `AdHocTableFunction` class, since it seems it 
should only be used in that case?



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