$query = $this->createQuery();// TYPO3\CMS\Extbase\Persistence\QueryInterface
$queryParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
    \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser::class
);
debug($queryParser->convertQueryToDoctrineQueryBuilder($query)->getSQL());