1
1
package io .cloudquery .memdb ;
2
2
3
3
import io .cloudquery .plugin .BackendOptions ;
4
+ import io .cloudquery .plugin .ClientNotInitializedException ;
5
+ import io .cloudquery .plugin .NewClientOptions ;
4
6
import io .cloudquery .plugin .Plugin ;
7
+ import io .cloudquery .plugin .TableOutputStream ;
5
8
import io .cloudquery .scheduler .Scheduler ;
9
+ import io .cloudquery .schema .ClientMeta ;
6
10
import io .cloudquery .schema .Column ;
11
+ import io .cloudquery .schema .Resource ;
7
12
import io .cloudquery .schema .SchemaException ;
8
13
import io .cloudquery .schema .Table ;
14
+ import io .cloudquery .schema .TableResolver ;
9
15
import io .grpc .stub .StreamObserver ;
10
16
import java .util .List ;
11
17
import org .apache .arrow .vector .types .pojo .ArrowType .Utf8 ;
@@ -15,26 +21,44 @@ public class MemDB extends Plugin {
15
21
List .of (
16
22
Table .builder ()
17
23
.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 ()))
19
34
.build (),
20
35
Table .builder ()
21
36
.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 ()))
23
47
.build ());
24
48
49
+ private Spec spec ;
50
+
25
51
public MemDB () {
26
52
super ("memdb" , "0.0.1" );
27
53
}
28
54
29
- @ Override
30
- public void init () {
31
- // do nothing
32
- }
33
-
34
55
@ Override
35
56
public List <Table > tables (
36
57
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
+ }
38
62
return Table .filterDFS (allTables , includeList , skipList , skipDependentTables );
39
63
}
40
64
@@ -46,13 +70,19 @@ public void sync(
46
70
boolean deterministicCqId ,
47
71
BackendOptions backendOptions ,
48
72
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
+
50
78
List <Table > filtered = Table .filterDFS (allTables , includeList , skipList , skipDependentTables );
51
79
Scheduler .builder ()
80
+ .client (client )
52
81
.tables (filtered )
53
82
.syncStream (syncStream )
54
83
.deterministicCqId (deterministicCqId )
55
84
.logger (getLogger ())
85
+ .concurrency (this .spec .getConcurrency ())
56
86
.build ()
57
87
.sync ();
58
88
}
@@ -69,6 +99,17 @@ public void write() {
69
99
70
100
@ Override
71
101
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 ();
73
114
}
74
115
}
0 commit comments