DRILL29 Flatten reference implementation

See https://issues.apache.org/jira/browse/DRILL-29