Skip to content

feat: router的tb_map增加通配符匹配功能 #368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

PDMoFan
Copy link

@PDMoFan PDMoFan commented Apr 27, 2025

router的tb_map增加通配符匹配功能

@PDMoFan
Copy link
Author

PDMoFan commented Apr 28, 2025

我已经完成了以下修改:

  1. 添加了match_token函数,用于支持通配符匹配,支持*和?通配符。
  2. 修改了get_tb_map方法,使其支持通配符匹配:
  • 首先尝试精确匹配
  • 然后尝试通配符匹配
  • 最后回退到schema map匹配
  1. 添加了测试用例来验证通配符功能:
  • test_tb_map_wildcard_matching: 测试基本的通配符匹配

  • test_tb_map_wildcard_matching_with_escapes: 测试带转义字符的通配符匹配

现在router的tb_map支持以下通配符功能:

    • 匹配任意多个字符
  1. ? 匹配0-1个字符
  2. 支持转义字符(如MySQL的`` 和PostgreSQL的")
  3. 支持schema和table级别的通配符例如:- test_db.:dst_db. - 将test_db下的所有表映射到dst_db下,保持表名不变- test_db.tb_:dst_db.dst_tb - 将test_db下所有以tb_开头的表映射到dst_db下,表名前加dst_前缀- test_db.:dst_db. - 带转义字符的通配符匹配这样的修改使得router的tb_map功能与filter的do_tbs保持一致,都支持通配符匹配。

1 similar comment
@PDMoFan
Copy link
Author

PDMoFan commented Apr 28, 2025

我已经完成了以下修改:

  1. 添加了match_token函数,用于支持通配符匹配,支持*和?通配符。
  2. 修改了get_tb_map方法,使其支持通配符匹配:
  • 首先尝试精确匹配
  • 然后尝试通配符匹配
  • 最后回退到schema map匹配
  1. 添加了测试用例来验证通配符功能:
  • test_tb_map_wildcard_matching: 测试基本的通配符匹配

  • test_tb_map_wildcard_matching_with_escapes: 测试带转义字符的通配符匹配

现在router的tb_map支持以下通配符功能:

    • 匹配任意多个字符
  1. ? 匹配0-1个字符
  2. 支持转义字符(如MySQL的`` 和PostgreSQL的")
  3. 支持schema和table级别的通配符例如:- test_db.:dst_db. - 将test_db下的所有表映射到dst_db下,保持表名不变- test_db.tb_:dst_db.dst_tb - 将test_db下所有以tb_开头的表映射到dst_db下,表名前加dst_前缀- test_db.:dst_db. - 带转义字符的通配符匹配这样的修改使得router的tb_map功能与filter的do_tbs保持一致,都支持通配符匹配。

if let Some((dst_schema, dst_tb)) = self.tb_map.get(&(schema.into(), tb.into())) {
return (dst_schema, dst_tb);
}

// Then try wildcard match
let escape_pairs = SqlUtil::get_escape_pairs(&self.db_type);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you forgot to add db_type field in RdbRouter, the project can't build successfully

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants