File tree Expand file tree Collapse file tree
branches/autosynth-websecurityscanner/google-cloud-clients/google-cloud-bigquery/src
main/java/com/google/cloud/bigquery
test/java/com/google/cloud/bigquery Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -145,7 +145,7 @@ refs/heads/autosynth-speech: 75d6c62a9d07d3a3642980502a25d07fbde0f232
145145refs/heads/autosynth-tasks: b0cdb991f3f75345151a3f68db1aab273dfc069b
146146refs/heads/autosynth-texttospeech: 2dcc5dc22be0f456caa1b6a8a4bcdace2641239c
147147refs/heads/autosynth-trace: db35fc1080cc51034e9c431c141cbceb53fb19c1
148- refs/heads/autosynth-websecurityscanner: 2aa9d803ed532d91a5f430368f1ec4fd21f3dd24
148+ refs/heads/autosynth-websecurityscanner: ea68410f175b64ab06ff8bd1371935d12e3ce3e9
149149refs/heads/bigquerystorage: 06db74d123d7f8a3ef48755c2fcabed09faf8e64
150150refs/heads/elharo-patch-1: ce159ef828d3c545991ff78e7b6e0d912a9453e9
151151refs/heads/mrschmidt-numericadd: 96509abadf6190b7886d57fdd9b090da55f5171c
Original file line number Diff line number Diff line change 1818
1919import static com .google .common .base .Preconditions .checkNotNull ;
2020
21+ import com .google .api .services .bigquery .model .TableFieldSchema ;
2122import com .google .api .services .bigquery .model .TableSchema ;
2223import com .google .common .base .Function ;
2324import com .google .common .base .MoreObjects ;
2425import java .io .Serializable ;
26+ import java .util .Collections ;
27+ import java .util .List ;
2528import java .util .Objects ;
2629
2730/** This class represents the schema for a Google BigQuery Table or data source. */
@@ -90,6 +93,10 @@ TableSchema toPb() {
9093 }
9194
9295 static Schema fromPb (com .google .api .services .bigquery .model .TableSchema tableSchemaPb ) {
93- return Schema .of (FieldList .fromPb (tableSchemaPb .getFields ()));
96+ List <TableFieldSchema > fields = tableSchemaPb .getFields ();
97+ if (fields == null ) {
98+ fields = Collections .emptyList ();
99+ }
100+ return Schema .of (FieldList .fromPb (fields ));
94101 }
95102}
Original file line number Diff line number Diff line change 1818
1919import static org .junit .Assert .assertEquals ;
2020
21+ import com .google .api .services .bigquery .model .TableSchema ;
2122import com .google .common .collect .ImmutableList ;
2223import java .util .List ;
2324import org .junit .Test ;
@@ -57,4 +58,11 @@ private void compareTableSchema(Schema expected, Schema value) {
5758 assertEquals (expected , value );
5859 assertEquals (expected .getFields (), value .getFields ());
5960 }
61+
62+ @ Test
63+ public void testEmptySchema () {
64+ TableSchema tableSchema = new TableSchema ();
65+ Schema schema = Schema .fromPb (tableSchema );
66+ assertEquals (0 , schema .getFields ().size ());
67+ }
6068}
You can’t perform that action at this time.
0 commit comments