You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-zh@flink.apache.org by hoose <xi...@qq.com.INVALID> on 2021/07/15 10:13:06 UTC

Flink1.13.1自定义Catalog问题出错

Flink1.13.1在Catalog方面修改比较大,特别是一些方法的实现上
如
JdbcCatalogFactory implements CatalogFactory中:
核心三个方法全部过期:
public Map<String, String&gt; requiredContext()
&nbsp;public List<String&gt; supportedProperties()
&nbsp;public Catalog createCatalog(String name, Map<String, String&gt; properties)



新的替换方法:
&nbsp; public Set<ConfigOption<?&gt;&gt; requiredOptions()
&nbsp; public Set<ConfigOption<?&gt;&gt; optionalOptions()
&nbsp; public Catalog createCatalog(Context context)



用新的方法打包之后运行:
Exception in thread "main" org.apache.flink.table.api.TableException: Required context of factory 'com.apache.flink.catalog.factory.MysqlCatalogFactory' must not be null
跟踪代码进去发现,
&nbsp; &nbsp; &nbsp;private static Map<String, String&gt; normalizeContext(TableFactory factory) {
&nbsp; &nbsp; &nbsp; &nbsp; Map<String, String&gt; requiredContext = factory.requiredContext();
&nbsp; &nbsp; &nbsp; &nbsp; if (requiredContext == null) {
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new TableException(
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String.format(
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; "Required context of factory '%s' must not be null.",
&nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;factory.getClass().getName()));

看错误是因为requiredContext == null了,其实就是上面requiredContext()没有实现,不明白新版api都把这个方法过期了,为啥在后面还要调用判断他?


希望大佬们讲解一下

Re: Flink1.13.1自定义Catalog问题出错

Posted by Shengkai Fang <fs...@gmail.com>.
Hi.

新版的 CatalogFactory 实现了 Factory,这意味着当前的所有的 connector、format 以及 Catalog
都实现了相同的接口,保持了统一性。而保持原来的方法,更多是为了暂时的兼容性( 我的理解 ): 如果 某个Catalog
从低版本迁移到高版本只需要添加一些新的接口方法,而不需要删除之前的逻辑。之后的版本可能会删除这些已经被deprecated 方法。

Best,
Shengkai.

hoose <xi...@qq.com.invalid> 于2021年7月15日周四 下午6:13写道:

> Flink1.13.1在Catalog方面修改比较大,特别是一些方法的实现上
> 如
> JdbcCatalogFactory implements CatalogFactory中:
> 核心三个方法全部过期:
> public Map<String, String&gt; requiredContext()
> &nbsp;public List<String&gt; supportedProperties()
> &nbsp;public Catalog createCatalog(String name, Map<String, String&gt;
> properties)
>
>
>
> 新的替换方法:
> &nbsp; public Set<ConfigOption<?&gt;&gt; requiredOptions()
> &nbsp; public Set<ConfigOption<?&gt;&gt; optionalOptions()
> &nbsp; public Catalog createCatalog(Context context)
>
>
>
> 用新的方法打包之后运行:
> Exception in thread "main" org.apache.flink.table.api.TableException:
> Required context of factory
> 'com.apache.flink.catalog.factory.MysqlCatalogFactory' must not be null
> 跟踪代码进去发现,
> &nbsp; &nbsp; &nbsp;private static Map<String, String&gt;
> normalizeContext(TableFactory factory) {
> &nbsp; &nbsp; &nbsp; &nbsp; Map<String, String&gt; requiredContext =
> factory.requiredContext();
> &nbsp; &nbsp; &nbsp; &nbsp; if (requiredContext == null) {
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new TableException(
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
> String.format(
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
> &nbsp; &nbsp; &nbsp; &nbsp; "Required context of factory '%s' must not be
> null.",
> &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;factory.getClass().getName()));
>
> 看错误是因为requiredContext ==
> null了,其实就是上面requiredContext()没有实现,不明白新版api都把这个方法过期了,为啥在后面还要调用判断他?
>
>
> 希望大佬们讲解一下