[SPARK-2518][SQL] Fix foldability of Substring expression.

This is a follow-up of #1428.