maxmind / MaxMind-DB-Writer-perl

Create MaxMind DB database files
https://metacpan.org/release/MaxMind-DB-Writer/
Other
77 stars 27 forks source link

Merge of array values on ip collision #100

Closed blaazetech closed 4 years ago

blaazetech commented 6 years ago

Am trying to merge array values when there is an ip collision, am trying something like this,

my %types = (
    ids => [ 'array', 'utf8_string' ],
);

while( my $line = <$info>) {
    #my $mk = 'merge_strategy';
    $tree->insert_network(
                trim($line).'/32' => {
                        ids => [ '5854' ],
                },
    );
        $tree->insert_network(
                trim($line).'/32' => {
                        ids => [ '5994' ],
                },
        );
}

but everytime am getting only 5994 in ids, the output is something like this

123.123.123.100/30
\ {
    ids   [
        [0] 5994
    ]
}

how can i achieve this to write something like below

123.123.123.100/30
\ {
    ids   [
        [0] 5854,
        [1] 5994
    ]
}
oschwald commented 6 years ago

I don't think any of the merge strategies support this. For array records, they merge or overwrite the record at the position. It wouldn't be that hard to add a new merge strategy based off of recurse that supported this. PRs are welcomed.

oschwald commented 4 years ago

This is possible in the Go mmdbwriter by writing your own inserter function for InsertFunc. I am going to close this issue as it is unlikely we will update the Perl writer with this functionality.