11package io .cloudquery .memdb ;
22
33import io .cloudquery .plugin .BackendOptions ;
4+ import io .cloudquery .plugin .ClientNotInitializedException ;
5+ import io .cloudquery .plugin .NewClientOptions ;
46import io .cloudquery .plugin .Plugin ;
7+ import io .cloudquery .plugin .TableOutputStream ;
58import io .cloudquery .scheduler .Scheduler ;
9+ import io .cloudquery .schema .ClientMeta ;
610import io .cloudquery .schema .Column ;
11+ import io .cloudquery .schema .Resource ;
712import io .cloudquery .schema .SchemaException ;
813import io .cloudquery .schema .Table ;
14+ import io .cloudquery .schema .TableResolver ;
915import io .grpc .stub .StreamObserver ;
1016import java .util .List ;
1117import org .apache .arrow .vector .types .pojo .ArrowType .Utf8 ;
@@ -15,26 +21,44 @@ public class MemDB extends Plugin {
1521 List .of (
1622 Table .builder ()
1723 .name ("table1" )
18- .columns (List .of (Column .builder ().name ("name1" ).type (new Utf8 ()).build ()))
24+ .resolver (
25+ new TableResolver () {
26+ @ Override
27+ public void resolve (
28+ ClientMeta clientMeta , Resource parent , TableOutputStream stream ) {
29+ stream .write (Table1Data .builder ().name ("name1" ).build ());
30+ stream .write (Table1Data .builder ().name ("name2" ).build ());
31+ }
32+ })
33+ .columns (List .of (Column .builder ().name ("name" ).type (new Utf8 ()).build ()))
1934 .build (),
2035 Table .builder ()
2136 .name ("table2" )
22- .columns (List .of (Column .builder ().name ("name1" ).type (new Utf8 ()).build ()))
37+ .resolver (
38+ new TableResolver () {
39+ @ Override
40+ public void resolve (
41+ ClientMeta clientMeta , Resource parent , TableOutputStream stream ) {
42+ stream .write (Table2Data .builder ().id ("id1" ).build ());
43+ stream .write (Table2Data .builder ().id ("id2" ).build ());
44+ }
45+ })
46+ .columns (List .of (Column .builder ().name ("id" ).type (new Utf8 ()).build ()))
2347 .build ());
2448
49+ private Spec spec ;
50+
2551 public MemDB () {
2652 super ("memdb" , "0.0.1" );
2753 }
2854
29- @ Override
30- public void init () {
31- // do nothing
32- }
33-
3455 @ Override
3556 public List <Table > tables (
3657 List <String > includeList , List <String > skipList , boolean skipDependentTables )
37- throws SchemaException {
58+ throws SchemaException , ClientNotInitializedException {
59+ if (this .client == null ) {
60+ throw new ClientNotInitializedException ();
61+ }
3862 return Table .filterDFS (allTables , includeList , skipList , skipDependentTables );
3963 }
4064
@@ -46,13 +70,19 @@ public void sync(
4670 boolean deterministicCqId ,
4771 BackendOptions backendOptions ,
4872 StreamObserver <io .cloudquery .plugin .v3 .Sync .Response > syncStream )
49- throws SchemaException {
73+ throws SchemaException , ClientNotInitializedException {
74+ if (this .client == null ) {
75+ throw new ClientNotInitializedException ();
76+ }
77+
5078 List <Table > filtered = Table .filterDFS (allTables , includeList , skipList , skipDependentTables );
5179 Scheduler .builder ()
80+ .client (client )
5281 .tables (filtered )
5382 .syncStream (syncStream )
5483 .deterministicCqId (deterministicCqId )
5584 .logger (getLogger ())
85+ .concurrency (this .spec .getConcurrency ())
5686 .build ()
5787 .sync ();
5888 }
@@ -69,6 +99,17 @@ public void write() {
6999
70100 @ Override
71101 public void close () {
72- // do nothing
102+ if (this .client != null ) {
103+ ((MemDBClient ) this .client ).close ();
104+ }
105+ }
106+
107+ @ Override
108+ public ClientMeta newClient (String spec , NewClientOptions options ) throws Exception {
109+ if (options .isNoConnection ()) {
110+ return null ;
111+ }
112+ this .spec = Spec .fromJSON (spec );
113+ return new MemDBClient ();
73114 }
74115}
0 commit comments