Example #1
0
    def test_partial_results(self, mock_post, method):
        """Tests partial results."""
        client = KustoClient(self.HOST)
        query = """set truncationmaxrecords = 5;
range x from 1 to 10 step 1"""
        properties = ClientRequestProperties()
        properties.set_option(
            ClientRequestProperties.
            results_defer_partial_query_failures_option_name, False)
        with pytest.raises(KustoMultiApiError) as e:
            response = method.__call__(client,
                                       "PythonTest",
                                       query,
                                       properties=properties)
            if type(response) == KustoStreamingResponseDataSet:
                results = list(get_response_first_primary_result(response))
        errors = e.value.get_api_errors()
        assert len(errors) == 1
        assert errors[0].code == "LimitsExceeded"

        properties.set_option(
            ClientRequestProperties.
            results_defer_partial_query_failures_option_name, True)
        response = method.__call__(client,
                                   "PythonTest",
                                   query,
                                   properties=properties)
        self._assert_partial_results_response(response)
    def test_properties(self):
        """positive tests"""
        defer = False
        timeout = timedelta(seconds=10)

        crp = ClientRequestProperties()
        crp.set_option(
            ClientRequestProperties.
            results_defer_partial_query_failures_option_name, defer)
        crp.set_option(ClientRequestProperties.request_timeout_option_name,
                       timeout)

        result = crp.to_json()

        assert '"{0}": false'.format(
            crp.results_defer_partial_query_failures_option_name) in result
        assert '"{0}": "0:00:10"'.format(
            ClientRequestProperties.request_timeout_option_name) in result

        assert crp.client_request_id is None
        assert crp.application is None
        assert crp.user is None

        crp.client_request_id = "CRID"
        assert crp.client_request_id == "CRID"

        crp.application = "myApp"
        assert crp.application == "myApp"

        crp.user = "******"
        assert crp.user == "myUser"
Example #3
0
    def test_partial_results(self, mock_post):
        """Tests partial results."""
        client = KustoClient("https://somecluster.kusto.windows.net")
        query = """set truncationmaxrecords = 5;
range x from 1 to 10 step 1"""
        properties = ClientRequestProperties()
        properties.set_option(ClientRequestProperties.results_defer_partial_query_failures_option_name, False)
        self.assertRaises(KustoServiceError, client.execute_query, "PythonTest", query, properties)
        properties.set_option(ClientRequestProperties.results_defer_partial_query_failures_option_name, True)
        response = client.execute_query("PythonTest", query, properties)
        assert response.errors_count == 1
        assert "E_QUERY_RESULT_SET_TOO_LARGE" in response.get_exceptions()[0]
        assert len(response) == 3
        results = list(response.primary_results[0])
        assert len(results) == 5
        assert results[0]["x"] == 1
    def test_partial_results(self, mock_post):
        """Tests partial results."""
        client = KustoClient(self.HOST)
        query = """set truncationmaxrecords = 5;
range x from 1 to 10 step 1"""
        properties = ClientRequestProperties()
        properties.set_option(
            ClientRequestProperties.
            results_defer_partial_query_failures_option_name, False)
        self.assertRaises(KustoServiceError, client.execute_query,
                          "PythonTest", query, properties)
        properties.set_option(
            ClientRequestProperties.
            results_defer_partial_query_failures_option_name, True)
        response = client.execute_query("PythonTest", query, properties)
        self._assert_partial_results_response(response)
Example #5
0
        def create_client_request_properties(
                cls,
                scope: str,
                timeout: str = None) -> ClientRequestProperties:
            """
            Creates a fitting ClientRequestProperties object, to be used when executing control commands or queries.
            :param scope: Working scope
            :param timeout: Requests default timeout
            :return: ClientRequestProperties object
            """
            client_request_properties = ClientRequestProperties()
            client_request_properties.client_request_id = f"{scope};{str(uuid.uuid4())}"
            client_request_properties.application = "sample_app.py"

            # Tip: Though uncommon, you can alter the request default command timeout using the below command, e.g. to set the timeout to 10 minutes, use "10m"
            if timeout:
                client_request_properties.set_option(
                    ClientRequestProperties.request_timeout_option_name,
                    timeout)

            return client_request_properties
def execute_query(client, db_name, query):
    query_result_df = None
    try:
        properties = ClientRequestProperties()
        properties.set_option(properties.results_defer_partial_query_failures_option_name, True)
        properties.set_option(properties.request_timeout_option_name, timedelta(seconds=1 * 30))
        response = client.execute(db_name, query, properties=properties)
        query_result_df = dataframe_from_result_table(response.primary_results[0])
    except KustoServiceError as error:
        print("2. Error:", error)
        print("2. Is semantic error:", error.is_semantic_error())
        print("2. Has partial results:", error.has_partial_results())
        print("2. Result size:", len(error.get_partial_results()))
        
        print("3. Response error count: ", response.errors_count)
        print("3. Exceptions:", response.get_exceptions())
        print("3. Result size:", len(response.primary_results))

        print("4. Error:", error)
        print("4. Is semantic error:", error.is_semantic_error())
        print("4. Has partial results:", error.has_partial_results())
    finally:
        return query_result_df
Example #7
0
### EXCEPTIONS ###
##################


# Query is too big to be executed
query = "StormEvents"
try:
    response = client.execute(db, query)
except KustoServiceError as error:
    print("2. Error:", error)
    print("2. Is semantic error:", error.is_semantic_error())
    print("2. Has partial results:", error.has_partial_results())
    print("2. Result size:", len(error.get_partial_results()))

properties = ClientRequestProperties()
properties.set_option(properties.results_defer_partial_query_failures_option_name, True)
properties.set_option(properties.request_timeout_option_name, timedelta(seconds=8 * 60))
response = client.execute(db, query, properties=properties)
print("3. Response error count: ", response.errors_count)
print("3. Exceptions:", response.get_exceptions())
print("3. Result size:", len(response.primary_results))

# Query has semantic error
query = "StormEvents | where foo = bar"
try:
    response = client.execute(db, query)
except KustoServiceError as error:
    print("4. Error:", error)
    print("4. Is semantic error:", error.is_semantic_error())
    print("4. Has partial results:", error.has_partial_results())
Example #8
0
##################
### EXCEPTIONS ###
##################

# Query is too big to be executed
query = "StormEvents"
try:
    response = client.execute(db, query)
except KustoServiceError as error:
    print("2. Error:", error)
    print("2. Is semantic error:", error.is_semantic_error())
    print("2. Has partial results:", error.has_partial_results())
    print("2. Result size:", len(error.get_partial_results()))

properties = ClientRequestProperties()
properties.set_option(
    properties.results_defer_partial_query_failures_option_name, True)
properties.set_option(properties.request_timeout_option_name,
                      timedelta(seconds=8 * 60))
response = client.execute(db, query, properties=properties)
print("3. Response error count: ", response.errors_count)
print("3. Exceptions:", response.get_exceptions())
print("3. Result size:", len(response.primary_results))

# Query has semantic error
query = "StormEvents | where foo = bar"
try:
    response = client.execute(db, query)
except KustoServiceError as error:
    print("4. Error:", error)
    print("4. Is semantic error:", error.is_semantic_error())
    print("4. Has partial results:", error.has_partial_results())