jeff3071 commented on code in PR #72246:
URL: https://github.com/apache/airflow/pull/72246#discussion_r3888325100
##########
providers/common/ai/tests/unit/common/ai/operators/test_document_loader.py:
##########
@@ -192,6 +192,42 @@ def test_json_from_bytes(self):
assert len(result) == 2
+class TestJsonLinesParser:
+ def test_one_document_per_non_empty_line(self, tmp_path):
+ f = tmp_path / "items.jsonl"
+ f.write_text('{"title": "First"}\n\n[1, 2]\n', encoding="utf-8")
+
+ op = DocumentLoaderOperator(task_id="test", source_path=str(f))
+ result = op.execute(context=MagicMock())
+
+ assert len(result) == 2
+ assert result[0]["text"] == "title: First"
+ assert result[1]["text"] == "[1, 2]"
+ assert [doc["metadata"]["item_index"] for doc in result] == [0, 1]
+
+ def test_source_bytes_uses_json_text_field(self):
+ raw = b'{"body": "First", "source": "a"}\n{"body": "Second", "source":
"b"}\n'
+ op = DocumentLoaderOperator(
+ task_id="test",
+ source_bytes=raw,
+ file_type=".jsonl",
+ json_text_field="body",
+ )
+ result = op.execute(context=MagicMock())
+
+ assert [doc["text"] for doc in result] == ["First", "Second"]
+ assert [doc["metadata"]["source"] for doc in result] == ["a", "b"]
+
+ def test_directory_recognizes_jsonl_extension(self, tmp_path):
+ (tmp_path / "items.jsonl").write_text('{"name": "kept"}\n',
encoding="utf-8")
+
+ op = DocumentLoaderOperator(task_id="test", source_path=str(tmp_path))
+ result = op.execute(context=MagicMock())
+
+ assert len(result) == 1
+ assert result[0]["text"] == "name: kept"
Review Comment:
Great catch! Fixed in b6033b0. `JSONDecodeError` now reports the correct
line number.
--
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]