RegionsHierarchy: fix for negative type [#METR-20000].

This commit is contained in:
Alexey Milovidov 2016-11-01 17:55:58 +03:00
parent bdde1b05cc
commit 48f14be32b

View File

@ -102,20 +102,23 @@ public:
RegionID max_region_id = 0; RegionID max_region_id = 0;
while (!in.eof()) while (!in.eof())
{ {
/** Our internal geobase has negative numbers,
* that means "this is garbage, ignore this row".
*/
Int32 read_region_id = 0; Int32 read_region_id = 0;
Int32 read_parent_id = 0; Int32 read_parent_id = 0;
RegionType type = 0; Int8 read_type = 0;
RegionPopulation population = 0;
DB::readIntText(read_region_id, in); DB::readIntText(read_region_id, in);
DB::assertChar('\t', in); DB::assertChar('\t', in);
DB::readIntText(read_parent_id, in); DB::readIntText(read_parent_id, in);
DB::assertChar('\t', in); DB::assertChar('\t', in);
DB::readIntText(type, in); DB::readIntText(read_type, in);
/** Далее может быть перевод строки (старый вариант) /** Далее может быть перевод строки (старый вариант)
* или таб, население региона, перевод строки (новый вариант). * или таб, население региона, перевод строки (новый вариант).
*/ */
RegionPopulation population = 0;
if (!in.eof() && *in.position() == '\t') if (!in.eof() && *in.position() == '\t')
{ {
++in.position(); ++in.position();
@ -127,7 +130,7 @@ public:
} }
DB::assertChar('\n', in); DB::assertChar('\n', in);
if (read_region_id <= 0) if (read_region_id <= 0 || read_type < 0)
continue; continue;
RegionID region_id = read_region_id; RegionID region_id = read_region_id;
@ -136,6 +139,8 @@ public:
if (read_parent_id >= 0) if (read_parent_id >= 0)
parent_id = read_parent_id; parent_id = read_parent_id;
RegionType type = read_type;
if (region_id > max_region_id) if (region_id > max_region_id)
{ {
if (region_id > max_size) if (region_id > max_size)