11package io .cloudquery .internal .servers .plugin .v3 ;
22
33import com .google .protobuf .ByteString ;
4+ import io .cloudquery .plugin .BackendOptions ;
45import io .cloudquery .plugin .Plugin ;
56import io .cloudquery .plugin .v3 .PluginGrpc .PluginImplBase ;
67import io .cloudquery .plugin .v3 .Write ;
78import io .cloudquery .schema .Table ;
89import io .grpc .stub .StreamObserver ;
9- import java .io .ByteArrayOutputStream ;
10- import java .nio .channels .Channels ;
1110import java .util .ArrayList ;
1211import java .util .List ;
13- import org .apache .arrow .memory .BufferAllocator ;
14- import org .apache .arrow .memory .RootAllocator ;
15- import org .apache .arrow .vector .VectorSchemaRoot ;
16- import org .apache .arrow .vector .ipc .ArrowStreamWriter ;
17- import org .apache .arrow .vector .types .pojo .Schema ;
1812
1913public class PluginServer extends PluginImplBase {
2014 private final Plugin plugin ;
@@ -64,18 +58,7 @@ public void getTables(
6458 request .getSkipDependentTables ());
6559 List <ByteString > byteStrings = new ArrayList <>();
6660 for (Table table : tables ) {
67- try (BufferAllocator bufferAllocator = new RootAllocator ()) {
68- Schema schema = table .toArrowSchema ();
69- VectorSchemaRoot schemaRoot = VectorSchemaRoot .create (schema , bufferAllocator );
70- try (ByteArrayOutputStream out = new ByteArrayOutputStream ()) {
71- try (ArrowStreamWriter writer =
72- new ArrowStreamWriter (schemaRoot , null , Channels .newChannel (out ))) {
73- writer .start ();
74- writer .end ();
75- byteStrings .add (ByteString .copyFrom (out .toByteArray ()));
76- }
77- }
78- }
61+ byteStrings .add (table .encode ());
7962 }
8063 responseObserver .onNext (
8164 io .cloudquery .plugin .v3 .GetTables .Response .newBuilder ()
@@ -91,9 +74,18 @@ public void getTables(
9174 public void sync (
9275 io .cloudquery .plugin .v3 .Sync .Request request ,
9376 StreamObserver <io .cloudquery .plugin .v3 .Sync .Response > responseObserver ) {
94- plugin .sync ();
95- responseObserver .onNext (io .cloudquery .plugin .v3 .Sync .Response .newBuilder ().build ());
96- responseObserver .onCompleted ();
77+ try {
78+ plugin .sync (
79+ request .getTablesList (),
80+ request .getSkipTablesList (),
81+ request .getSkipDependentTables (),
82+ request .getDeterministicCqId (),
83+ new BackendOptions (
84+ request .getBackend ().getTableName (), request .getBackend ().getConnection ()),
85+ responseObserver );
86+ } catch (Exception e ) {
87+ responseObserver .onError (e );
88+ }
9789 }
9890
9991 @ Override
0 commit comments