aaron-y-chen commented on code in PR #74290:
URL: https://github.com/apache/airflow/pull/74290#discussion_r4224273568


##########
providers/microsoft/azure/tests/system/microsoft/azure/example_azure_ai_search.py:
##########
@@ -0,0 +1,175 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+System test for AzureAISearchHook.
+
+Requires a real Azure AI Search service, reachable through the 
``azure_ai_search_default``
+connection (``AIRFLOW_CONN_AZURE_AI_SEARCH_DEFAULT``) with an admin API key as 
password: the
+test creates its own index, writes and reads documents through the hook and 
deletes the index.
+"""
+
+from __future__ import annotations
+
+import os
+from datetime import datetime
+
+from airflow.providers.common.compat.sdk import DAG, TriggerRule, task
+from airflow.providers.microsoft.azure.hooks.ai_search import AzureAISearchHook
+
+DAG_ID = "example_azure_ai_search"
+ENV_ID = os.environ.get("SYSTEM_TESTS_ENV_ID") or "default"
+INDEX = f"airflow-system-test-{ENV_ID}"
+DOCUMENTS = [
+    {"id": "1", "title": "Annual report 2025", "category": "report"},
+    {"id": "2", "title": "Quarterly report Q1", "category": "report"},
+    {"id": "3", "title": "Meeting notes", "category": "memo"},
+]
+
+
+@task
+def create_index():
+    """Create the index of this test; the hook works on documents, not on 
indexes."""
+    from azure.core.credentials import AzureKeyCredential
+    from azure.search.documents.indexes import SearchIndexClient
+    from azure.search.documents.indexes.models import (
+        SearchableField,
+        SearchFieldDataType,
+        SearchIndex,
+        SimpleField,
+    )
+
+    conn = 
AzureAISearchHook.get_connection(AzureAISearchHook.default_conn_name)
+    client = SearchIndexClient(
+        f"https://{conn.host.removeprefix('https://')}", 
AzureKeyCredential(conn.password)
+    )
+    client.create_or_update_index(
+        SearchIndex(
+            name=INDEX,
+            fields=[
+                SimpleField(name="id", type=SearchFieldDataType.String, 
key=True),

Review Comment:
   `create_index` declares the key as `SimpleField(name="id", 
type=SearchFieldDataType.String, key=True)`. `SimpleField` defaults to 
`sortable=False`: in both 11.6.0 and 12.0.0 the SDK writes `"sortable": false` 
into the index definition. `find_reports` then sorts on that field with 
`order_by=["id"]` (line 90).
   
   The [OData `$orderby` 
reference](https://learn.microsoft.com/en-us/azure/search/search-query-odata-orderby)
 says "The sort criteria can either be the path of a `sortable` field or a call 
to either the `geo.distance` or the `search.score` functions", so I'd expect 
the service to reject this query. The `retries=3` on `find_reports` would then 
only repeat the same error until the test fails.
   
   ```suggestion
                   SimpleField(name="id", type=SearchFieldDataType.String, 
key=True, sortable=True),
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to