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

This is a follow-up of #1428.

Author: Takuya UESHIN <ueshin@happy-camper.st>

Closes #1432 from ueshin/issues/SPARK-2518 and squashes the following commits:

37d1ace [Takuya UESHIN] Fix foldability of Substring expression.

(cherry picked from commit cc965eea510397642830acb21f61127b68c098d6)
Signed-off-by: Reynold Xin <rxin@apache.org>