1919from google .cloud .spanner import Client , KeySet # type: ignore
2020from langchain_core .documents import Document
2121
22- from langchain_google_spanner .document_loader import SpannerDocumentSaver , SpannerLoader
22+ from langchain_google_spanner .document_loader import (
23+ Column ,
24+ SpannerDocumentSaver ,
25+ SpannerLoader ,
26+ )
2327
2428project_id = os .environ ["PROJECT_ID" ]
2529instance_id = os .environ ["INSTANCE_ID" ]
@@ -47,9 +51,9 @@ def setup_database(self, client):
4751 table_name ,
4852 content_column = "product_id" ,
4953 metadata_columns = [
50- ("product_name" , "STRING(1024)" , True ),
51- ("description" , "STRING(1024)" , False ),
52- ("price" , "INT64" , False ),
54+ Column ("product_name" , "STRING(1024)" , True ),
55+ Column ("description" , "STRING(1024)" , False ),
56+ Column ("price" , "INT64" , False ),
5357 ],
5458 )
5559
@@ -258,9 +262,9 @@ def test_loader_custom_json_metadata(self, client):
258262 table_name ,
259263 content_column = "product_id" ,
260264 metadata_columns = [
261- ("product_name" , "STRING(1024)" , True ),
262- ("description" , "STRING(1024)" , False ),
263- ("price" , "INT64" , False ),
265+ Column ("product_name" , "STRING(1024)" , True ),
266+ Column ("description" , "STRING(1024)" , False ),
267+ Column ("price" , "INT64" , False ),
264268 ],
265269 metadata_json_column = "my_metadata" ,
266270 )
@@ -324,9 +328,9 @@ def setup_database(self, client):
324328 table_name ,
325329 content_column = "product_id" ,
326330 metadata_columns = [
327- ("product_name" , "VARCHAR(1024)" , True ),
328- ("description" , "VARCHAR(1024)" , False ),
329- ("price" , "INT" , False ),
331+ Column ("product_name" , "VARCHAR(1024)" , True ),
332+ Column ("description" , "VARCHAR(1024)" , False ),
333+ Column ("price" , "INT" , False ),
330334 ],
331335 )
332336
@@ -535,9 +539,9 @@ def test_loader_custom_json_metadata(self, client):
535539 table_name ,
536540 content_column = "product_id" ,
537541 metadata_columns = [
538- ("product_name" , "VARCHAR(1024)" , True ),
539- ("description" , "VARCHAR(1024)" , False ),
540- ("price" , "INT" , False ),
542+ Column ("product_name" , "VARCHAR(1024)" , True ),
543+ Column ("description" , "VARCHAR(1024)" , False ),
544+ Column ("price" , "INT" , False ),
541545 ],
542546 metadata_json_column = "my_metadata" ,
543547 )
@@ -606,15 +610,17 @@ def setup_pg_client(self, client) -> Client:
606610 yield client
607611
608612 def test_saver_google_sql (self , google_client ):
609- SpannerDocumentSaver .init_document_table (instance_id , google_database , table_name )
613+ SpannerDocumentSaver .init_document_table (
614+ instance_id , google_database , table_name
615+ )
610616 saver = SpannerDocumentSaver (
611617 instance_id , google_database , table_name , google_client
612618 )
613619 query = f"SELECT * FROM { table_name } "
614620 loader = SpannerLoader (
615621 client = google_client ,
616- instance = instance_id ,
617- database = google_database ,
622+ instance_id = instance_id ,
623+ database_id = google_database ,
618624 query = query ,
619625 )
620626 expected_docs = [
@@ -631,7 +637,10 @@ def test_saver_pg(self, pg_client):
631637 saver = SpannerDocumentSaver (instance_id , pg_database , table_name , pg_client )
632638 query = f"SELECT * FROM { table_name } "
633639 loader = SpannerLoader (
634- client = pg_client , instance = instance_id , database = pg_database , query = query
640+ client = pg_client ,
641+ instance_id = instance_id ,
642+ database_id = pg_database ,
643+ query = query ,
635644 )
636645 expected_docs = [
637646 Document (page_content = "Hello, World!" , metadata = {"source" : "my-computer" }),
@@ -649,8 +658,8 @@ def test_saver_google_sql_with_custom_schema(self, google_client):
649658 table_name ,
650659 content_column = "my_page_content" ,
651660 metadata_columns = [
652- ("category" , "STRING(35)" , True ),
653- ("price" , "INT64" , False ),
661+ Column ("category" , "STRING(35)" , True ),
662+ Column ("price" , "INT64" , False ),
654663 ],
655664 primary_key = "my_page_content" ,
656665 store_metadata = True ,
@@ -661,8 +670,8 @@ def test_saver_google_sql_with_custom_schema(self, google_client):
661670 query = f"SELECT * FROM { table_name } "
662671 loader = SpannerLoader (
663672 client = google_client ,
664- instance = instance_id ,
665- database = google_database ,
673+ instance_id = instance_id ,
674+ database_id = google_database ,
666675 query = query ,
667676 )
668677 expected_docs = [
@@ -691,16 +700,19 @@ def test_saver_pg_with_custom_schema(self, pg_client):
691700 table_name ,
692701 content_column = "my_page_content" ,
693702 metadata_columns = [
694- ("category" , "VARCHAR(35)" , True ),
695- ("price" , "INT" , False ),
703+ Column ("category" , "VARCHAR(35)" , True ),
704+ Column ("price" , "INT" , False ),
696705 ],
697706 primary_key = "my_page_content" ,
698707 store_metadata = True ,
699708 )
700709 saver = SpannerDocumentSaver (instance_id , pg_database , table_name , pg_client )
701710 query = f"SELECT * FROM { table_name } "
702711 loader = SpannerLoader (
703- client = pg_client , instance = instance_id , database = pg_database , query = query
712+ client = pg_client ,
713+ instance_id = instance_id ,
714+ database_id = pg_database ,
715+ query = query ,
704716 )
705717 expected_docs = [
706718 Document (
@@ -722,15 +734,17 @@ def test_saver_pg_with_custom_schema(self, pg_client):
722734 ]
723735
724736 def test_delete (self , google_client ):
725- SpannerDocumentSaver .init_document_table (instance_id , google_database , table_name )
737+ SpannerDocumentSaver .init_document_table (
738+ instance_id , google_database , table_name
739+ )
726740 saver = SpannerDocumentSaver (
727741 instance_id , google_database , table_name , google_client
728742 )
729743 query = f"SELECT * FROM { table_name } "
730744 loader = SpannerLoader (
731745 client = google_client ,
732- instance = instance_id ,
733- database = google_database ,
746+ instance_id = instance_id ,
747+ database_id = google_database ,
734748 query = query ,
735749 )
736750 expected_docs = [
@@ -745,7 +759,9 @@ def test_delete(self, google_client):
745759 assert loader .load () == [expected_docs [1 ]]
746760
747761 def test_saver_with_bad_docs (self , google_client ):
748- SpannerDocumentSaver .init_document_table (instance_id , google_database , table_name )
762+ SpannerDocumentSaver .init_document_table (
763+ instance_id , google_database , table_name
764+ )
749765 saver = SpannerDocumentSaver (
750766 instance_id , google_database , table_name , google_client
751767 )
0 commit comments