-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
feat(bigquery): add helper classes for cloud-client testing (1/3) #10034
feat(bigquery): add helper classes for cloud-client testing (1/3) #10034
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
The pull request introduces helper classes for cloud-client testing in BigQuery, specifically focusing on creating and deleting datasets, tables, and views. The code includes the necessary classes and integration tests to validate the functionality. Overall, the code is well-structured and addresses the requirements outlined in the pull request description. However, there are a few areas that could be improved for better clarity and maintainability.
Summary of Findings
- TODO comments: The code contains
TODO
comments that should be addressed before merging. These comments indicate areas where the developer needs to replace placeholder values with actual values. - Redundant cleanup in tearDown methods: In the
tearDown
methods of the integration tests, the dataset deletion is performed even if the table deletion fails. This could lead to unnecessary operations and potential errors. It's better to ensure that table deletion is successful before attempting to delete the dataset. - Inconsistent naming: In
CreateTableIT.java
, the schema fields are namedstringField
andbooleanField
, while inCreateViewIT.java
they are namedtimestampField
,stringField
, andbooleanField
. This inconsistency should be addressed for better readability and maintainability.
Merge Readiness
The pull request is almost ready for merging. However, the TODO
comments should be addressed, and the redundant cleanup in the tearDown
methods should be fixed. Additionally, the naming inconsistency in the schema fields should be resolved. Once these issues are addressed, the pull request can be merged. I am unable to approve this pull request, and recommend that others review and approve this code before merging.
bigquery/cloud-client/snippets/src/main/java/com/example/bigquery/CreateDataset.java
Show resolved
Hide resolved
bigquery/cloud-client/snippets/src/main/java/com/example/bigquery/CreateTable.java
Show resolved
Hide resolved
bigquery/cloud-client/snippets/src/main/java/com/example/bigquery/CreateView.java
Show resolved
Hide resolved
bigquery/cloud-client/snippets/src/main/java/com/example/bigquery/DeleteDataset.java
Show resolved
Hide resolved
bigquery/cloud-client/snippets/src/main/java/com/example/bigquery/DeleteTable.java
Show resolved
Hide resolved
DeleteTable.deleteTable(GOOGLE_CLOUD_PROJECT, datasetName, tableName); | ||
DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, datasetName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a try-catch block around the DeleteTable.deleteTable
call to handle potential exceptions during table deletion. If table deletion fails, log the error and proceed with dataset deletion. This ensures that the dataset is deleted even if the table deletion fails.
DeleteTable.deleteTable(GOOGLE_CLOUD_PROJECT, datasetName, tableName); | |
DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, datasetName); | |
try { | |
DeleteTable.deleteTable(GOOGLE_CLOUD_PROJECT, datasetName, tableName); | |
} catch (Exception e) { | |
log.log(Level.SEVERE, "Error deleting table: " + e.getMessage(), e); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. I would also put the deletion of the table inside of a try-catch block.
// Clean up. | ||
DeleteTable.deleteTable(GOOGLE_CLOUD_PROJECT, datasetName, viewName); | ||
DeleteTable.deleteTable(GOOGLE_CLOUD_PROJECT, datasetName, tableName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a try-catch block around the DeleteTable.deleteTable
calls to handle potential exceptions during table deletion. If table deletion fails, log the error and proceed with dataset deletion. This ensures that the dataset is deleted even if the table deletion fails.
try {
DeleteTable.deleteTable(GOOGLE_CLOUD_PROJECT, datasetName, viewName);
} catch (Exception e) {
log.log(Level.SEVERE, "Error deleting view: " + e.getMessage(), e);
}
try {
DeleteTable.deleteTable(GOOGLE_CLOUD_PROJECT, datasetName, tableName);
} catch (Exception e) {
log.log(Level.SEVERE, "Error deleting table: " + e.getMessage(), e);
}
Field.of("timestampField", StandardSQLTypeName.TIMESTAMP), | ||
Field.of("stringField", StandardSQLTypeName.STRING), | ||
Field.of("booleanField", StandardSQLTypeName.BOOL)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In CreateTableIT.java
, the schema fields are named stringField
and booleanField
, while here they are named timestampField
, stringField
, and booleanField
. This inconsistency should be addressed for better readability and maintainability. Consider using consistent naming conventions across all test classes.
Schema schema =
Schema.of(
Field.of("stringField", StandardSQLTypeName.STRING),
Field.of("booleanField", StandardSQLTypeName.BOOL));
|
||
package com.example.bigquery; | ||
|
||
import com.google.cloud.bigquery.BigQuery; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: insert region tags. Make sure that you use the same region tags as used in the same sample (create dataset) in other languages. It looks like Go uses bigquery_create_dataset
.
See https://googlecloudplatform.github.io/samples-style-guide/#region-tags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now, those samples (with region tags) are in a different repo, but I need the classes to test the samples in the list. I'm planning to migrate the region tags and use the samples in this PR and repo once the PRs 10034, 10035 and 10036 are merged as that migration is not part of the current scope.
Is this a good way to go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that makes sense. I assume that there is a work item or bug that tracks adding region tags to these files?
bigquery/cloud-client/snippets/src/main/java/com/example/bigquery/CreateDataset.java
Show resolved
Hide resolved
@After | ||
public void tearDown() { | ||
// Clean up | ||
DeleteTable.deleteTable(GOOGLE_CLOUD_PROJECT, datasetName, tableName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Use the BQ client to delete table and dataset, not the corresponding samples.
Although it is much easier to use the samples, unfortunately using the samples for clean up has some unwanted potential side effects. Specifically, if one of these samples start failing, then that will cause THIS test to start failing as well.
@After | ||
public void tearDown() { | ||
// Clean up. | ||
DeleteTable.deleteTable(GOOGLE_CLOUD_PROJECT, datasetName, viewName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment about tearDown()
.
CreateDataset.createDataset(GOOGLE_CLOUD_PROJECT, datasetName); | ||
|
||
// Create temporary table. | ||
tableName = "table_test_" + UUID.randomUUID().toString().substring(0, 8); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add a preface like bigquery_
before the "table_test_"
string.
These strings are crucial for identifying failing tests in the logs. We have multiple products that involve entities called "tables" and "datasets." When I'm scanning through the logs to see why a test failed, it's helpful if the name of the resource that caused the failure helps me pinpoint which service or set of tests the failure originates from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alarconesparza as discussed internally, we could use a prefixer like Python does:
conftest.py#L22
Do we have an equivalent to the test_utils
on the Java testing system? The prefix on Python looks similar to java-docs-samples-bigquery-cloud-client
plus a timestamp.
|
||
// Create temporary dataset. | ||
datasetName = RemoteBigQueryHelper.generateDatasetName(); | ||
CreateDataset.createDataset(GOOGLE_CLOUD_PROJECT, datasetName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same principle applies here as my previous comment about using samples for tearDown()
.
Using samples in test setUp()
and tearDown()
can cause a cascading set of test failures.
|
||
// Create temporary dataset. | ||
datasetName = RemoteBigQueryHelper.generateDatasetName(); | ||
CreateDataset.createDataset(GOOGLE_CLOUD_PROJECT, datasetName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above about using samples in setUp()
and tearDown()
.
|
||
package com.example.bigquery; | ||
|
||
import com.google.cloud.bigquery.BigQuery; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, that makes sense. I assume that there is a work item or bug that tracks adding region tags to these files?
DeleteTable.deleteTable(GOOGLE_CLOUD_PROJECT, datasetName, tableName); | ||
DeleteDataset.deleteDataset(GOOGLE_CLOUD_PROJECT, datasetName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1. I would also put the deletion of the table inside of a try-catch block.
Description
Part of internal b/394478489
First part of bigquery cloud-client (1/3).
(#10034, #10035, #10036)
Create[Dataset,Table,View] and Delete[Dataset,Table] are required for testing the following samples (samples will be added in part 2 and 3).
Samples
Checklist
pom.xml
parent set to latestshared-configuration
mvn clean verify
requiredmvn -P lint checkstyle:check
requiredmvn -P lint clean compile pmd:cpd-check spotbugs:check
advisory only