Skip to content
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

DM: support PCRE regexp syntax for routing #11635

Open
takaidohigasi opened this issue Oct 3, 2024 · 7 comments
Open

DM: support PCRE regexp syntax for routing #11635

takaidohigasi opened this issue Oct 3, 2024 · 7 comments
Labels
type/feature Issues about a new feature

Comments

@takaidohigasi
Copy link

Is your feature request related to a problem?

I'd like to consolidate many schema by a simple route config.

Describe the feature you'd like

if there are databases for source like

  • mercari_a
  • mercari_b
  • mercari_c
  • mercari_d
  • mercari_e

following config do not work

  route-a:
    schema-pattern: "mercari_a"
    target-schema: "mercari"
  route-others:
    schema-pattern: "mercari_(?!a).*"
    target-schema: "mercari-other"

Describe alternatives you've considered

No response

Teachability, Documentation, Adoption, Migration Strategy

No response

@takaidohigasi takaidohigasi added the type/feature Issues about a new feature label Oct 3, 2024
@takaidohigasi
Copy link
Author

I might mistake the repository to create issue
https://github.com/pingcap/tidb/blob/master/pkg/util/table-router/router.go

@takaidohigasi takaidohigasi changed the title DM: support not operator for regexp for schema-pattern DM: support brace and not operator for regexp for schema-pattern Oct 3, 2024
@takaidohigasi
Copy link
Author

I understood Golang regxp support RE2 syntax, not PCRE

@takaidohigasi takaidohigasi reopened this Oct 3, 2024
@takaidohigasi takaidohigasi changed the title DM: support brace and not operator for regexp for schema-pattern DM: support PCRE regexp syntax for routing Oct 3, 2024
@takaidohigasi
Copy link
Author

I understand there isn't lightweight safe proper library for Golang...

@lance6716
Copy link
Contributor

lance6716 commented Oct 8, 2024

You can use mercari_[^a] in RE2 syntax. I think it's confusing to have two RE flavors and they can be converted to the other in most cases.

@kennytm
Copy link
Contributor

kennytm commented Oct 8, 2024

the actual wildcard syntax is mercari_[!a]. you need to prefix with ~ to use the regexp syntax. but the doc still seems to only recommend the wildcards * and ? at the end

schema-pattern: 'mercari_[!a]'
# or
schema-pattern: '~^mercari_[^a]'

@takaidohigasi
Copy link
Author

takaidohigasi commented Oct 22, 2024

sorry My example was a bit wrong and I think I can't cope with existing RE2 syntax

  • mercari_sample
  • mercari_sample2
  • mercari_sample_hoge
  • mercari_asample
  • mercari_bsample
  • ...

following config do not work

  route-a:
    schema-pattern: "mercari_sample"
    target-schema: "mercari"
  route-others:
    schema-pattern: "^mercari_(?!sample$).*$"

@kennytm
Copy link
Contributor

kennytm commented Oct 22, 2024

It won't work because assertions (?!x) is not "regular" and thus not part of RE2 syntax. There is no plan to support regex flavors other than Golang's built-in one.

Route-rules do not allow overlapping matches1, but if the "other" schemas are a finite set you could always do

routes:
  route_a:
    schema-pattern: mercari_sample
    target-schema: mercari
  route_others:
    schema-pattern: '~^mercari_(sample2|sample_hoge|asample|bsample|...etc...)$'
    target-schema: mercari_others

Footnotes

  1. I think this can be relaxed, given that route-rules being an array with order, we can easily break the tie by favor the first matching rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature Issues about a new feature
Projects
None yet
Development

No branches or pull requests

3 participants