Minor comment: more documentation on this method would be nice. I take it from reading the rest of the code, if this has a set, then the categories are written to both the first class column and the categories array column. 

But did I understand the code correctly, if a category is not in this set, then it will only be written to its first class column (if such mapping exists) or if the mapping doesn't exist, then it will be written to categories array column?

In other words, it would be nice if we describe what is the behavior if a category is not in this set and does not have mapping.