You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@rocketmq.apache.org by GitBox <gi...@apache.org> on 2022/08/22 02:28:36 UTC

[GitHub] [rocketmq-flink] SteNicholas commented on a diff in pull request #49: [ISSUE #32] Feature rocketmq catalog

SteNicholas commented on code in PR #49:
URL: https://github.com/apache/rocketmq-flink/pull/49#discussion_r950952238


##########
src/main/java/org/apache/rocketmq/flink/catalog/RocketMQCatalog.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.rocketmq.flink.catalog;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.flink.common.constant.RocketMqCatalogConstant;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.remoting.protocol.LanguageCode;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.FieldsDataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Expose a RocketMQ instance as a database catalog. */
+public class RocketMQCatalog extends AbstractCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RocketMQCatalog.class);
+    public static final String DEFAULT_DB = "default";
+    public final String namesrvAddr;
+    private final String schemaRegistryUrl;
+    private DefaultMQAdminExt mqAdminExt;
+    private SchemaRegistryClient schemaRegistryClient;
+
+    public RocketMQCatalog(
+            String catalogName, String database, String namesrvAddr, String schemaRegistryUrl) {
+        super(catalogName, database);
+        this.namesrvAddr = namesrvAddr;

Review Comment:
   Adds `checkArgument(!isNullOrWhitespaceOnly(namesrvAddr), "namesrvAddr cannot be null or empty");`



##########
src/main/java/org/apache/rocketmq/flink/catalog/RocketMQCatalog.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.rocketmq.flink.catalog;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.flink.common.constant.RocketMqCatalogConstant;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.remoting.protocol.LanguageCode;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.FieldsDataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Expose a RocketMQ instance as a database catalog. */
+public class RocketMQCatalog extends AbstractCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RocketMQCatalog.class);
+    public static final String DEFAULT_DB = "default";
+    public final String namesrvAddr;
+    private final String schemaRegistryUrl;
+    private DefaultMQAdminExt mqAdminExt;
+    private SchemaRegistryClient schemaRegistryClient;
+
+    public RocketMQCatalog(
+            String catalogName, String database, String namesrvAddr, String schemaRegistryUrl) {
+        super(catalogName, database);
+        this.namesrvAddr = namesrvAddr;
+        this.schemaRegistryUrl = schemaRegistryUrl;
+        LOG.info("Created RocketMQ Catalog {}", catalogName);
+    }
+
+    @Override
+    public Optional<Factory> getFactory() {
+        return Optional.of(new RocketMQCatalogFactory());
+    }
+
+    @Override
+    public void open() throws CatalogException {
+        if (mqAdminExt == null) {
+            try {
+                mqAdminExt = new DefaultMQAdminExt();
+                mqAdminExt.setNamesrvAddr(namesrvAddr);
+                mqAdminExt.setLanguage(LanguageCode.JAVA);
+                mqAdminExt.start();
+            } catch (MQClientException e) {
+                throw new CatalogException(
+                        "Failed to create RocketMQ admin using :" + namesrvAddr, e);
+            }
+        }
+        if (schemaRegistryClient == null) {
+            schemaRegistryClient = SchemaRegistryClientFactory.newClient(schemaRegistryUrl, null);
+        }
+    }
+
+    @Override
+    public void close() throws CatalogException {
+        if (Objects.nonNull(mqAdminExt)) {
+            mqAdminExt.shutdown();
+        }
+        if (Objects.nonNull(schemaRegistryClient)) {
+            schemaRegistryClient = null;

Review Comment:
   Could the `schemaRegistryClient` firstly close and then set to null?



##########
src/main/java/org/apache/rocketmq/flink/catalog/RocketMQCatalog.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.rocketmq.flink.catalog;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.flink.common.constant.RocketMqCatalogConstant;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.remoting.protocol.LanguageCode;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.FieldsDataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Expose a RocketMQ instance as a database catalog. */
+public class RocketMQCatalog extends AbstractCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RocketMQCatalog.class);
+    public static final String DEFAULT_DB = "default";
+    public final String namesrvAddr;
+    private final String schemaRegistryUrl;
+    private DefaultMQAdminExt mqAdminExt;
+    private SchemaRegistryClient schemaRegistryClient;
+
+    public RocketMQCatalog(
+            String catalogName, String database, String namesrvAddr, String schemaRegistryUrl) {
+        super(catalogName, database);
+        this.namesrvAddr = namesrvAddr;
+        this.schemaRegistryUrl = schemaRegistryUrl;
+        LOG.info("Created RocketMQ Catalog {}", catalogName);
+    }
+
+    @Override
+    public Optional<Factory> getFactory() {
+        return Optional.of(new RocketMQCatalogFactory());
+    }
+
+    @Override
+    public void open() throws CatalogException {
+        if (mqAdminExt == null) {
+            try {
+                mqAdminExt = new DefaultMQAdminExt();
+                mqAdminExt.setNamesrvAddr(namesrvAddr);
+                mqAdminExt.setLanguage(LanguageCode.JAVA);
+                mqAdminExt.start();
+            } catch (MQClientException e) {
+                throw new CatalogException(
+                        "Failed to create RocketMQ admin using :" + namesrvAddr, e);
+            }
+        }
+        if (schemaRegistryClient == null) {
+            schemaRegistryClient = SchemaRegistryClientFactory.newClient(schemaRegistryUrl, null);
+        }
+    }
+
+    @Override
+    public void close() throws CatalogException {
+        if (Objects.nonNull(mqAdminExt)) {
+            mqAdminExt.shutdown();
+        }
+        if (Objects.nonNull(schemaRegistryClient)) {
+            schemaRegistryClient = null;
+        }
+    }
+
+    @Override
+    public List<String> listDatabases() throws CatalogException {
+        return Collections.singletonList(getDefaultDatabase());
+    }
+
+    @Override
+    public CatalogDatabase getDatabase(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (StringUtils.isEmpty(databaseName)) {
+            throw new CatalogException("Database name can not be null or empty.");
+        }
+        if (!databaseExists(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        } else {
+            return new CatalogDatabaseImpl(new HashMap<>(), null);
+        }
+    }
+
+    @Override
+    public boolean databaseExists(String databaseName) throws CatalogException {
+        return getDefaultDatabase().equals(databaseName);
+    }
+
+    @Override
+    public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists)
+            throws DatabaseAlreadyExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade)
+            throws DatabaseNotExistException, DatabaseNotEmptyException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<String> listTables(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (!getDefaultDatabase().equals(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        }
+        try {
+            List<String> tables = schemaRegistryClient.getSubjectsByTenant("default", "default");
+            return tables;
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get topics from schema registry client.", e);

Review Comment:
   ```suggestion
               throw new CatalogException(String.format("Failed to get topics of namespace %s from schema registry client.", databaseName), e);
   ```



##########
src/main/java/org/apache/rocketmq/flink/catalog/RocketMQCatalog.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.rocketmq.flink.catalog;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.flink.common.constant.RocketMqCatalogConstant;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.remoting.protocol.LanguageCode;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.FieldsDataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Expose a RocketMQ instance as a database catalog. */
+public class RocketMQCatalog extends AbstractCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RocketMQCatalog.class);
+    public static final String DEFAULT_DB = "default";
+    public final String namesrvAddr;
+    private final String schemaRegistryUrl;
+    private DefaultMQAdminExt mqAdminExt;
+    private SchemaRegistryClient schemaRegistryClient;
+
+    public RocketMQCatalog(
+            String catalogName, String database, String namesrvAddr, String schemaRegistryUrl) {
+        super(catalogName, database);
+        this.namesrvAddr = namesrvAddr;
+        this.schemaRegistryUrl = schemaRegistryUrl;

Review Comment:
   Adds checkArgument(!isNullOrWhitespaceOnly(schemaRegistryUrl), "schemaRegistryUrl cannot be null or empty");



##########
src/main/java/org/apache/rocketmq/flink/catalog/RocketMQCatalog.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.rocketmq.flink.catalog;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.flink.common.constant.RocketMqCatalogConstant;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.remoting.protocol.LanguageCode;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.FieldsDataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Expose a RocketMQ instance as a database catalog. */
+public class RocketMQCatalog extends AbstractCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RocketMQCatalog.class);
+    public static final String DEFAULT_DB = "default";
+    public final String namesrvAddr;
+    private final String schemaRegistryUrl;
+    private DefaultMQAdminExt mqAdminExt;
+    private SchemaRegistryClient schemaRegistryClient;
+
+    public RocketMQCatalog(
+            String catalogName, String database, String namesrvAddr, String schemaRegistryUrl) {
+        super(catalogName, database);
+        this.namesrvAddr = namesrvAddr;
+        this.schemaRegistryUrl = schemaRegistryUrl;
+        LOG.info("Created RocketMQ Catalog {}", catalogName);
+    }
+
+    @Override
+    public Optional<Factory> getFactory() {
+        return Optional.of(new RocketMQCatalogFactory());
+    }
+
+    @Override
+    public void open() throws CatalogException {
+        if (mqAdminExt == null) {
+            try {
+                mqAdminExt = new DefaultMQAdminExt();
+                mqAdminExt.setNamesrvAddr(namesrvAddr);
+                mqAdminExt.setLanguage(LanguageCode.JAVA);
+                mqAdminExt.start();
+            } catch (MQClientException e) {
+                throw new CatalogException(
+                        "Failed to create RocketMQ admin using :" + namesrvAddr, e);
+            }
+        }
+        if (schemaRegistryClient == null) {
+            schemaRegistryClient = SchemaRegistryClientFactory.newClient(schemaRegistryUrl, null);
+        }
+    }
+
+    @Override
+    public void close() throws CatalogException {
+        if (Objects.nonNull(mqAdminExt)) {
+            mqAdminExt.shutdown();

Review Comment:
   Why not set `mqAdminExt ` to null?



##########
src/main/java/org/apache/rocketmq/flink/catalog/RocketMQCatalog.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.rocketmq.flink.catalog;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.flink.common.constant.RocketMqCatalogConstant;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.remoting.protocol.LanguageCode;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.FieldsDataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Expose a RocketMQ instance as a database catalog. */
+public class RocketMQCatalog extends AbstractCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RocketMQCatalog.class);
+    public static final String DEFAULT_DB = "default";
+    public final String namesrvAddr;
+    private final String schemaRegistryUrl;
+    private DefaultMQAdminExt mqAdminExt;
+    private SchemaRegistryClient schemaRegistryClient;
+
+    public RocketMQCatalog(
+            String catalogName, String database, String namesrvAddr, String schemaRegistryUrl) {
+        super(catalogName, database);
+        this.namesrvAddr = namesrvAddr;
+        this.schemaRegistryUrl = schemaRegistryUrl;
+        LOG.info("Created RocketMQ Catalog {}", catalogName);
+    }
+
+    @Override
+    public Optional<Factory> getFactory() {
+        return Optional.of(new RocketMQCatalogFactory());
+    }
+
+    @Override
+    public void open() throws CatalogException {
+        if (mqAdminExt == null) {
+            try {
+                mqAdminExt = new DefaultMQAdminExt();
+                mqAdminExt.setNamesrvAddr(namesrvAddr);
+                mqAdminExt.setLanguage(LanguageCode.JAVA);
+                mqAdminExt.start();
+            } catch (MQClientException e) {
+                throw new CatalogException(
+                        "Failed to create RocketMQ admin using :" + namesrvAddr, e);
+            }
+        }
+        if (schemaRegistryClient == null) {
+            schemaRegistryClient = SchemaRegistryClientFactory.newClient(schemaRegistryUrl, null);
+        }
+    }
+
+    @Override
+    public void close() throws CatalogException {
+        if (Objects.nonNull(mqAdminExt)) {
+            mqAdminExt.shutdown();
+        }
+        if (Objects.nonNull(schemaRegistryClient)) {
+            schemaRegistryClient = null;
+        }
+    }
+
+    @Override
+    public List<String> listDatabases() throws CatalogException {
+        return Collections.singletonList(getDefaultDatabase());
+    }
+
+    @Override
+    public CatalogDatabase getDatabase(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (StringUtils.isEmpty(databaseName)) {
+            throw new CatalogException("Database name can not be null or empty.");
+        }
+        if (!databaseExists(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        } else {
+            return new CatalogDatabaseImpl(new HashMap<>(), null);
+        }
+    }
+
+    @Override
+    public boolean databaseExists(String databaseName) throws CatalogException {
+        return getDefaultDatabase().equals(databaseName);
+    }
+
+    @Override
+    public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists)
+            throws DatabaseAlreadyExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade)
+            throws DatabaseNotExistException, DatabaseNotEmptyException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<String> listTables(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (!getDefaultDatabase().equals(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        }
+        try {
+            List<String> tables = schemaRegistryClient.getSubjectsByTenant("default", "default");
+            return tables;
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get topics from schema registry client.", e);
+        }
+    }
+
+    @Override
+    public CatalogBaseTable getTable(ObjectPath tablePath)
+            throws TableNotExistException, CatalogException {
+        if (!tableExists(tablePath)) {
+            throw new TableNotExistException(getName(), tablePath);
+        }
+        String subject = tablePath.getObjectName();
+        try {
+            GetSchemaResponse getSchemaResponse = schemaRegistryClient.getSchemaBySubject(subject);
+            if (getSchemaResponse.getType() != SchemaType.AVRO) {
+                throw new CatalogException("Only support avro schema.");
+            }
+            return getCatalogTableForSchema(subject, getSchemaResponse);
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get schema from schema registry client.", e);
+        }
+    }
+
+    private CatalogTable getCatalogTableForSchema(
+            String topic, GetSchemaResponse getSchemaResponse) {
+        DataType dataType = AvroSchemaConverter.convertToDataType(getSchemaResponse.getIdl());
+        Schema.Builder builder = Schema.newBuilder();
+        if (dataType instanceof FieldsDataType) {
+            FieldsDataType fieldsDataType = (FieldsDataType) dataType;
+            RowType rowType = (RowType) fieldsDataType.getLogicalType();
+            for (RowType.RowField field : rowType.getFields()) {
+                DataType toDataType = TypeConversions.fromLogicalToDataType(field.getType());
+                builder.column(field.getName(), toDataType);
+            }
+        }
+        Schema schema = builder.build();
+        Map<String, String> options = new HashMap<>();
+        options.put(RocketMqCatalogConstant.CONNECTOR, RocketMqCatalogConstant.ROCKETMQ_CONNECTOR);
+        options.put(RocketMqCatalogConstant.TOPIC, topic);
+        options.put(RocketMqCatalogConstant.NAME_SERVER_ADDRESS, mqAdminExt.getNamesrvAddr());
+        return CatalogTable.of(schema, null, Collections.emptyList(), options);
+    }
+
+    @Override
+    public boolean tableExists(ObjectPath tablePath) throws CatalogException {
+        if (!getDefaultDatabase().equals(tablePath.getDatabaseName())) {
+            throw new CatalogException("Database name is not default.");
+        }
+        if (StringUtils.isEmpty(tablePath.getObjectName())) {
+            return false;
+        }
+        String subject = tablePath.getObjectName();
+        try {
+            GetSchemaResponse getSchemaResponse = schemaRegistryClient.getSchemaBySubject(subject);
+            if (Objects.nonNull(getSchemaResponse)) {
+                return true;
+            }
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get topics from schema registry client.", e);

Review Comment:
   ```suggestion
               throw new CatalogException(String.format("Failed to get schema of table %s from schema registry client.", tablePath.getFullName(), e);
   ```



##########
src/main/java/org/apache/rocketmq/flink/catalog/RocketMQCatalog.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.rocketmq.flink.catalog;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.flink.common.constant.RocketMqCatalogConstant;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.remoting.protocol.LanguageCode;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.FieldsDataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Expose a RocketMQ instance as a database catalog. */
+public class RocketMQCatalog extends AbstractCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RocketMQCatalog.class);
+    public static final String DEFAULT_DB = "default";
+    public final String namesrvAddr;
+    private final String schemaRegistryUrl;
+    private DefaultMQAdminExt mqAdminExt;
+    private SchemaRegistryClient schemaRegistryClient;
+
+    public RocketMQCatalog(
+            String catalogName, String database, String namesrvAddr, String schemaRegistryUrl) {
+        super(catalogName, database);
+        this.namesrvAddr = namesrvAddr;
+        this.schemaRegistryUrl = schemaRegistryUrl;
+        LOG.info("Created RocketMQ Catalog {}", catalogName);
+    }
+
+    @Override
+    public Optional<Factory> getFactory() {
+        return Optional.of(new RocketMQCatalogFactory());
+    }
+
+    @Override
+    public void open() throws CatalogException {
+        if (mqAdminExt == null) {
+            try {
+                mqAdminExt = new DefaultMQAdminExt();
+                mqAdminExt.setNamesrvAddr(namesrvAddr);
+                mqAdminExt.setLanguage(LanguageCode.JAVA);
+                mqAdminExt.start();
+            } catch (MQClientException e) {
+                throw new CatalogException(
+                        "Failed to create RocketMQ admin using :" + namesrvAddr, e);
+            }
+        }
+        if (schemaRegistryClient == null) {
+            schemaRegistryClient = SchemaRegistryClientFactory.newClient(schemaRegistryUrl, null);
+        }
+    }
+
+    @Override
+    public void close() throws CatalogException {
+        if (Objects.nonNull(mqAdminExt)) {
+            mqAdminExt.shutdown();
+        }
+        if (Objects.nonNull(schemaRegistryClient)) {
+            schemaRegistryClient = null;
+        }
+    }
+
+    @Override
+    public List<String> listDatabases() throws CatalogException {
+        return Collections.singletonList(getDefaultDatabase());
+    }
+
+    @Override
+    public CatalogDatabase getDatabase(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (StringUtils.isEmpty(databaseName)) {
+            throw new CatalogException("Database name can not be null or empty.");
+        }
+        if (!databaseExists(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        } else {
+            return new CatalogDatabaseImpl(new HashMap<>(), null);
+        }
+    }
+
+    @Override
+    public boolean databaseExists(String databaseName) throws CatalogException {
+        return getDefaultDatabase().equals(databaseName);
+    }
+
+    @Override
+    public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists)
+            throws DatabaseAlreadyExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade)
+            throws DatabaseNotExistException, DatabaseNotEmptyException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<String> listTables(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (!getDefaultDatabase().equals(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        }
+        try {
+            List<String> tables = schemaRegistryClient.getSubjectsByTenant("default", "default");
+            return tables;
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get topics from schema registry client.", e);
+        }
+    }
+
+    @Override
+    public CatalogBaseTable getTable(ObjectPath tablePath)
+            throws TableNotExistException, CatalogException {
+        if (!tableExists(tablePath)) {
+            throw new TableNotExistException(getName(), tablePath);
+        }
+        String subject = tablePath.getObjectName();
+        try {
+            GetSchemaResponse getSchemaResponse = schemaRegistryClient.getSchemaBySubject(subject);
+            if (getSchemaResponse.getType() != SchemaType.AVRO) {
+                throw new CatalogException("Only support avro schema.");
+            }
+            return getCatalogTableForSchema(subject, getSchemaResponse);
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get schema from schema registry client.", e);
+        }
+    }
+
+    private CatalogTable getCatalogTableForSchema(
+            String topic, GetSchemaResponse getSchemaResponse) {
+        DataType dataType = AvroSchemaConverter.convertToDataType(getSchemaResponse.getIdl());
+        Schema.Builder builder = Schema.newBuilder();
+        if (dataType instanceof FieldsDataType) {
+            FieldsDataType fieldsDataType = (FieldsDataType) dataType;
+            RowType rowType = (RowType) fieldsDataType.getLogicalType();
+            for (RowType.RowField field : rowType.getFields()) {
+                DataType toDataType = TypeConversions.fromLogicalToDataType(field.getType());
+                builder.column(field.getName(), toDataType);
+            }
+        }
+        Schema schema = builder.build();
+        Map<String, String> options = new HashMap<>();
+        options.put(RocketMqCatalogConstant.CONNECTOR, RocketMqCatalogConstant.ROCKETMQ_CONNECTOR);
+        options.put(RocketMqCatalogConstant.TOPIC, topic);
+        options.put(RocketMqCatalogConstant.NAME_SERVER_ADDRESS, mqAdminExt.getNamesrvAddr());
+        return CatalogTable.of(schema, null, Collections.emptyList(), options);
+    }
+
+    @Override
+    public boolean tableExists(ObjectPath tablePath) throws CatalogException {
+        if (!getDefaultDatabase().equals(tablePath.getDatabaseName())) {
+            throw new CatalogException("Database name is not default.");
+        }
+        if (StringUtils.isEmpty(tablePath.getObjectName())) {
+            return false;
+        }
+        String subject = tablePath.getObjectName();
+        try {
+            GetSchemaResponse getSchemaResponse = schemaRegistryClient.getSchemaBySubject(subject);
+            if (Objects.nonNull(getSchemaResponse)) {
+                return true;
+            }
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get topics from schema registry client.", e);
+        }
+        return false;
+    }
+
+    @Override
+    public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
+            throws TableAlreadyExistException, DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists)
+            throws TableNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    // ------------------------------------------------------------------------
+    // Unsupported catalog operations for RocketMQ
+    // There should not be such permission in the connector, it is very dangerous
+    // ------------------------------------------------------------------------
+
+    @Override
+    public List<String> listFunctions(String dbName)
+            throws DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public CatalogFunction getFunction(ObjectPath functionPath)
+            throws FunctionNotExistException, CatalogException {
+        throw new FunctionNotExistException("Not support to find functions.", functionPath);
+    }
+
+    @Override
+    public boolean functionExists(ObjectPath functionPath) throws CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void createFunction(
+            ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists)
+            throws FunctionAlreadyExistException, DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void alterFunction(
+            ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists)
+            throws FunctionNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropFunction(ObjectPath functionPath, boolean ignoreIfNotExists)
+            throws FunctionNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void alterDatabase(String name, CatalogDatabase newDatabase, boolean ignoreIfNotExists)
+            throws DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<String> listViews(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void alterTable(
+            ObjectPath tablePath, CatalogBaseTable newTable, boolean ignoreIfNotExists)
+            throws TableNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists)
+            throws TableNotExistException, TableAlreadyExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<CatalogPartitionSpec> listPartitions(ObjectPath tablePath)
+            throws TableNotExistException, TableNotPartitionedException, CatalogException {
+        checkNotNull(tablePath, "Table path cannot be null");
+
+        try {
+            TopicStatsTable topicStatsTable =
+                    mqAdminExt.examineTopicStats(tablePath.getObjectName());
+            return topicStatsTable.getOffsetTable().keySet().stream()
+                    .map(
+                            topicOffset ->
+                                    new CatalogPartitionSpec(
+                                            new HashMap<String, String>(1) {
+                                                {
+                                                    String queueId =
+                                                            String.valueOf(
+                                                                    topicOffset.getQueueId());
+                                                    put("__queue_id__", queueId);
+                                                }
+                                            }))
+                    .collect(Collectors.toList());
+        } catch (RemotingException e) {
+            throw new RuntimeException(e);
+        } catch (MQClientException e) {
+            throw new RuntimeException(e);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        } catch (MQBrokerException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public List<CatalogPartitionSpec> listPartitions(
+            ObjectPath tablePath, CatalogPartitionSpec partitionSpec)
+            throws TableNotExistException, TableNotPartitionedException, CatalogException {
+        return listPartitions(tablePath);
+    }
+
+    @Override
+    public List<CatalogPartitionSpec> listPartitionsByFilter(
+            ObjectPath tablePath, List<Expression> expressions)
+            throws TableNotExistException, TableNotPartitionedException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public CatalogPartition getPartition(ObjectPath tablePath, CatalogPartitionSpec partitionSpec)

Review Comment:
   Adds the implementation of the `getPartition` interface.



##########
src/main/java/org/apache/rocketmq/flink/catalog/RocketMQCatalog.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.rocketmq.flink.catalog;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.flink.common.constant.RocketMqCatalogConstant;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.remoting.protocol.LanguageCode;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.FieldsDataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Expose a RocketMQ instance as a database catalog. */
+public class RocketMQCatalog extends AbstractCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RocketMQCatalog.class);
+    public static final String DEFAULT_DB = "default";
+    public final String namesrvAddr;
+    private final String schemaRegistryUrl;
+    private DefaultMQAdminExt mqAdminExt;
+    private SchemaRegistryClient schemaRegistryClient;
+
+    public RocketMQCatalog(
+            String catalogName, String database, String namesrvAddr, String schemaRegistryUrl) {
+        super(catalogName, database);
+        this.namesrvAddr = namesrvAddr;
+        this.schemaRegistryUrl = schemaRegistryUrl;
+        LOG.info("Created RocketMQ Catalog {}", catalogName);
+    }
+
+    @Override
+    public Optional<Factory> getFactory() {
+        return Optional.of(new RocketMQCatalogFactory());
+    }
+
+    @Override
+    public void open() throws CatalogException {
+        if (mqAdminExt == null) {
+            try {
+                mqAdminExt = new DefaultMQAdminExt();
+                mqAdminExt.setNamesrvAddr(namesrvAddr);
+                mqAdminExt.setLanguage(LanguageCode.JAVA);
+                mqAdminExt.start();
+            } catch (MQClientException e) {
+                throw new CatalogException(
+                        "Failed to create RocketMQ admin using :" + namesrvAddr, e);
+            }
+        }
+        if (schemaRegistryClient == null) {
+            schemaRegistryClient = SchemaRegistryClientFactory.newClient(schemaRegistryUrl, null);
+        }
+    }
+
+    @Override
+    public void close() throws CatalogException {
+        if (Objects.nonNull(mqAdminExt)) {
+            mqAdminExt.shutdown();
+        }
+        if (Objects.nonNull(schemaRegistryClient)) {
+            schemaRegistryClient = null;
+        }
+    }
+
+    @Override
+    public List<String> listDatabases() throws CatalogException {
+        return Collections.singletonList(getDefaultDatabase());
+    }
+
+    @Override
+    public CatalogDatabase getDatabase(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (StringUtils.isEmpty(databaseName)) {
+            throw new CatalogException("Database name can not be null or empty.");
+        }
+        if (!databaseExists(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        } else {
+            return new CatalogDatabaseImpl(new HashMap<>(), null);
+        }
+    }
+
+    @Override
+    public boolean databaseExists(String databaseName) throws CatalogException {
+        return getDefaultDatabase().equals(databaseName);
+    }
+
+    @Override
+    public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists)
+            throws DatabaseAlreadyExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade)
+            throws DatabaseNotExistException, DatabaseNotEmptyException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<String> listTables(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (!getDefaultDatabase().equals(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        }
+        try {
+            List<String> tables = schemaRegistryClient.getSubjectsByTenant("default", "default");
+            return tables;
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get topics from schema registry client.", e);
+        }
+    }
+
+    @Override
+    public CatalogBaseTable getTable(ObjectPath tablePath)
+            throws TableNotExistException, CatalogException {
+        if (!tableExists(tablePath)) {
+            throw new TableNotExistException(getName(), tablePath);
+        }
+        String subject = tablePath.getObjectName();
+        try {
+            GetSchemaResponse getSchemaResponse = schemaRegistryClient.getSchemaBySubject(subject);
+            if (getSchemaResponse.getType() != SchemaType.AVRO) {
+                throw new CatalogException("Only support avro schema.");
+            }
+            return getCatalogTableForSchema(subject, getSchemaResponse);
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get schema from schema registry client.", e);
+        }
+    }
+
+    private CatalogTable getCatalogTableForSchema(
+            String topic, GetSchemaResponse getSchemaResponse) {
+        DataType dataType = AvroSchemaConverter.convertToDataType(getSchemaResponse.getIdl());
+        Schema.Builder builder = Schema.newBuilder();
+        if (dataType instanceof FieldsDataType) {
+            FieldsDataType fieldsDataType = (FieldsDataType) dataType;
+            RowType rowType = (RowType) fieldsDataType.getLogicalType();
+            for (RowType.RowField field : rowType.getFields()) {
+                DataType toDataType = TypeConversions.fromLogicalToDataType(field.getType());
+                builder.column(field.getName(), toDataType);
+            }
+        }
+        Schema schema = builder.build();
+        Map<String, String> options = new HashMap<>();
+        options.put(RocketMqCatalogConstant.CONNECTOR, RocketMqCatalogConstant.ROCKETMQ_CONNECTOR);
+        options.put(RocketMqCatalogConstant.TOPIC, topic);
+        options.put(RocketMqCatalogConstant.NAME_SERVER_ADDRESS, mqAdminExt.getNamesrvAddr());
+        return CatalogTable.of(schema, null, Collections.emptyList(), options);
+    }
+
+    @Override
+    public boolean tableExists(ObjectPath tablePath) throws CatalogException {
+        if (!getDefaultDatabase().equals(tablePath.getDatabaseName())) {
+            throw new CatalogException("Database name is not default.");
+        }
+        if (StringUtils.isEmpty(tablePath.getObjectName())) {
+            return false;
+        }
+        String subject = tablePath.getObjectName();
+        try {
+            GetSchemaResponse getSchemaResponse = schemaRegistryClient.getSchemaBySubject(subject);
+            if (Objects.nonNull(getSchemaResponse)) {
+                return true;
+            }
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get topics from schema registry client.", e);
+        }
+        return false;
+    }
+
+    @Override
+    public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
+            throws TableAlreadyExistException, DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists)
+            throws TableNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    // ------------------------------------------------------------------------
+    // Unsupported catalog operations for RocketMQ
+    // There should not be such permission in the connector, it is very dangerous
+    // ------------------------------------------------------------------------
+
+    @Override
+    public List<String> listFunctions(String dbName)
+            throws DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public CatalogFunction getFunction(ObjectPath functionPath)
+            throws FunctionNotExistException, CatalogException {
+        throw new FunctionNotExistException("Not support to find functions.", functionPath);
+    }
+
+    @Override
+    public boolean functionExists(ObjectPath functionPath) throws CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void createFunction(
+            ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists)
+            throws FunctionAlreadyExistException, DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void alterFunction(
+            ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists)
+            throws FunctionNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropFunction(ObjectPath functionPath, boolean ignoreIfNotExists)
+            throws FunctionNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void alterDatabase(String name, CatalogDatabase newDatabase, boolean ignoreIfNotExists)
+            throws DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<String> listViews(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void alterTable(
+            ObjectPath tablePath, CatalogBaseTable newTable, boolean ignoreIfNotExists)
+            throws TableNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists)
+            throws TableNotExistException, TableAlreadyExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<CatalogPartitionSpec> listPartitions(ObjectPath tablePath)
+            throws TableNotExistException, TableNotPartitionedException, CatalogException {
+        checkNotNull(tablePath, "Table path cannot be null");
+
+        try {
+            TopicStatsTable topicStatsTable =
+                    mqAdminExt.examineTopicStats(tablePath.getObjectName());
+            return topicStatsTable.getOffsetTable().keySet().stream()
+                    .map(
+                            topicOffset ->
+                                    new CatalogPartitionSpec(
+                                            new HashMap<String, String>(1) {
+                                                {
+                                                    String queueId =
+                                                            String.valueOf(
+                                                                    topicOffset.getQueueId());
+                                                    put("__queue_id__", queueId);
+                                                }
+                                            }))
+                    .collect(Collectors.toList());
+        } catch (RemotingException e) {
+            throw new RuntimeException(e);
+        } catch (MQClientException e) {
+            throw new RuntimeException(e);
+        } catch (InterruptedException e) {
+            throw new RuntimeException(e);
+        } catch (MQBrokerException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    @Override
+    public List<CatalogPartitionSpec> listPartitions(

Review Comment:
   Ditto.



##########
src/main/java/org/apache/rocketmq/flink/catalog/RocketMQCatalog.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.rocketmq.flink.catalog;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.flink.common.constant.RocketMqCatalogConstant;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.remoting.protocol.LanguageCode;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.FieldsDataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Expose a RocketMQ instance as a database catalog. */
+public class RocketMQCatalog extends AbstractCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RocketMQCatalog.class);
+    public static final String DEFAULT_DB = "default";
+    public final String namesrvAddr;
+    private final String schemaRegistryUrl;
+    private DefaultMQAdminExt mqAdminExt;
+    private SchemaRegistryClient schemaRegistryClient;
+
+    public RocketMQCatalog(
+            String catalogName, String database, String namesrvAddr, String schemaRegistryUrl) {
+        super(catalogName, database);
+        this.namesrvAddr = namesrvAddr;
+        this.schemaRegistryUrl = schemaRegistryUrl;
+        LOG.info("Created RocketMQ Catalog {}", catalogName);
+    }
+
+    @Override
+    public Optional<Factory> getFactory() {
+        return Optional.of(new RocketMQCatalogFactory());
+    }
+
+    @Override
+    public void open() throws CatalogException {
+        if (mqAdminExt == null) {
+            try {
+                mqAdminExt = new DefaultMQAdminExt();
+                mqAdminExt.setNamesrvAddr(namesrvAddr);
+                mqAdminExt.setLanguage(LanguageCode.JAVA);
+                mqAdminExt.start();
+            } catch (MQClientException e) {
+                throw new CatalogException(
+                        "Failed to create RocketMQ admin using :" + namesrvAddr, e);
+            }
+        }
+        if (schemaRegistryClient == null) {
+            schemaRegistryClient = SchemaRegistryClientFactory.newClient(schemaRegistryUrl, null);
+        }
+    }
+
+    @Override
+    public void close() throws CatalogException {
+        if (Objects.nonNull(mqAdminExt)) {
+            mqAdminExt.shutdown();
+        }
+        if (Objects.nonNull(schemaRegistryClient)) {
+            schemaRegistryClient = null;
+        }
+    }
+
+    @Override
+    public List<String> listDatabases() throws CatalogException {
+        return Collections.singletonList(getDefaultDatabase());
+    }
+
+    @Override
+    public CatalogDatabase getDatabase(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (StringUtils.isEmpty(databaseName)) {
+            throw new CatalogException("Database name can not be null or empty.");
+        }
+        if (!databaseExists(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        } else {
+            return new CatalogDatabaseImpl(new HashMap<>(), null);
+        }
+    }
+
+    @Override
+    public boolean databaseExists(String databaseName) throws CatalogException {
+        return getDefaultDatabase().equals(databaseName);
+    }
+
+    @Override
+    public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists)
+            throws DatabaseAlreadyExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade)
+            throws DatabaseNotExistException, DatabaseNotEmptyException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<String> listTables(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (!getDefaultDatabase().equals(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        }
+        try {
+            List<String> tables = schemaRegistryClient.getSubjectsByTenant("default", "default");
+            return tables;
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get topics from schema registry client.", e);
+        }
+    }
+
+    @Override
+    public CatalogBaseTable getTable(ObjectPath tablePath)
+            throws TableNotExistException, CatalogException {
+        if (!tableExists(tablePath)) {
+            throw new TableNotExistException(getName(), tablePath);
+        }
+        String subject = tablePath.getObjectName();
+        try {
+            GetSchemaResponse getSchemaResponse = schemaRegistryClient.getSchemaBySubject(subject);
+            if (getSchemaResponse.getType() != SchemaType.AVRO) {
+                throw new CatalogException("Only support avro schema.");
+            }
+            return getCatalogTableForSchema(subject, getSchemaResponse);
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get schema from schema registry client.", e);
+        }
+    }
+
+    private CatalogTable getCatalogTableForSchema(
+            String topic, GetSchemaResponse getSchemaResponse) {
+        DataType dataType = AvroSchemaConverter.convertToDataType(getSchemaResponse.getIdl());
+        Schema.Builder builder = Schema.newBuilder();
+        if (dataType instanceof FieldsDataType) {
+            FieldsDataType fieldsDataType = (FieldsDataType) dataType;
+            RowType rowType = (RowType) fieldsDataType.getLogicalType();
+            for (RowType.RowField field : rowType.getFields()) {
+                DataType toDataType = TypeConversions.fromLogicalToDataType(field.getType());
+                builder.column(field.getName(), toDataType);
+            }
+        }
+        Schema schema = builder.build();
+        Map<String, String> options = new HashMap<>();
+        options.put(RocketMqCatalogConstant.CONNECTOR, RocketMqCatalogConstant.ROCKETMQ_CONNECTOR);
+        options.put(RocketMqCatalogConstant.TOPIC, topic);
+        options.put(RocketMqCatalogConstant.NAME_SERVER_ADDRESS, mqAdminExt.getNamesrvAddr());
+        return CatalogTable.of(schema, null, Collections.emptyList(), options);
+    }
+
+    @Override
+    public boolean tableExists(ObjectPath tablePath) throws CatalogException {
+        if (!getDefaultDatabase().equals(tablePath.getDatabaseName())) {
+            throw new CatalogException("Database name is not default.");
+        }
+        if (StringUtils.isEmpty(tablePath.getObjectName())) {
+            return false;
+        }
+        String subject = tablePath.getObjectName();
+        try {
+            GetSchemaResponse getSchemaResponse = schemaRegistryClient.getSchemaBySubject(subject);
+            if (Objects.nonNull(getSchemaResponse)) {
+                return true;
+            }
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get topics from schema registry client.", e);
+        }
+        return false;
+    }
+
+    @Override
+    public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
+            throws TableAlreadyExistException, DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists)
+            throws TableNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    // ------------------------------------------------------------------------
+    // Unsupported catalog operations for RocketMQ
+    // There should not be such permission in the connector, it is very dangerous
+    // ------------------------------------------------------------------------
+
+    @Override
+    public List<String> listFunctions(String dbName)
+            throws DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public CatalogFunction getFunction(ObjectPath functionPath)
+            throws FunctionNotExistException, CatalogException {
+        throw new FunctionNotExistException("Not support to find functions.", functionPath);
+    }
+
+    @Override
+    public boolean functionExists(ObjectPath functionPath) throws CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void createFunction(
+            ObjectPath functionPath, CatalogFunction function, boolean ignoreIfExists)
+            throws FunctionAlreadyExistException, DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void alterFunction(
+            ObjectPath functionPath, CatalogFunction newFunction, boolean ignoreIfNotExists)
+            throws FunctionNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropFunction(ObjectPath functionPath, boolean ignoreIfNotExists)
+            throws FunctionNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void alterDatabase(String name, CatalogDatabase newDatabase, boolean ignoreIfNotExists)
+            throws DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<String> listViews(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void alterTable(
+            ObjectPath tablePath, CatalogBaseTable newTable, boolean ignoreIfNotExists)
+            throws TableNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void renameTable(ObjectPath tablePath, String newTableName, boolean ignoreIfNotExists)
+            throws TableNotExistException, TableAlreadyExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<CatalogPartitionSpec> listPartitions(ObjectPath tablePath)

Review Comment:
   Moves this interface before the comment ` Unsupported catalog operations for RocketMQ`.



##########
src/main/java/org/apache/rocketmq/flink/catalog/RocketMQCatalog.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.rocketmq.flink.catalog;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.flink.common.constant.RocketMqCatalogConstant;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.remoting.protocol.LanguageCode;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.FieldsDataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Expose a RocketMQ instance as a database catalog. */

Review Comment:
   ```suggestion
   /** A catalog implementation for RocketMQ. */
   ```



##########
src/main/java/org/apache/rocketmq/flink/catalog/RocketMQCatalog.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.rocketmq.flink.catalog;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.flink.common.constant.RocketMqCatalogConstant;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.remoting.protocol.LanguageCode;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.FieldsDataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Expose a RocketMQ instance as a database catalog. */
+public class RocketMQCatalog extends AbstractCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RocketMQCatalog.class);
+    public static final String DEFAULT_DB = "default";
+    public final String namesrvAddr;
+    private final String schemaRegistryUrl;
+    private DefaultMQAdminExt mqAdminExt;
+    private SchemaRegistryClient schemaRegistryClient;
+
+    public RocketMQCatalog(
+            String catalogName, String database, String namesrvAddr, String schemaRegistryUrl) {
+        super(catalogName, database);
+        this.namesrvAddr = namesrvAddr;
+        this.schemaRegistryUrl = schemaRegistryUrl;
+        LOG.info("Created RocketMQ Catalog {}", catalogName);
+    }
+
+    @Override
+    public Optional<Factory> getFactory() {
+        return Optional.of(new RocketMQCatalogFactory());
+    }
+
+    @Override
+    public void open() throws CatalogException {
+        if (mqAdminExt == null) {
+            try {
+                mqAdminExt = new DefaultMQAdminExt();
+                mqAdminExt.setNamesrvAddr(namesrvAddr);
+                mqAdminExt.setLanguage(LanguageCode.JAVA);
+                mqAdminExt.start();
+            } catch (MQClientException e) {
+                throw new CatalogException(
+                        "Failed to create RocketMQ admin using :" + namesrvAddr, e);
+            }
+        }
+        if (schemaRegistryClient == null) {
+            schemaRegistryClient = SchemaRegistryClientFactory.newClient(schemaRegistryUrl, null);
+        }
+    }
+
+    @Override
+    public void close() throws CatalogException {
+        if (Objects.nonNull(mqAdminExt)) {
+            mqAdminExt.shutdown();
+        }
+        if (Objects.nonNull(schemaRegistryClient)) {
+            schemaRegistryClient = null;
+        }
+    }
+
+    @Override
+    public List<String> listDatabases() throws CatalogException {
+        return Collections.singletonList(getDefaultDatabase());
+    }
+
+    @Override
+    public CatalogDatabase getDatabase(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (StringUtils.isEmpty(databaseName)) {
+            throw new CatalogException("Database name can not be null or empty.");
+        }
+        if (!databaseExists(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        } else {
+            return new CatalogDatabaseImpl(new HashMap<>(), null);
+        }
+    }
+
+    @Override
+    public boolean databaseExists(String databaseName) throws CatalogException {
+        return getDefaultDatabase().equals(databaseName);
+    }
+
+    @Override
+    public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists)
+            throws DatabaseAlreadyExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade)
+            throws DatabaseNotExistException, DatabaseNotEmptyException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<String> listTables(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (!getDefaultDatabase().equals(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        }
+        try {
+            List<String> tables = schemaRegistryClient.getSubjectsByTenant("default", "default");
+            return tables;
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get topics from schema registry client.", e);
+        }
+    }
+
+    @Override
+    public CatalogBaseTable getTable(ObjectPath tablePath)
+            throws TableNotExistException, CatalogException {
+        if (!tableExists(tablePath)) {
+            throw new TableNotExistException(getName(), tablePath);
+        }
+        String subject = tablePath.getObjectName();
+        try {
+            GetSchemaResponse getSchemaResponse = schemaRegistryClient.getSchemaBySubject(subject);
+            if (getSchemaResponse.getType() != SchemaType.AVRO) {
+                throw new CatalogException("Only support avro schema.");
+            }
+            return getCatalogTableForSchema(subject, getSchemaResponse);
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get schema from schema registry client.", e);

Review Comment:
   ```suggestion
               throw new CatalogException(String.format("Failed to get schema of table %s from schema registry client.", tablePath.getFullName(), e);
   ```



##########
src/main/java/org/apache/rocketmq/flink/catalog/RocketMQCatalog.java:
##########
@@ -0,0 +1,471 @@
+/*
+ * 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.rocketmq.flink.catalog;
+
+import org.apache.rocketmq.client.exception.MQBrokerException;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.admin.TopicStatsTable;
+import org.apache.rocketmq.flink.common.constant.RocketMqCatalogConstant;
+import org.apache.rocketmq.remoting.exception.RemotingException;
+import org.apache.rocketmq.remoting.protocol.LanguageCode;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClient;
+import org.apache.rocketmq.schema.registry.client.SchemaRegistryClientFactory;
+import org.apache.rocketmq.schema.registry.common.dto.GetSchemaResponse;
+import org.apache.rocketmq.schema.registry.common.model.SchemaType;
+import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;
+
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.catalog.AbstractCatalog;
+import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
+import org.apache.flink.table.catalog.CatalogFunction;
+import org.apache.flink.table.catalog.CatalogPartition;
+import org.apache.flink.table.catalog.CatalogPartitionSpec;
+import org.apache.flink.table.catalog.CatalogTable;
+import org.apache.flink.table.catalog.ObjectPath;
+import org.apache.flink.table.catalog.exceptions.CatalogException;
+import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException;
+import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.FunctionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException;
+import org.apache.flink.table.catalog.exceptions.PartitionNotExistException;
+import org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException;
+import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotExistException;
+import org.apache.flink.table.catalog.exceptions.TableNotPartitionedException;
+import org.apache.flink.table.catalog.stats.CatalogColumnStatistics;
+import org.apache.flink.table.catalog.stats.CatalogTableStatistics;
+import org.apache.flink.table.expressions.Expression;
+import org.apache.flink.table.factories.Factory;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.FieldsDataType;
+import org.apache.flink.table.types.logical.RowType;
+import org.apache.flink.table.types.utils.TypeConversions;
+
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/** Expose a RocketMQ instance as a database catalog. */
+public class RocketMQCatalog extends AbstractCatalog {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RocketMQCatalog.class);
+    public static final String DEFAULT_DB = "default";
+    public final String namesrvAddr;
+    private final String schemaRegistryUrl;
+    private DefaultMQAdminExt mqAdminExt;
+    private SchemaRegistryClient schemaRegistryClient;
+
+    public RocketMQCatalog(
+            String catalogName, String database, String namesrvAddr, String schemaRegistryUrl) {
+        super(catalogName, database);
+        this.namesrvAddr = namesrvAddr;
+        this.schemaRegistryUrl = schemaRegistryUrl;
+        LOG.info("Created RocketMQ Catalog {}", catalogName);
+    }
+
+    @Override
+    public Optional<Factory> getFactory() {
+        return Optional.of(new RocketMQCatalogFactory());
+    }
+
+    @Override
+    public void open() throws CatalogException {
+        if (mqAdminExt == null) {
+            try {
+                mqAdminExt = new DefaultMQAdminExt();
+                mqAdminExt.setNamesrvAddr(namesrvAddr);
+                mqAdminExt.setLanguage(LanguageCode.JAVA);
+                mqAdminExt.start();
+            } catch (MQClientException e) {
+                throw new CatalogException(
+                        "Failed to create RocketMQ admin using :" + namesrvAddr, e);
+            }
+        }
+        if (schemaRegistryClient == null) {
+            schemaRegistryClient = SchemaRegistryClientFactory.newClient(schemaRegistryUrl, null);
+        }
+    }
+
+    @Override
+    public void close() throws CatalogException {
+        if (Objects.nonNull(mqAdminExt)) {
+            mqAdminExt.shutdown();
+        }
+        if (Objects.nonNull(schemaRegistryClient)) {
+            schemaRegistryClient = null;
+        }
+    }
+
+    @Override
+    public List<String> listDatabases() throws CatalogException {
+        return Collections.singletonList(getDefaultDatabase());
+    }
+
+    @Override
+    public CatalogDatabase getDatabase(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (StringUtils.isEmpty(databaseName)) {
+            throw new CatalogException("Database name can not be null or empty.");
+        }
+        if (!databaseExists(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        } else {
+            return new CatalogDatabaseImpl(new HashMap<>(), null);
+        }
+    }
+
+    @Override
+    public boolean databaseExists(String databaseName) throws CatalogException {
+        return getDefaultDatabase().equals(databaseName);
+    }
+
+    @Override
+    public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists)
+            throws DatabaseAlreadyExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropDatabase(String name, boolean ignoreIfNotExists, boolean cascade)
+            throws DatabaseNotExistException, DatabaseNotEmptyException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public List<String> listTables(String databaseName)
+            throws DatabaseNotExistException, CatalogException {
+        if (!getDefaultDatabase().equals(databaseName)) {
+            throw new DatabaseNotExistException(getName(), databaseName);
+        }
+        try {
+            List<String> tables = schemaRegistryClient.getSubjectsByTenant("default", "default");
+            return tables;
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get topics from schema registry client.", e);
+        }
+    }
+
+    @Override
+    public CatalogBaseTable getTable(ObjectPath tablePath)
+            throws TableNotExistException, CatalogException {
+        if (!tableExists(tablePath)) {
+            throw new TableNotExistException(getName(), tablePath);
+        }
+        String subject = tablePath.getObjectName();
+        try {
+            GetSchemaResponse getSchemaResponse = schemaRegistryClient.getSchemaBySubject(subject);
+            if (getSchemaResponse.getType() != SchemaType.AVRO) {
+                throw new CatalogException("Only support avro schema.");
+            }
+            return getCatalogTableForSchema(subject, getSchemaResponse);
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get schema from schema registry client.", e);
+        }
+    }
+
+    private CatalogTable getCatalogTableForSchema(
+            String topic, GetSchemaResponse getSchemaResponse) {
+        DataType dataType = AvroSchemaConverter.convertToDataType(getSchemaResponse.getIdl());
+        Schema.Builder builder = Schema.newBuilder();
+        if (dataType instanceof FieldsDataType) {
+            FieldsDataType fieldsDataType = (FieldsDataType) dataType;
+            RowType rowType = (RowType) fieldsDataType.getLogicalType();
+            for (RowType.RowField field : rowType.getFields()) {
+                DataType toDataType = TypeConversions.fromLogicalToDataType(field.getType());
+                builder.column(field.getName(), toDataType);
+            }
+        }
+        Schema schema = builder.build();
+        Map<String, String> options = new HashMap<>();
+        options.put(RocketMqCatalogConstant.CONNECTOR, RocketMqCatalogConstant.ROCKETMQ_CONNECTOR);
+        options.put(RocketMqCatalogConstant.TOPIC, topic);
+        options.put(RocketMqCatalogConstant.NAME_SERVER_ADDRESS, mqAdminExt.getNamesrvAddr());
+        return CatalogTable.of(schema, null, Collections.emptyList(), options);
+    }
+
+    @Override
+    public boolean tableExists(ObjectPath tablePath) throws CatalogException {
+        if (!getDefaultDatabase().equals(tablePath.getDatabaseName())) {
+            throw new CatalogException("Database name is not default.");
+        }
+        if (StringUtils.isEmpty(tablePath.getObjectName())) {
+            return false;
+        }
+        String subject = tablePath.getObjectName();
+        try {
+            GetSchemaResponse getSchemaResponse = schemaRegistryClient.getSchemaBySubject(subject);
+            if (Objects.nonNull(getSchemaResponse)) {
+                return true;
+            }
+        } catch (Exception e) {
+            throw new CatalogException("Fail to get topics from schema registry client.", e);
+        }
+        return false;
+    }
+
+    @Override
+    public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists)
+            throws TableAlreadyExistException, DatabaseNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists)
+            throws TableNotExistException, CatalogException {
+        throw new UnsupportedOperationException();
+    }
+
+    // ------------------------------------------------------------------------
+    // Unsupported catalog operations for RocketMQ

Review Comment:
   Why not move interfaces like `createDatabase` under this comment?



-- 
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: dev-unsubscribe@rocketmq.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org