Cherry pick from 4ee63c1a84859e39326a61600431a7082395d75f (opts for schema flattening)