sql: relabel by.apply to match schema

WIP: causes failing tests