11package com .microsoft .semantickernel .tests .connectors .memory .jdbc ;
22
3+ import com .microsoft .semantickernel .connectors .data .hsqldb .HSQLDBVectorStoreQueryProvider ;
34import com .microsoft .semantickernel .connectors .data .jdbc .JDBCVectorStore ;
45import com .microsoft .semantickernel .connectors .data .jdbc .JDBCVectorStoreOptions ;
56import com .microsoft .semantickernel .connectors .data .jdbc .SQLVectorStoreQueryProvider ;
89import com .microsoft .semantickernel .connectors .data .postgres .PostgreSQLVectorStoreQueryProvider ;
910import com .microsoft .semantickernel .connectors .data .sqlite .SQLiteVectorStoreQueryProvider ;
1011import com .mysql .cj .jdbc .MysqlDataSource ;
12+ import org .hsqldb .jdbc .JDBCDataSourceFactory ;
1113import org .junit .jupiter .params .ParameterizedTest ;
1214import org .junit .jupiter .params .provider .EnumSource ;
1315import org .postgresql .ds .PGSimpleDataSource ;
1921import org .testcontainers .utility .DockerImageName ;
2022
2123import javax .sql .DataSource ;
24+ import java .nio .file .Files ;
25+ import java .nio .file .Path ;
2226import java .util .Arrays ;
2327import java .util .List ;
28+ import java .util .Map ;
29+ import java .util .Properties ;
2430
2531import com .microsoft .semantickernel .tests .connectors .memory .jdbc .JDBCVectorStoreRecordCollectionTest .QueryProvider ;
32+
2633import static org .junit .jupiter .api .Assertions .assertEquals ;
2734import static org .junit .jupiter .api .Assertions .assertNotNull ;
2835import static org .junit .jupiter .api .Assertions .assertTrue ;
2936
3037@ Testcontainers
3138public class JDBCVectorStoreTest {
39+
3240 @ Container
3341 private static final MySQLContainer <?> MYSQL_CONTAINER = new MySQLContainer <>("mysql:5.7.34" );
3442
35- private static final DockerImageName PGVECTOR = DockerImageName .parse ("pgvector/pgvector:pg16" ).asCompatibleSubstituteFor ("postgres" );
43+ private static final DockerImageName PGVECTOR = DockerImageName .parse ("pgvector/pgvector:pg16" )
44+ .asCompatibleSubstituteFor ("postgres" );
3645 @ Container
37- private static final PostgreSQLContainer <?> POSTGRESQL_CONTAINER = new PostgreSQLContainer <>(PGVECTOR );
46+ private static final PostgreSQLContainer <?> POSTGRESQL_CONTAINER = new PostgreSQLContainer <>(
47+ PGVECTOR );
3848
3949 private JDBCVectorStore buildVectorStore (QueryProvider provider ) {
4050 SQLVectorStoreQueryProvider queryProvider ;
@@ -48,8 +58,8 @@ private JDBCVectorStore buildVectorStore(QueryProvider provider) {
4858 mysqlDataSource .setPassword (MYSQL_CONTAINER .getPassword ());
4959 dataSource = mysqlDataSource ;
5060 queryProvider = MySQLVectorStoreQueryProvider .builder ()
51- .withDataSource (dataSource )
52- .build ();
61+ .withDataSource (dataSource )
62+ .build ();
5363 break ;
5464 case PostgreSQL :
5565 PGSimpleDataSource pgSimpleDataSource = new PGSimpleDataSource ();
@@ -58,30 +68,53 @@ private JDBCVectorStore buildVectorStore(QueryProvider provider) {
5868 pgSimpleDataSource .setPassword (POSTGRESQL_CONTAINER .getPassword ());
5969 dataSource = pgSimpleDataSource ;
6070 queryProvider = PostgreSQLVectorStoreQueryProvider .builder ()
61- .withDataSource (dataSource )
62- .build ();
71+ .withDataSource (dataSource )
72+ .build ();
6373 break ;
6474 case SQLite :
6575 SQLiteDataSource sqliteDataSource = new SQLiteDataSource ();
6676 sqliteDataSource .setUrl ("jdbc:sqlite:file:test" );
6777 dataSource = sqliteDataSource ;
6878 queryProvider = SQLiteVectorStoreQueryProvider .builder ()
69- .withDataSource (sqliteDataSource )
70- .build ();
79+ .withDataSource (sqliteDataSource )
80+ .build ();
81+ break ;
82+ case HSQLDB :
83+ try {
84+ Path file = Files .createTempFile ("testdb" , ".db" );
85+ file .toFile ().deleteOnExit ();
86+
87+ Properties properties = new Properties ();
88+ properties .putAll (
89+ Map .of (
90+ "url" , "jdbc:hsqldb:file:" + file .toFile ().getAbsolutePath ()
91+ + ";sql.syntax_mys=true" ,
92+ "user" , "SA" ,
93+ "password" , ""
94+ )
95+ );
96+
97+ dataSource = JDBCDataSourceFactory .createDataSource (properties );
98+ } catch (Exception e ) {
99+ throw new RuntimeException (e );
100+ }
101+
102+ queryProvider = HSQLDBVectorStoreQueryProvider .builder ()
103+ .withDataSource (dataSource )
104+ .build ();
71105 break ;
72106 default :
73107 throw new IllegalArgumentException ("Unknown query provider: " + provider );
74108 }
75109
76-
77110 JDBCVectorStore vectorStore = JDBCVectorStore .builder ()
78- .withDataSource (dataSource )
79- .withOptions (
80- JDBCVectorStoreOptions .builder ()
81- .withQueryProvider (queryProvider )
82- .build ()
83- )
84- .build ();
111+ .withDataSource (dataSource )
112+ .withOptions (
113+ JDBCVectorStoreOptions .builder ()
114+ .withQueryProvider (queryProvider )
115+ .build ()
116+ )
117+ .build ();
85118
86119 vectorStore .prepareAsync ().block ();
87120 return vectorStore ;
@@ -99,7 +132,7 @@ public void getCollectionNamesAsync(QueryProvider provider) {
99132
100133 for (String collectionName : collectionNames ) {
101134 vectorStore .getCollection (collectionName ,
102- JDBCVectorStoreRecordCollectionOptions .<Hotel >builder ()
135+ JDBCVectorStoreRecordCollectionOptions .<Hotel >builder ()
103136 .withRecordClass (Hotel .class )
104137 .build ()).createCollectionAsync ().block ();
105138 }
0 commit comments