Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: nullpointerexception for listroutines and listmodels #890

Merged
merged 1 commit into from Oct 30, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -388,7 +388,8 @@ public Tuple<String, Iterable<Model>> listModels(
.setMaxResults(Option.MAX_RESULTS.getLong(options))
.setPageToken(Option.PAGE_TOKEN.getString(options))
.execute();
Iterable<Model> models = modelList.getModels();
Iterable<Model> models =
modelList.getModels() != null ? modelList.getModels() : ImmutableList.<Model>of();
return Tuple.of(modelList.getNextPageToken(), models);
} catch (IOException ex) {
throw translate(ex);
Expand Down Expand Up @@ -456,7 +457,10 @@ public Tuple<String, Iterable<Routine>> listRoutines(
.setMaxResults(Option.MAX_RESULTS.getLong(options))
.setPageToken(Option.PAGE_TOKEN.getString(options))
.execute();
Iterable<Routine> routines = routineList.getRoutines();
Iterable<Routine> routines =
routineList.getRoutines() != null
? routineList.getRoutines()
: ImmutableList.<Routine>of();
return Tuple.of(routineList.getNextPageToken(), routines);
} catch (IOException ex) {
throw translate(ex);
Expand Down
Expand Up @@ -146,6 +146,7 @@ public class ITBigQueryTest {
private static final String MODEL_DATASET = RemoteBigQueryHelper.generateDatasetName();
private static final String ROUTINE_DATASET = RemoteBigQueryHelper.generateDatasetName();
private static final String PROJECT_ID = ServiceOptions.getDefaultProjectId();
private static final String RANDOM_ID = UUID.randomUUID().toString().substring(0, 8);
private static final Map<String, String> LABELS =
ImmutableMap.of(
"example-label1", "example-value1",
Expand Down Expand Up @@ -1425,6 +1426,29 @@ public void testModelLifecycle() throws InterruptedException {
assertTrue(bigquery.delete(modelId));
}

@Test
public void testEmptyListModels() {
String datasetId = "test_empty_dataset_list_models_" + RANDOM_ID;
assertNotNull(bigquery.create(DatasetInfo.of(datasetId)));
Page<Model> models = bigquery.listModels(datasetId, BigQuery.ModelListOption.pageSize(100));
assertEquals(0, Iterables.size(models.getValues()));
assertFalse(models.hasNextPage());
assertNull(models.getNextPageToken());
assertTrue(bigquery.delete(datasetId));
}

@Test
public void testEmptyListRoutines() {
String datasetId = "test_empty_dataset_list_routines_" + RANDOM_ID;
assertNotNull(bigquery.create(DatasetInfo.of(datasetId)));
Page<Routine> routines =
bigquery.listRoutines(datasetId, BigQuery.RoutineListOption.pageSize(100));
assertEquals(0, Iterables.size(routines.getValues()));
assertFalse(routines.hasNextPage());
assertNull(routines.getNextPageToken());
assertTrue(bigquery.delete(datasetId));
}

@Test
public void testRoutineLifecycle() throws InterruptedException {

Expand Down