Andrey Rublev edged Roberto Bautista Agut in two hard-fought sets to win through to the semi-finals of the Hamburg European Open.