Github user beyond1920 commented on a diff in the pull request:

    https://github.com/apache/flink/pull/3406#discussion_r106403723
  
    --- Diff: 
flink-libraries/flink-table/src/main/scala/org/apache/flink/table/catalog/ExternalTableSourceUtil.scala
 ---
    @@ -0,0 +1,153 @@
    +/*
    + * 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.flink.table.catalog
    +
    +import java.lang.reflect.Modifier
    +import java.net.URL
    +
    +import org.apache.commons.configuration.{ConfigurationException, 
ConversionException, PropertiesConfiguration}
    +import org.apache.flink.table.annotation.TableType
    +import org.apache.flink.table.api.{AmbiguousTableSourceConverterException, 
NoMatchedTableSourceConverterException}
    +import org.apache.flink.table.plan.schema.TableSourceTable
    +import org.apache.flink.table.plan.stats.FlinkStatistic
    +import org.apache.flink.table.sources.TableSource
    +import org.apache.flink.util.InstantiationUtil
    +import org.reflections.Reflections
    +import org.slf4j.{Logger, LoggerFactory}
    +
    +import scala.collection.JavaConverters._
    +import scala.collection.mutable
    +
    +/**
    +  * The utility class is used to convert ExternalCatalogTable to 
TableSourceTable.
    +  */
    +object ExternalTableSourceUtil {
    +
    +  // config file to specify scan package to search TableSourceConverter
    +  private val tableSourceConverterConfigFileName = 
"tableSourceConverter.properties"
    +
    +  private val LOG: Logger = LoggerFactory.getLogger(this.getClass)
    +
    +  // registered table type with the TableSourceConverter.
    +  // Key is table type name, Value is set of converter class.
    +  private val tableTypeToTableSourceConvertersClazz = {
    +    val registeredConverters =
    +      new mutable.HashMap[String, mutable.Set[Class[_ <: 
TableSourceConverter[_]]]]
    +          with mutable.MultiMap[String, Class[_ <: 
TableSourceConverter[_]]]
    +    // scan all config files to find TableSourceConverters which are 
annotationed with TableType.
    +    val resourceUrls = 
getClass.getClassLoader.getResources(tableSourceConverterConfigFileName)
    +    while (resourceUrls.hasMoreElements) {
    +      val url = resourceUrls.nextElement()
    +      val scanPackages = parseScanPackagesFromConfigFile(url)
    +      scanPackages.foreach(scanPackage => {
    +        val clazzWithAnnotations = new Reflections(scanPackage)
    +            .getTypesAnnotatedWith(classOf[TableType])
    +        clazzWithAnnotations.asScala.foreach(clazz =>
    +          if (classOf[TableSourceConverter[_]].isAssignableFrom(clazz)) {
    +            if (Modifier.isAbstract(clazz.getModifiers()) ||
    --- End diff --
    
    Yes, I would add check on it based on InstantiationUtil.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to