Repository navigation
generate phone numbers using Google library "libphonenumber" - #1249
Conversation
This library already contains phone number patterns for all countries. It's reasonable to reuse them instead of re-inventing the wheel. Now PhoneNumberTest is stable, and doesn't need all these "max allowed errors count" hacks. P.S. Also, I had to add few Canada area codes that has appeared meanwhile (742 for Toronto, 450, 579, 354 for Quebec etc.)
kingthorin
left a comment
There was a problem hiding this comment.
Overall looks good to me. Nothing seems breaking to me either so I don't see why we'd wait.
| for (int i = 0; i < 10_000_000; i++) { | ||
| for (int i = 0; i < 10_000; i++) { | ||
| Faker f = new Faker(); | ||
| String s = f.ancient().god(); | ||
| if (i % 1_000_000 == 0) { | ||
| if (i % 1_000 == 0) { |
There was a problem hiding this comment.
This was purposefully huge to ensure a timing/performance issue isn't re-introduced.
There was a problem hiding this comment.
If it's really going to be dropped by a factor of 10 then the timeout should as well I guess.
There was a problem hiding this comment.
We can restore 10_000_000, of course. It just seemed to much for me. Was a bit slow on my machine.
There was a problem hiding this comment.
I believe that's the right move.
There was a problem hiding this comment.
Before changing number here we need to have a good replacement for that
Just changing 10_000_000 to 1_000 makes test useless since with so small number it is unable to reproduce the original problem #883 for the code before it was fixed
|
Sorry, I'd like to veto this PR. I'm against bringing in new production libraries into Datafaker. It took me a lot of time to get most of them out, and only the Regex one is a special case for this. If you really want this, we could discuss making an SPI for this or so, that when you add a dependency to datafaker-phone-numbers it would use this library instead? |
| private static Stream<Arguments> dataParameters() { | ||
| List<Arguments> arguments = new ArrayList<>(); | ||
| arguments.add(Arguments.of(Locale.ENGLISH, new Random())); | ||
| arguments.add(Arguments.of(new Locale("en-US"), new Random())); |
There was a problem hiding this comment.
we really should stop using this - or _ approach, it's not something we support officially, and it's removed from all documentation AFAIK.
There was a problem hiding this comment.
Do you mean replacing new Locale("en-US") by new Locale("en", "US")?
Yes, why not.
P.S. Starting from Java 19, this constructor is also deprecated. Should be replaced by Locale.of("en", "US").
There was a problem hiding this comment.
Yes, the new Locale("en-US") is not an officially supported Locale, that's something Javafaker introduced, and ideally, it should be removed from the code, not added.
Interesting take. :) NB! Look at PhoneNumberTest: @erikpragt-connectid |
…("lang_COUNTRY")`
There are many useful libraries, but that's not a reason to include them. Maybe we should have used Jackson to generate JSON and XML, and Apache CSV for the CSV files, and Hibernate for the SQL generation? The Datafaker should be minimal library, small and non-invasive, and no dependencies. No dependencies is hard since the regex library and snakeyml are libraries which are hard to avoid since a large part of the codebase is built around it, and probably too complex to embed in the code itself. It's also never the goal of Datafaker to provide 100% real data (Most likely the credit cards generated won't work either) |
No, "libphonenumber" cannot generate random phone number. It can only validate phone numbers.
I agree that adding Jackson or Hibernate would be a bad idea I believe this is a reasonable general rule: it's reasonable to add a dependency if:
I think "libphinenumber" exactly matches both criterias (and Jackson/Hibernate do not match). |
|
Despite the fact I understand the rationale of usage From the side as it was mentioned such lib could improve quality of generated data. Thus I would suggest to think towards kind of plugin api (SPI or whatever). We already have custom provider support we allows to create a provider with better quality. May be we need to think about more fine-grained api allowing to use more accurate custom code for some providers (currently just brainstorming) P.S.: I would even remove |
|
@snuyanzin @erikpragt-connectid Ok, would you mind creating a new repository like https://github.com/datafaker-net/datafaker-phones? Who will be responsible for releasing new versions then? Someone will need to always remember to release P.S. I sincerely don't understand why you want to avoid dependencies. |
should we have a new repo? I guess having another module depending on a library would be ok. |
|
Ok, you suggest to make a multi-module project from datafaker? Yes, sure, why not. I can modify the PR accordingly. |
|
Well, do you really need the library at runtime if all you need is the formats? As in, if we would use the lib phone number at build time to extract the formats, would that be an option? |
|
libohonenumber's metadata is available as an xml file. I guess we could create a GitHub workflow to pull it and update our yaml(s) from time to time. Though that seems like a lot of extra work to for some reason avoid including a 350k dependency. (I know you're worried about bloat but I suspect we could come up with some reasonable criteria/rationale to be applied in this and future cases.) |
|
Javafaker had a ton of dependencies. Most of the dependencies had bugs or CVEs, which caused Javafaker to have CVEs too. Besides that, dependencies can have dependencies, and those dependencies can conflict with other dependencies. Maybe "no extra dependencies" is too strict, but I wouldn't know where to draw the line. Just keep in mind we have around 500.000 downloads per month, so that's the impact we can have on people. |
Understood, I wouldn't want us to get into modern dependency hell like Node projects 😀
That's a good stat to know, and definitely helps contextualize things. As for criteria, based just on what's been mentioned so far.
Of course we can edit or add more 🤷♂️ |
|
Thanks for that writeup, appreciate it! Given that it doesn't introduce a whole tree of dependencies (see the merits of dependency free libraries? 😉) and the size is small, and all of the above, plus that we live in a democracy, and "code wins", I'm happy to change my mind on this. Maybe I'll maakt a small note in the contributing section (be mindful when introducing new libraries, or something like that). What do you think @snuyanzin ? |
|
Small question though : is the result still repeatable? I think I saw something in the PR about having to generate a phone number a couple of times to create a valid one? |
Good question. But yes, inside we have a loop a'la "up to 100 retries". |
|
@bodiam @snuyanzin You decide. I can prepare another PR which adds "libphonenumber" generation as a separate module, no problems. It may be even good to show others how they could add other modules as well. The only drawback is that such PR would move all existing sources to a subfolder, something like "core" or "engine" or just "datafaker". It's because Maven multi-module architecture requires the root project have type "pom", and submodules can have type "jar". |
|
I think the current way of doing it is fine, no need to overcomplicate things. I'm happy if you want to merge it. |
This library already contains phone number patterns for all countries. It's reasonable to reuse them instead of re-inventing the wheel.
Now PhoneNumberTest is stable, and doesn't need all these "max allowed errors count" hacks.
P.S. Maybe it's a good idea not to include this PR into the nearest release.
It's quite a big change, maybe postpone it to a next major release?