clickhouse分布式表查询报错There is no table

clickhouse0-0.clickhouse0.clickhouse-new.svc.cluster.local. :) select * from log_gather_devops_4a_devops_4a_logs_all

SELECT *
FROM log_gather_devops_4a_devops_4a_logs_all

0 rows in set. Elapsed: 0.005 sec. 

Received exception from server (version 21.3.4):
Code: 279. DB::Exception: Received from localhost:9000. DB::Exception: All connection tries failed. Log: 

There is no table `devops_filelog_collection`.`devops_filelog_collection.log_gather_devops_4a_devops_4a_logs` on server: clickhouse0-0.clickhouse0:9000
There is no table `devops_filelog_collection`.`devops_filelog_collection.log_gather_devops_4a_devops_4a_logs` on server: clickhouse1-1.clickhouse1:9001

报错的情况如上,我在报错里的那个server里查到了对应的表,我的使用情况是自动创建表,我把代码粘到下面,求大佬帮忙看看

建表语句,用的mybatis :

    <update id="createPhysicalTables">
        CREATE TABLE IF NOT EXISTS ${physicalTableName} on cluster ${clusterName}
        (
            createDate     Date DEFAULT toDate(now()),
            logDateTime    DateTime,
            offset         UInt64,
            logLevel       String,
            path           String,
            note           Nullable(String)
        )
        ENGINE = MergeTree()
            PARTITION BY createDate
            ORDER BY(
            createDate,
            logDateTime,
            offset,
            logLevel)
            PRIMARY KEY(
            createDate)
            SETTINGS index_granularity=8192;
    </update>

    <update id="createLogicalTables">
        CREATE TABLE IF NOT EXISTS ${logicalTableName} on cluster ${clusterName} as ${physicalTableName}
            ENGINE = Distributed(
                                    ${clusterName},
                                    ${databaseName},
                                    ${physicalTableName},
                                    rand());
    </update>

Mapper:

    void createPhysicalTables(@Param("physicalTableName") String physicalTableName, @Param("clusterName") String clusterName) throws UncategorizedSQLException;

    void createLogicalTables(@Param("physicalTableName") String physicalTableName, @Param("logicalTableName") String logicalTableName, @Param("databaseName") String databaseName, @Param("clusterName") String clusterName) throws UncategorizedSQLException;

service调用的情况:其中fileLogDatabaseName是定义好的库名,clusterName是定义好的集群名

        String physicalTableName = fileLogDatabaseName + ".log_gather_" + recordEntity.getAppTableName() + "_logs";
        clickhouseMapper.createPhysicalTables(physicalTableName, clusterName);
        clickhouseMapper.createLogicalTables(physicalTableName, physicalTableName + "_all", fileLogDatabaseName, clusterName);

 

注意表名大小写,还有权限问题,如果没有同义词的话要加上用户前缀哦

补充一下,手动创建的表没问题

您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632