Patch to address SPARK-4459

Please see https://issues.apache.org/jira/browse/SPARK-4459