@@ -20,6 +20,10 @@ func TestInformationSchema(t *testing.T) {
2020 dsn := testclickhouse .Start (t )
2121 conn , err := drivers .Open ("clickhouse" , "default" , map [string ]any {"dsn" : dsn , "mode" : "readwrite" }, storage .MustNew (t .TempDir (), nil ), activity .NewNoopClient (), zap .NewNop ())
2222 require .NoError (t , err )
23+
24+ infoSchema , ok := conn .AsInformationSchema ()
25+ require .True (t , ok )
26+
2327 prepareConn (t , conn )
2428 t .Run ("testInformationSchemaAll" , func (t * testing.T ) { testInformationSchemaAll (t , conn ) })
2529 t .Run ("testInformationSchemaAllLike" , func (t * testing.T ) { testInformationSchemaAllLike (t , conn ) })
@@ -29,8 +33,13 @@ func TestInformationSchema(t *testing.T) {
2933 testInformationSchemaSystemAllLike (t , conn )
3034 })
3135 t .Run ("testInformationSchemaLookup" , func (t * testing.T ) { testInformationSchemaLookup (t , conn ) })
32- t .Run ("testInformationSchemaPagination" , func (t * testing.T ) { testInformationSchemaAllPagination (t , conn ) })
33- t .Run ("testInformationSchemaPaginationWithLike" , func (t * testing.T ) { testInformationSchemaAllPaginationWithLike (t , conn ) })
36+ t .Run ("testInformationSchemaAllPagination" , func (t * testing.T ) { testInformationSchemaAllPagination (t , conn ) })
37+ t .Run ("testInformationSchemaAllPaginationWithLike" , func (t * testing.T ) { testInformationSchemaAllPaginationWithLike (t , conn ) })
38+ t .Run ("testInformationSchemaListDatabaseSchemas" , func (t * testing.T ) { testInformationSchemaListDatabaseSchemas (t , infoSchema ) })
39+ t .Run ("testInformationSchemaListTables" , func (t * testing.T ) { testInformationSchemaListTables (t , infoSchema ) })
40+ t .Run ("testInformationSchemaGetTable" , func (t * testing.T ) { testInformationSchemaGetTable (t , infoSchema ) })
41+ t .Run ("testInformationSchemaListDatabaseSchemasPagination" , func (t * testing.T ) { testInformationSchemaListDatabaseSchemasPagination (t , infoSchema ) })
42+ t .Run ("testInformationSchemaListTablesPagination" , func (t * testing.T ) { testInformationSchemaListTablesPagination (t , infoSchema ) })
3443}
3544
3645func testInformationSchemaAll (t * testing.T , conn drivers.Handle ) {
@@ -186,6 +195,119 @@ func testInformationSchemaAllPaginationWithLike(t *testing.T, conn drivers.Handl
186195 require .Empty (t , nextToken )
187196}
188197
198+ func testInformationSchemaListDatabaseSchemas (t * testing.T , infoSchema drivers.InformationSchema ) {
199+ databaseSchemaInfo , _ , err := infoSchema .ListDatabaseSchemas (context .Background (), 0 , "" )
200+ require .NoError (t , err )
201+ require .Equal (t , 3 , len (databaseSchemaInfo ))
202+
203+ require .Equal (t , "" , databaseSchemaInfo [0 ].Database )
204+ require .Equal (t , "clickhouse" , databaseSchemaInfo [0 ].DatabaseSchema )
205+ require .Equal (t , "" , databaseSchemaInfo [1 ].Database )
206+ require .Equal (t , "default" , databaseSchemaInfo [1 ].DatabaseSchema )
207+ require .Equal (t , "" , databaseSchemaInfo [2 ].Database )
208+ require .Equal (t , "other" , databaseSchemaInfo [2 ].DatabaseSchema )
209+ }
210+
211+ func testInformationSchemaListTables (t * testing.T , infoSchema drivers.InformationSchema ) {
212+ tables , _ , err := infoSchema .ListTables (context .Background (), "" , "default" , 0 , "" )
213+ require .NoError (t , err )
214+ require .Equal (t , len (tables ), 3 )
215+
216+ require .Equal (t , "bar" , tables [0 ].Name )
217+ require .Equal (t , false , tables [0 ].View )
218+ require .Equal (t , "foo" , tables [1 ].Name )
219+ require .Equal (t , false , tables [1 ].View )
220+ require .Equal (t , "model" , tables [2 ].Name )
221+ require .Equal (t , true , tables [2 ].View )
222+
223+ tables , _ , err = infoSchema .ListTables (context .Background (), "" , "other" , 0 , "" )
224+ require .NoError (t , err )
225+ require .Equal (t , len (tables ), 2 )
226+
227+ require .Equal (t , "bar" , tables [0 ].Name )
228+ require .Equal (t , false , tables [0 ].View )
229+ require .Equal (t , "foo" , tables [1 ].Name )
230+ require .Equal (t , false , tables [1 ].View )
231+ }
232+
233+ func testInformationSchemaGetTable (t * testing.T , infoSchema drivers.InformationSchema ) {
234+ ctx := context .Background ()
235+
236+ // Existing table
237+ foo , err := infoSchema .GetTable (ctx , "" , "default" , "foo" )
238+ require .NoError (t , err )
239+ require .Len (t , foo .Schema , 2 )
240+ require .Equal (t , "STRING" , foo .Schema ["bar" ])
241+ require .Equal (t , "INT32" , foo .Schema ["baz" ])
242+ require .False (t , foo .View )
243+
244+ // Non-existent table
245+ noTable , err := infoSchema .GetTable (ctx , "" , "default" , "nonexistent_table" )
246+ require .NoError (t , err )
247+ require .Empty (t , noTable .Schema )
248+
249+ // View
250+ model , err := infoSchema .GetTable (ctx , "" , "default" , "model" )
251+ require .NoError (t , err )
252+ require .Equal (t , "UINT8" , model .Schema ["1" ])
253+ require .Equal (t , "UINT8" , model .Schema ["2" ])
254+ require .Equal (t , "UINT8" , model .Schema ["3" ])
255+ require .True (t , model .View )
256+
257+ ofoo , err := infoSchema .GetTable (ctx , "" , "other" , "foo" )
258+ require .NoError (t , err )
259+ require .Equal (t , "STRING" , ofoo .Schema ["bar" ])
260+ require .Equal (t , "INT32" , ofoo .Schema ["baz" ])
261+ require .Equal (t , false , ofoo .View )
262+
263+ }
264+
265+ func testInformationSchemaListDatabaseSchemasPagination (t * testing.T , infoSchema drivers.InformationSchema ) {
266+ ctx := context .Background ()
267+ pageSize := 2
268+
269+ // First page
270+ page1 , token1 , err := infoSchema .ListDatabaseSchemas (ctx , uint32 (pageSize ), "" )
271+ require .NoError (t , err )
272+ require .Len (t , page1 , pageSize )
273+ require .NotEmpty (t , token1 )
274+
275+ // second page
276+ page2 , token2 , err := infoSchema .ListDatabaseSchemas (ctx , uint32 (pageSize ), token1 )
277+ require .NoError (t , err )
278+ require .NotEmpty (t , page2 )
279+ require .Empty (t , token2 )
280+
281+ // Page size 0
282+ all , token , err := infoSchema .ListDatabaseSchemas (ctx , 0 , "" )
283+ require .NoError (t , err )
284+ require .Equal (t , len (all ), 3 )
285+ require .Empty (t , token )
286+ }
287+
288+ func testInformationSchemaListTablesPagination (t * testing.T , infoSchema drivers.InformationSchema ) {
289+ ctx := context .Background ()
290+ pageSize := 2
291+
292+ // First page
293+ page1 , token1 , err := infoSchema .ListTables (ctx , "" , "default" , uint32 (pageSize ), "" )
294+ require .NoError (t , err )
295+ require .Len (t , page1 , pageSize )
296+ require .NotEmpty (t , token1 )
297+
298+ // Second page
299+ page2 , token2 , err := infoSchema .ListTables (ctx , "" , "default" , uint32 (pageSize ), token1 )
300+ require .NoError (t , err )
301+ require .NotEmpty (t , page2 )
302+ require .Empty (t , token2 )
303+
304+ // Page size 0
305+ all , token , err := infoSchema .ListTables (ctx , "" , "default" , 0 , "" )
306+ require .NoError (t , err )
307+ require .GreaterOrEqual (t , len (all ), 3 )
308+ require .Empty (t , token )
309+ }
310+
189311func prepareConn (t * testing.T , conn drivers.Handle ) {
190312 olap , ok := conn .AsOLAP ("" )
191313 require .True (t , ok )
0 commit comments