Skip to content

Commit c5e4c65

Browse files
committed
chore: minor refactors
1 parent 119ad10 commit c5e4c65

2 files changed

Lines changed: 31 additions & 39 deletions

File tree

java-bigquery/google-cloud-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaData.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,19 +1749,14 @@ private ResultSet getTablesImpl(
17491749

17501750
@VisibleForTesting
17511751
Thread runGetTablesTaskAsync(
1752-
String catalog,
1753-
String schemaPattern,
1752+
String effectiveCatalog,
1753+
String effectiveSchemaPattern,
17541754
String tableNamePattern,
17551755
String[] types,
17561756
Schema resultSchema,
17571757
BlockingQueue<BigQueryFieldValueListWrapper> queue)
17581758
throws SQLException {
17591759

1760-
Tuple<String, String> effectiveIdentifiers =
1761-
determineEffectiveCatalogAndSchema(catalog, schemaPattern);
1762-
String effectiveCatalog = effectiveIdentifiers.x();
1763-
String effectiveSchemaPattern = effectiveIdentifiers.y();
1764-
17651760
final Pattern schemaRegex = compileSqlLikePattern(effectiveSchemaPattern);
17661761
final Pattern tableNameRegex = compileSqlLikePattern(tableNamePattern);
17671762
final Set<String> requestedTypes =
@@ -2155,7 +2150,12 @@ private ResultSet getColumnsImpl(
21552150

21562151
Thread fetcherThread =
21572152
runGetColumnsTaskAsync(
2158-
catalog, schemaPattern, tableNamePattern, columnNamePattern, resultSchema, queue);
2153+
effectiveCatalog,
2154+
effectiveSchemaPattern,
2155+
tableNamePattern,
2156+
columnNamePattern,
2157+
resultSchema,
2158+
queue);
21592159

21602160
BigQueryJsonResultSet resultSet =
21612161
BigQueryJsonResultSet.of(resultSchema, -1, queue, null, new Thread[] {fetcherThread});
@@ -2166,19 +2166,14 @@ private ResultSet getColumnsImpl(
21662166

21672167
@VisibleForTesting
21682168
Thread runGetColumnsTaskAsync(
2169-
String catalog,
2170-
String schemaPattern,
2169+
String effectiveCatalog,
2170+
String effectiveSchemaPattern,
21712171
String tableNamePattern,
21722172
String columnNamePattern,
21732173
Schema resultSchema,
21742174
BlockingQueue<BigQueryFieldValueListWrapper> queue)
21752175
throws SQLException {
21762176

2177-
Tuple<String, String> effectiveIdentifiers =
2178-
determineEffectiveCatalogAndSchema(catalog, schemaPattern);
2179-
String effectiveCatalog = effectiveIdentifiers.x();
2180-
String effectiveSchemaPattern = effectiveIdentifiers.y();
2181-
21822177
Pattern schemaRegex = compileSqlLikePattern(effectiveSchemaPattern);
21832178
Pattern tableNameRegex = compileSqlLikePattern(tableNamePattern);
21842179
Pattern columnNameRegex = compileSqlLikePattern(columnNamePattern);

java-bigquery/google-cloud-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryDatabaseMetaDataTest.java

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3299,14 +3299,7 @@ public void testGetTables_createsDetachedLinkedSpan() throws Exception {
32993299
Assertions.assertNotNull(workerThread, "Worker thread should not be null");
33003300
workerThread.join();
33013301

3302-
boolean found =
3303-
otelTesting.getSpans().stream()
3304-
.anyMatch(
3305-
span ->
3306-
span.getName().equals("BigQueryDatabaseMetaData.getTables.background")
3307-
&& span.getLinks().stream()
3308-
.anyMatch(link -> link.getSpanContext().isValid()));
3309-
assertTrue(found);
3302+
assertSpanLinkedToParent("BigQueryDatabaseMetaData.getTables.background", parentSpan);
33103303
} finally {
33113304
parentSpan.end();
33123305
}
@@ -3327,14 +3320,7 @@ public void testGetColumns_createsDetachedLinkedSpan() throws Exception {
33273320
Assertions.assertNotNull(workerThread, "Worker thread should not be null");
33283321
workerThread.join();
33293322

3330-
boolean found =
3331-
otelTesting.getSpans().stream()
3332-
.anyMatch(
3333-
span ->
3334-
span.getName().equals("BigQueryDatabaseMetaData.getColumns.background")
3335-
&& span.getLinks().stream()
3336-
.anyMatch(link -> link.getSpanContext().isValid()));
3337-
assertTrue(found);
3323+
assertSpanLinkedToParent("BigQueryDatabaseMetaData.getColumns.background", parentSpan);
33383324
} finally {
33393325
parentSpan.end();
33403326
}
@@ -3355,16 +3341,27 @@ public void testGetSchemas_createsDetachedLinkedSpan() throws Exception {
33553341
Assertions.assertNotNull(workerThread, "Worker thread should not be null");
33563342
workerThread.join();
33573343

3358-
boolean found =
3359-
otelTesting.getSpans().stream()
3360-
.anyMatch(
3361-
span ->
3362-
span.getName().equals("BigQueryDatabaseMetaData.getSchemas.background")
3363-
&& span.getLinks().stream()
3364-
.anyMatch(link -> link.getSpanContext().isValid()));
3365-
assertTrue(found);
3344+
assertSpanLinkedToParent("BigQueryDatabaseMetaData.getSchemas.background", parentSpan);
33663345
} finally {
33673346
parentSpan.end();
33683347
}
33693348
}
3349+
3350+
private void assertSpanLinkedToParent(String spanName, Span parentSpan) {
3351+
boolean found =
3352+
otelTesting.getSpans().stream()
3353+
.anyMatch(
3354+
span ->
3355+
span.getName().equals(spanName)
3356+
&& span.getLinks().stream()
3357+
.anyMatch(
3358+
link ->
3359+
link.getSpanContext()
3360+
.getTraceId()
3361+
.equals(parentSpan.getSpanContext().getTraceId())
3362+
&& link.getSpanContext()
3363+
.getSpanId()
3364+
.equals(parentSpan.getSpanContext().getSpanId())));
3365+
assertTrue(found, "Span " + spanName + " not found or not linked to parent");
3366+
}
33703367
}

0 commit comments

Comments
 (0)