The reason why we need to do the judgement in the outer function and pass over a flag is that we need to if the "retainPKColumns" is true.
Only the PK columns of the last table to be scanned will be projected as rowkey and used as PK columns in the final joined table schema, and the order-by compilation can take advantage of that construct. The PK columns of all other hashed tables will not be projected as PK columns in the their intermediate schemas. The rowkeys of such tables are simply copied but are never used in later stages, for the mere purpose of constructing a meaningful HBase Result. These PK columns, if used in the query, will instead be projected as non-PK columns so that the runtime merge of these KeyValueSchema-formatted values between two table results can be easier and more efficient.