@@ -79,14 +79,15 @@ async def test_write_documents_async(self, document_store):
7979 @pytest .mark .asyncio
8080 async def test_write_documents_async_invalid_document_type (self , document_store ):
8181 """Test write_documents with invalid document type"""
82- invalid_docs = [{"id" : "1" , "content" : "test" }]
82+ invalid_docs = [{"id" : "1" , "content" : "test" }] # Dictionary instead of Document object
8383 with pytest .raises (ValueError , match = "param 'documents' must contain a list of objects of type Document" ):
8484 await document_store .write_documents_async (invalid_docs )
8585
8686 @pytest .mark .asyncio
8787 async def test_write_documents_async_with_sparse_embedding_warning (self , document_store , caplog ):
8888 """Test write_documents with document containing sparse_embedding field"""
8989 doc = Document (id = "1" , content = "test" , sparse_embedding = SparseEmbedding (indices = [0 , 1 ], values = [0.5 , 0.5 ]))
90+
9091 await document_store .write_documents_async ([doc ])
9192 assert "but `sparse_vector_field` is not configured" in caplog .text
9293
@@ -298,37 +299,48 @@ async def test_query_sql_async(self, document_store: ElasticsearchDocumentStore)
298299 ]
299300 await document_store .write_documents_async (docs )
300301
302+ # SQL query returns raw JSON response from Elasticsearch SQL API
301303 sql_query = (
302304 f'SELECT content, category, status, priority FROM "{ document_store ._index } " ' # noqa: S608
303305 f"WHERE category = 'A' ORDER BY priority"
304306 )
305307 result = await document_store ._query_sql_async (sql_query )
306308
309+ # Verify raw JSON response structure
307310 assert isinstance (result , dict )
308311 assert "columns" in result
309312 assert "rows" in result
313+
314+ # Verify we got 2 rows (documents with category A)
310315 assert len (result ["rows" ]) == 2
316+
317+ # Verify column structure
311318 column_names = [col ["name" ] for col in result ["columns" ]]
312319 assert "content" in column_names
313320 assert "category" in column_names
314321
315322 @pytest .mark .asyncio
316323 async def test_query_sql_async_with_fetch_size (self , document_store : ElasticsearchDocumentStore ):
324+ """Test async SQL query with fetch_size parameter"""
317325 docs = [Document (content = f"Document { i } " , meta = {"category" : "A" , "index" : i }) for i in range (15 )]
318326 await document_store .write_documents_async (docs )
319327
320328 sql_query = (
321329 f'SELECT content, category FROM "{ document_store ._index } " ' # noqa: S608
322330 f"WHERE category = 'A'"
323331 )
332+
333+ # Test with fetch_size
324334 result = await document_store ._query_sql_async (sql_query , fetch_size = 5 )
325335
336+ # Should return raw JSON response
326337 assert isinstance (result , dict )
327338 assert "columns" in result
328339 assert "rows" in result
329340
330341 @pytest .mark .asyncio
331342 async def test_query_sql_async_error_handling (self , document_store : ElasticsearchDocumentStore ):
343+ """Test error handling for invalid SQL queries"""
332344 invalid_query = "SELECT * FROM non_existent_index"
333345 with pytest .raises (DocumentStoreError , match = "Failed to execute SQL query" ):
334346 await document_store ._query_sql_async (invalid_query )
0 commit comments