Skip to content
This repository was archived by the owner on Feb 24, 2026. It is now read-only.

Commit d385995

Browse files
Refactoring down to only the simple case. Complex case will be handled in a different PR
1 parent 064c8d6 commit d385995

File tree

1 file changed

+6
-132
lines changed

1 file changed

+6
-132
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 Google LLC
2+
* Copyright 2021 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,7 +23,6 @@
2323
import com.google.cloud.bigquery.BigQuery;
2424
import com.google.cloud.bigquery.DatasetInfo;
2525
import com.google.cloud.bigquery.Field;
26-
import com.google.cloud.bigquery.Field.Mode;
2726
import com.google.cloud.bigquery.FieldValueList;
2827
import com.google.cloud.bigquery.Schema;
2928
import com.google.cloud.bigquery.StandardSQLTypeName;
@@ -60,10 +59,9 @@ public enum RowComplexity {
6059
Logger.getLogger(ITBigQueryStorageLongRunningTest.class.getName());
6160
private static final String LONG_TESTS_ENABLED_PROPERTY =
6261
"bigquery.storage.enable_long_running_tests";
63-
64-
private static String dataset;
6562
private static final String DESCRIPTION = "BigQuery Write Java long test dataset";
6663

64+
private static String dataset;
6765
private static BigQueryWriteClient client;
6866
private static String parentProjectId;
6967
private static BigQuery bigquery;
@@ -79,69 +77,7 @@ private static JSONObject MakeJsonObject(RowComplexity complexity) throws IOExce
7977
object.put("test_datetime", String.valueOf(LocalDateTime.now()));
8078
break;
8179
case COMPLEX:
82-
object.put("test_str", "aaa");
83-
object.put(
84-
"test_numerics1",
85-
new JSONArray(
86-
new String[] {
87-
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
88-
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28",
89-
"29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41",
90-
"42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54",
91-
"55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67",
92-
"68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80",
93-
"81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93",
94-
"94", "95", "96", "97", "98", "99", "100"
95-
}));
96-
object.put(
97-
"test_numerics2",
98-
new JSONArray(
99-
new String[] {
100-
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
101-
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28",
102-
"29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41",
103-
"42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54",
104-
"55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67",
105-
"68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80",
106-
"81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93",
107-
"94", "95", "96", "97", "98", "99", "100"
108-
}));
109-
object.put(
110-
"test_numerics3",
111-
new JSONArray(
112-
new String[] {
113-
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
114-
"16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28",
115-
"29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41",
116-
"42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54",
117-
"55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67",
118-
"68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80",
119-
"81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93",
120-
"94", "95", "96", "97", "98", "99", "100"
121-
}));
122-
object.put("test_datetime", String.valueOf(LocalDateTime.now()));
123-
object.put(
124-
"test_bools",
125-
new JSONArray(
126-
new boolean[] {
127-
false, true, false, true, false, true, false, true, false, true, false, true,
128-
false, true, false, true, false, true, true, false, true, false, true, false,
129-
true, false, true, false, true, false, true, true, false, true, false, true,
130-
false, true, false, true, false, true, false, true, true, false, true, false,
131-
true, false, true, false, true, false, true, false, true, true, false, true,
132-
false, true, false, true, false, true, false, true, false, true, true, false,
133-
true, false, true, false, true, false, true, false, true, false, true, true,
134-
false, true, false, true, false, true, false, true, false, true, false, true,
135-
true, false, true, false, true, false, true, false, true, false, true, false,
136-
true, true, false, true, false, true, false, true, false, true, false, true,
137-
false, true,
138-
}));
139-
JSONObject sub = new JSONObject();
140-
sub.put("sub_bool", true);
141-
sub.put("sub_int", 12);
142-
sub.put("sub_string", "Test Test Test");
143-
object.put("test_subs", new JSONArray(new JSONObject[] {sub, sub, sub, sub, sub, sub}));
144-
break;
80+
// TODO(jstocklass): make a complex object
14581
default:
14682
break;
14783
}
@@ -158,6 +94,7 @@ public static void beforeClass() throws IOException {
15894
dataset = RemoteBigQueryHelper.generateDatasetName();
15995
DatasetInfo datasetInfo =
16096
DatasetInfo.newBuilder(/* datasetId = */ dataset).setDescription(DESCRIPTION).build();
97+
LOG.info("Creating dataset: " + dataset);
16198
bigquery.create(datasetInfo);
16299
}
163100

@@ -173,7 +110,7 @@ public static void afterClass() {
173110
}
174111

175112
@Test
176-
public void testDefaultStream()
113+
public void testSimpleDefaultStream()
177114
throws IOException, InterruptedException, ExecutionException,
178115
Descriptors.DescriptorValidationException {
179116
// TODO(jstocklass): Set up a default stream. Write to it for a long time,
@@ -202,39 +139,7 @@ public void testDefaultStream()
202139
.build();
203140
bigquery.create(tableInfo);
204141

205-
StandardSQLTypeName[] array = new StandardSQLTypeName[] {StandardSQLTypeName.INT64};
206-
String complexTableName = "JsonComplexTableDefaultStream";
207-
TableInfo tableInfo2 =
208-
TableInfo.newBuilder(
209-
TableId.of(dataset, complexTableName),
210-
StandardTableDefinition.of(
211-
Schema.of(
212-
Field.newBuilder("test_str", StandardSQLTypeName.STRING).build(),
213-
Field.newBuilder("test_numerics1", StandardSQLTypeName.NUMERIC)
214-
.setMode(Mode.REPEATED)
215-
.build(),
216-
Field.newBuilder("test_numerics2", StandardSQLTypeName.NUMERIC)
217-
.setMode(Mode.REPEATED)
218-
.build(),
219-
Field.newBuilder("test_numerics3", StandardSQLTypeName.NUMERIC)
220-
.setMode(Mode.REPEATED)
221-
.build(),
222-
Field.newBuilder("test_datetime", StandardSQLTypeName.DATETIME).build(),
223-
Field.newBuilder("test_bools", StandardSQLTypeName.BOOL)
224-
.setMode(Mode.REPEATED)
225-
.build(),
226-
Field.newBuilder(
227-
"test_subs",
228-
StandardSQLTypeName.STRUCT,
229-
Field.of("sub_bool", StandardSQLTypeName.BOOL),
230-
Field.of("sub_int", StandardSQLTypeName.INT64),
231-
Field.of("sub_string", StandardSQLTypeName.STRING))
232-
.setMode(Mode.REPEATED)
233-
.build())))
234-
.build();
235-
bigquery.create(tableInfo2);
236-
237-
int requestLimit = 1000;
142+
int requestLimit = 10;
238143
long averageLatency = 0;
239144
long totalLatency = 0;
240145
TableName parent = TableName.of(ServiceOptions.getDefaultProjectId(), dataset, tableName);
@@ -272,36 +177,5 @@ public void testDefaultStream()
272177
}
273178
assertEquals(false, iter.hasNext());
274179
}
275-
parent = TableName.of(ServiceOptions.getDefaultProjectId(), dataset, complexTableName);
276-
try (JsonStreamWriter jsonStreamWriter =
277-
JsonStreamWriter.newBuilder(parent.toString(), tableInfo2.getDefinition().getSchema())
278-
.createDefaultStream()
279-
.build()) {
280-
for (int i = 0; i < requestLimit; i++) {
281-
JSONObject row = MakeJsonObject(RowComplexity.COMPLEX);
282-
JSONArray jsonArr = new JSONArray(new JSONObject[] {row});
283-
long startTime = System.nanoTime();
284-
// TODO(jstocklass): Make asynchronized calls instead of synchronized calls
285-
ApiFuture<AppendRowsResponse> response = jsonStreamWriter.append(jsonArr, -1);
286-
long finishTime = System.nanoTime();
287-
Assert.assertFalse(response.get().getAppendResult().hasOffset());
288-
if (i != 0) {
289-
totalLatency += (finishTime - startTime);
290-
}
291-
}
292-
averageLatency = totalLatency / requestLimit;
293-
LOG.info("Complex average Latency: " + String.valueOf(averageLatency) + " ns");
294-
TableResult result2 =
295-
bigquery.listTableData(
296-
tableInfo2.getTableId(), BigQuery.TableDataListOption.startIndex(0L));
297-
Iterator<FieldValueList> iter = result2.getValues().iterator();
298-
FieldValueList currentRow2;
299-
for (int i = 0; i < requestLimit; i++) {
300-
assertTrue(iter.hasNext());
301-
currentRow2 = iter.next();
302-
assertEquals("aaa", currentRow2.get(0).getStringValue());
303-
}
304-
assertEquals(false, iter.hasNext());
305-
}
306180
}
307181
}

0 commit comments

Comments
 (0)