private static function validate($awqlString, $startIndex, $pageSize)
    {
        $validationResult = QueryValidator::validateServiceQuery(
            $awqlString,
            false
        );
        if ($validationResult->isFailed()) {
            throw new InvalidArgumentException(
                'The service query string is invalid. Validation fail reason: '.
                $validationResult->getFailReason()
            );
        }

        // The `startIndex` and `pageSize` arguments are optional for
        // constructing a `ServiceQuery` object. They must either be both null,
        // or both not null.

        if (is_null($startIndex) !== is_null($pageSize)) {
            throw new InvalidArgumentException('Start index and page size' .
                ' must be both null, or both not null.');
        }

        if (!is_null($startIndex)) {
            if (!is_int($startIndex)) {
                throw new InvalidArgumentException('The start index must be' .
                    ' an integer.');
            }

            if ($startIndex < 0) {
                throw new OutOfBoundsException('The start index must be 0 or' .
                    ' a positive number.');
            }
        }

        if (!is_null($pageSize)) {
            if (!is_int($pageSize)) {
                throw new InvalidArgumentException('The page size must be' .
                    ' an integer.');
            }

            if ($pageSize < 1) {
                throw new OutOfBoundsException('The page size must be a' .
                    ' positive number.');
            }
        }
    }