Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.services.bigquery.model.TableFieldSchema;
import com.google.api.services.bigquery.model.TableSchema;
import com.google.common.base.Function;
import com.google.common.base.MoreObjects;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/** This class represents the schema for a Google BigQuery Table or data source. */
Expand Down Expand Up @@ -90,6 +93,10 @@ TableSchema toPb() {
}

static Schema fromPb(com.google.api.services.bigquery.model.TableSchema tableSchemaPb) {
return Schema.of(FieldList.fromPb(tableSchemaPb.getFields()));
List<TableFieldSchema> fields = tableSchemaPb.getFields();
if (fields == null) {
fields = Collections.emptyList();
}
return Schema.of(FieldList.fromPb(fields));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.junit.Assert.assertEquals;

import com.google.api.services.bigquery.model.TableSchema;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.junit.Test;
Expand Down Expand Up @@ -57,4 +58,11 @@ private void compareTableSchema(Schema expected, Schema value) {
assertEquals(expected, value);
assertEquals(expected.getFields(), value.getFields());
}

@Test
public void testEmptySchema() {
TableSchema tableSchema = new TableSchema();
Schema schema = Schema.fromPb(tableSchema);
assertEquals(0, schema.getFields().size());
}
}