您的位置:首页 > 娱乐 > 八卦 > 如何在 Doris 中通过外表访问 OceanBase 表

如何在 Doris 中通过外表访问 OceanBase 表

2025/2/25 22:18:28 来源:https://blog.csdn.net/maray/article/details/139691959  浏览:    关键词:如何在 Doris 中通过外表访问 OceanBase 表

在OceanBase 中建立了一张表 test.t1:

CREATE TABLE `t1` (`apply_id` varchar(500) DEFAULT NULL,`apply_dt` date DEFAULT NULL,`mobile_prov_nm` varchar(500) DEFAULT NULL,`mobile_city_nm` varchar(500) DEFAULT NULL
);-- 插入 10000 行数据到 t1 表insert /*+parallel(48) enable_parallel_dml append */ into t1select abs(random()),case abs(random()%3)when 0 then '2022-10-10'when 1 then '2021-10-10' when 2 then '2023-10-10'end,abs(random()%10000),10000000 * abs(random()%25)
from table(generator(10000));

我的 OceanBase 的账号信息如下:

host: 127.0.0.1
port: 44035
database: test
user: root@mysql_tenant
pass: 空

然后在 Doris 中通过外表 et1 可以访问 OceanBase 中的 t1 表。Doris 中建外表的流程如下:

drop resource jdbc_resource;
drop table et1;CREATE EXTERNAL RESOURCE jdbc_resource
properties ("type"="jdbc","user"="root@mysql_tenant","password"="","jdbc_url"="jdbc:oceanbase://127.0.0.1:44035/test","driver_url"="file:///home/admin/ob.z1.obs0/oceanbase-client-2.4.1.jar","driver_class"="com.oceanbase.jdbc.Driver"
);CREATE TABLE `et1` (`apply_id` varchar(500) DEFAULT NULL,`apply_dt` date DEFAULT NULL,`mobile_prov_nm` varchar(500) DEFAULT NULL,`mobile_city_nm` varchar(500) DEFAULT NULL
)ENGINE=JDBC
PROPERTIES (
"resource" = "jdbc_resource",   -- 在Doris中建立外表时依赖的资源名
"table" = "t1",   -- 在Doris中建立外表时,与外部数据库相映射的表名。
"table_type"="oceanbase"   -- 外表对应的数据库 mysql,postgresql,sqlserver,oracle, 和 jdbc_url 中的数据库名保持一致
);-- 测试访问外表
select * from et1;

其中,

  • driver_url 中的 jar 文件oceanbase-client-2.4.1.jar 文件来自 OceanBase 官网:资源与服务-》软件下载-》企业版-》[驱动和中间件](https://www.oceanbase.com/softwarecenter-enterprise)
  • jdbc_url 中 的 url 前缀是 jdbc:oceanbase ,不是 jdbc:mysql
  • driver_classcom.oceanbase.jdbc.Driver,而不是 com.mysql.jdbc.Driver
  • 创建外表的属性中,"table_type"="oceanbase" 不要写成 "table_type"="mysql"

总之,所有 mysql 的痕迹,都变成 oceanbase,就对了。其余和 MySQL jdbc 一模一样。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com