1212
1313import com .google .protobuf .ByteString ;
1414import io .cloudquery .schema .Column ;
15+ import io .cloudquery .schema .Resource ;
1516import io .cloudquery .schema .Table ;
1617import java .io .IOException ;
1718import java .util .List ;
1819import java .util .Map ;
1920import org .apache .arrow .vector .types .pojo .ArrowType ;
2021import org .apache .arrow .vector .types .pojo .Field ;
2122import org .apache .arrow .vector .types .pojo .Schema ;
23+ import org .junit .jupiter .api .Assertions ;
2224import org .junit .jupiter .api .Test ;
2325
2426public class ArrowHelperTest {
@@ -32,20 +34,21 @@ public class ArrowHelperTest {
3234 .columns (
3335 List .of (
3436 Column .builder ()
35- .name ("column1 " )
37+ .name ("string_column1 " )
3638 .type (ArrowType .Utf8 .INSTANCE )
3739 .unique (true )
3840 .incrementalKey (true )
3941 .primaryKey (true )
4042 .build (),
41- Column .builder ().name ("column2" ).type (ArrowType .Utf8 .INSTANCE ).build ()))
43+ Column .builder ().name ("string_column2" ).type (ArrowType .Utf8 .INSTANCE ).build (),
44+ Column .builder ().name ("boolean_column" ).type (ArrowType .Bool .INSTANCE ).build ()))
4245 .build ();
4346
4447 @ Test
4548 public void testToArrowSchema () {
4649 Schema arrowSchema = ArrowHelper .toArrowSchema (TEST_TABLE );
4750
48- assertEquals (arrowSchema .getFields ().get (0 ).getName (), "column1 " );
51+ assertEquals (arrowSchema .getFields ().get (0 ).getName (), "string_column1 " );
4952 assertEquals (
5053 arrowSchema .getFields ().get (0 ).getMetadata (),
5154 Map .of (
@@ -55,7 +58,7 @@ public void testToArrowSchema() {
5558 "true" ,
5659 CQ_EXTENSION_PRIMARY_KEY ,
5760 "true" ));
58- assertEquals (arrowSchema .getFields ().get (1 ).getName (), "column2 " );
61+ assertEquals (arrowSchema .getFields ().get (1 ).getName (), "string_column2 " );
5962 assertEquals (
6063 arrowSchema .getFields ().get (1 ).getMetadata (),
6164 Map .of (
@@ -80,8 +83,8 @@ public void testToArrowSchema() {
8083 public void testFromArrowSchema () {
8184 List <Field > fields =
8285 List .of (
83- Field .nullable ("column1 " , ArrowType .Utf8 .INSTANCE ),
84- Field .nullable ("column2 " , ArrowType .Utf8 .INSTANCE ));
86+ Field .nullable ("string_column1 " , ArrowType .Utf8 .INSTANCE ),
87+ Field .nullable ("string_column2 " , ArrowType .Utf8 .INSTANCE ));
8588
8689 Schema schema = new Schema (fields , Map .of (CQ_TABLE_NAME , "table1" ));
8790
@@ -97,7 +100,7 @@ public void testFromArrowSchema() {
97100 }
98101
99102 @ Test
100- public void testRoundTrip () throws IOException {
103+ public void testRoundTripTableEncoding () throws IOException {
101104 ByteString byteString = ArrowHelper .encode (TEST_TABLE );
102105 Table table = ArrowHelper .decode (byteString );
103106
@@ -111,4 +114,18 @@ public void testRoundTrip() throws IOException {
111114 assertEquals (TEST_TABLE .getColumns ().get (i ).getType (), table .getColumns ().get (i ).getType ());
112115 }
113116 }
117+
118+ @ Test
119+ public void testRoundTripResourceEncoding () throws Exception {
120+ Resource resource = Resource .builder ().table (TEST_TABLE ).build ();
121+ resource .set ("string_column1" , "test_data" );
122+ resource .set ("string_column2" , "test_data2" );
123+ resource .set ("boolean_column" , true );
124+
125+ Assertions .assertDoesNotThrow (
126+ () -> {
127+ ByteString byteString = ArrowHelper .encode (resource );
128+ ArrowHelper .decodeResource (byteString );
129+ });
130+ }
114131}
0 commit comments