Dynamically generate the queries to load a partitioned store_sales table...

....

Also, I think "ss_sold_date_sk between A and B" should make things easier. You can get rid of the "if" branch in line 39.

If we don't want to assert that, we can simply use "ss_sold_date_sk in (...)". This will be a longer IN list, but Impala can handle it.