Flink 报错 "Could not find a suitable table factory for 'org.apache.flink.table.factories.StreamTableSourceFactory' in the classpath"

转自:

https://www.cnblogs.com/Springmoon-venn/p/10570056.html

先上代码:

table = tablexx.select(‘*).tablexx.groupBy(‘x).select(‘x, xx.count )

tableEnvironment
  // declare the external system to connect to
  .connect(
    new Kafka()
      .version("0.10")
      .topic("test-input")
      .startFromEarliest()
      .property("zookeeper.connect", "localhost:2181")
      .property("bootstrap.servers", "localhost:9092")
  )

  // declare a format for this system
  .withFormat(
    new Json().deriveSchema()
  )

  // declare the schema of the table
  .withSchema(
    new Schema()
      .field("rowtime", Types.SQL_TIMESTAMP)
        .rowtime(new Rowtime()
          .timestampsFromField("timestamp")
          .watermarksPeriodicBounded(60000)
        )
      .field("user", Types.LONG)
      .field("message", Types.STRING)
  )

  // specify the update-mode for streaming tables
  .inUpsertMode()

  // register as source, sink, or both and under a name
  .registerTableSource("outputTable");
  table.insertInto("outputTable")

直接上报错信息:

The program finished with the following exception:

org.apache.flink.client.program.ProgramInvocationException: The main method caused an error.
    at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:546)
    at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:421)
    at org.apache.flink.client.program.ClusterClient.run(ClusterClient.java:427)
    at org.apache.flink.client.cli.CliFrontend.executeProgram(CliFrontend.java:813)
    at org.apache.flink.client.cli.CliFrontend.runProgram(CliFrontend.java:287)
    at org.apache.flink.client.cli.CliFrontend.run(CliFrontend.java:213)
    at org.apache.flink.client.cli.CliFrontend.parseParameters(CliFrontend.java:1050)
    at org.apache.flink.client.cli.CliFrontend.lambda$main$11(CliFrontend.java:1126)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1836)
    at org.apache.flink.runtime.security.HadoopSecurityContext.runSecured(HadoopSecurityContext.java:41)
    at org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:1126)
Caused by: org.apache.flink.table.api.NoMatchingTableFactoryException: Could not find a suitable table factory for ‘org.apache.flink.table.factories.StreamTableSourceFactory‘ in
the classpath.

Reason: No context matches.

The following factories have been considered:
org.apache.flink.table.sources.CsvBatchTableSourceFactory
org.apache.flink.table.sources.CsvAppendTableSourceFactory
org.apache.flink.table.sinks.CsvBatchTableSinkFactory
org.apache.flink.table.sinks.CsvAppendTableSinkFactory

    at org.apache.flink.table.factories.TableFactoryService$.filterByContext(TableFactoryService.scala:214)
    at org.apache.flink.table.factories.TableFactoryService$.findInternal(TableFactoryService.scala:130)
    at org.apache.flink.table.factories.TableFactoryService$.find(TableFactoryService.scala:81)
    at org.apache.flink.table.factories.TableFactoryUtil$.findAndCreateTableSource(TableFactoryUtil.scala:49)
    at org.apache.flink.table.descriptors.ConnectTableDescriptor.registerTableSource(ConnectTableDescriptor.scala:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:529)
    ... 12 more

报错信息是找不到合适的table factory,查询报错类TableFactoryService.scala 源码214行(报错信息中报错位置)

/**
    * Filters for factories with matching context.
    *
    * @return all matching factories
    */
  private def filterByContext[T](
      factoryClass: Class[T],
      properties: Map[String, String],
      foundFactories: Seq[TableFactory],
      classFactories: Seq[TableFactory])
    : Seq[TableFactory] = {

    val matchingFactories = classFactories.filter { factory =>
      val requestedContext = normalizeContext(factory)

      val plainContext = mutable.Map[String, String]()
      plainContext ++= requestedContext
      // we remove the version for now until we have the first backwards compatibility case
      // with the version we can provide mappings in case the format changes
      plainContext.remove(CONNECTOR_PROPERTY_VERSION)
      plainContext.remove(FORMAT_PROPERTY_VERSION)
      plainContext.remove(METADATA_PROPERTY_VERSION)
      plainContext.remove(STATISTICS_PROPERTY_VERSION)

      // check if required context is met
      plainContext.forall(e => properties.contains(e._1) && properties(e._1) == e._2)
    }

    if (matchingFactories.isEmpty) {
      throw new NoMatchingTableFactoryException(
        "No context matches.",
        factoryClass,
        foundFactories,
        properties)
    }

    matchingFactories
  }

主要是对比 requestedContext 中的必需属性,在 properties 中是否有

requestedContext 必需属性如下:

connector.type kafka

update-mode append

connector.version,0.10

 connector.property-version,1

这些属性properties中都有,只是“update-mode”,我这里是 "upsert", 将方法 “inUpsertMode()” 改为 “.inAppendMode()”,执行,这个错就解决了。

(找问题的时候,看到个大哥的,properties 里面没有 connector.type,不过好像用的是1.7的dev版本)

结论是,遇到这个问题,debug进去,看下到底那个属性对应不上,然后针对解决。

--------------------------

你以为这样就解决了吗,不可能的

新的报错如下: "AppendStreamTableSink requires than Table has only insert changes",意思是 AppendStreamTableSink 需要表只有插入(不能update),

去掉表上面的groupBy(),就不会报错了。。。

table = tablexx.select(‘*).tablexx.groupBy(‘x).select(‘x, xx.count )改为:
table = tablexx.select(‘*)是不会报错,但是,我要group 啊。。。没办法,只有先转成stream,再输出了使用 toRetractStream(), 转成stream,结果发现,一直想用的flink的撤回功能就在这里了。group 字段的 count 值变化的时候,会产生两条数据,一条是旧数据,带着false标示,一条是新数据,带着true标示

Flink 报错 "Could not find a suitable table factory for 'org.apache.flink.table.factories.StreamTableSourceFactory' in the classpath"

原文地址:https://www.cnblogs.com/leon0/p/11381289.html

时间: 2024-10-11 01:20:00

Flink 报错 "Could not find a suitable table factory for 'org.apache.flink.table.factories.StreamTableSourceFactory' in the classpath"的相关文章

Webservice报错java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlBeanDefinitionRead

用spring集成发布一个Webservice服务,老是报错: java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlBeanDefinitionReader.setValidationMode(I)V at org.apache.xbean.spring.context.v2.XBeanXmlBeanDefinitionReader.<init>(XBeanXmlBeanDefinitionReader.j

Eclipse导入别人的项目报错:Unable to load annotation processor factory &#39;xxxxx.jar&#39; for project

使用eclipse导入别人的项目时候,报错Unable to load annotation processor factory 'xxxxx.jar' for project. 解决方案 1.项目右键——Properties 2.Java Compiler——Annotation Procession——Factory Path 3.Apply 现在正常了. 参考资料 Unable to load annotation processor factory Eclipse导入别人的项目报错:Un

【MySQL笔记】mysql报错"ERROR 1206 (HY000): The total number of locks exceeds the lock table size"的解决方法

step1:查看 1.1 Mysql命令行里输入"show engines:"查看innoddb数据引擎状态, 1.2 show variables "%_buffer%"里查看innodb_buffer_pool_size的数值,默认是8M(太小,需要改大一点!) step2:找配置文件,修改innodb_buffer_pool_size=64M 2.1 在linux里配置文件是my.cnf,windows里是my.ini(注:不是my-default.ini).

mac 虚拟机启动网络报错Connection activation failed: No suitable device found for this connection

systemctl  network start 找不到命令是因为 centos8没有了network 而是nmcli 代替了 1 排查 本机的ip  netmask  mac地址是否一致 2 mac机 ifconfig 我的虚拟机使用是nat模式 如果是桥接模式就看vmnet1 如果子网掩码是乱码 就看 上面的 IP 子网掩码  路由器要仔细查看 且虚拟机的要跟本机同一个网段 登陆虚拟机 vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=E

git 打包报错:Maven Build时提示:Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test

1.使用git 升级 服务命令 mvn  deploy -e 之后报错: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project zm-live-client: Unable to generate classpath: org.apache.maven.artifact.resolver.ArtifactResolutionExcept

Spark 启动历史任务记录进程,报错 Logging directory must be specified解决

最近在自己电脑上装了Spark 单机运行模式,Spark 启动没有任何问题,可是启动spark history时,一直报错,错误信息如下: Spark assembly has been built with Hive, including Datanucleus jars on classpath Spark Command: /usr/local/java/jdk1.7.0_67/bin/java -cp ::/usr/local/spark/conf:/usr/local/spark/li

spring-boot:run启动报错

Intellij Idea中的spring boot项目,使用main方法运行可以启动,但是使用mvn spring-boot:run启动总是报错 大概意思就是找不到类:org/apache/maven/shared/artifact/filter/collection/ArtifactsFilter 原来是没有在仓库中找到对应的插件,指定一个找得到的版本号即可解决 <build> <plugins> <plugin> <groupId>org.spring

jsp使用c:forEach报错 javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext的问题

今天发现了一个折磨我一天的问题: 在jsp文件中使用 <c:forEach items="${checkResult}" var="item"> </c:forEach> 一直报错: [ERROR] 2013-12-09 15:03:20,740 method:org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:253) Servlet.

WebService之CXF注解报错(二)

WebService之CXF注解 1.具体报错如下 五月 04, 2014 11:24:12 下午 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass 信息: Creating Service {http://service.you.com/}IServiceService from class com.you.service.IService 五月 04, 2014 11: