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"
Exemplo n.º 2
0
 def test_custom_request_id(self, mock_post, method):
     """Test query V2."""
     client = KustoClient(self.HOST)
     properties = ClientRequestProperties()
     request_id = "test_request_id"
     properties.client_request_id = request_id
     response = method.__call__(client,
                                "PythonTest",
                                "Deft",
                                properties=properties)
     self._assert_sanity_query_response(response)
     self._assert_client_request_id(mock_post.call_args.kwargs,
                                    value=request_id)
Exemplo n.º 3
0
    def _ingest_from_stream_with_client_request_id(
        self, stream_descriptor: Union[StreamDescriptor, IO[AnyStr]], ingestion_properties: IngestionProperties, client_request_id: Optional[str]
    ) -> IngestionResult:
        stream_descriptor = BaseIngestClient._prepare_stream(stream_descriptor, ingestion_properties)
        additional_properties = None
        if client_request_id:
            additional_properties = ClientRequestProperties()
            additional_properties.client_request_id = client_request_id

        self._kusto_client.execute_streaming_ingest(
            ingestion_properties.database,
            ingestion_properties.table,
            stream_descriptor.stream,
            ingestion_properties.format.name,
            additional_properties,
            mapping_name=ingestion_properties.ingestion_mapping_reference,
        )

        return IngestionResult(IngestionStatus.SUCCESS, ingestion_properties.database, ingestion_properties.table, stream_descriptor.source_id)
Exemplo n.º 4
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 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
Exemplo n.º 6
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)
Exemplo n.º 8
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
Exemplo n.º 9
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())
Exemplo n.º 10
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)