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

Is java google cloud bigquery is threadsafe or not ? #2932

Closed
joshnarani9 opened this issue Oct 10, 2023 · 3 comments
Closed

Is java google cloud bigquery is threadsafe or not ? #2932

joshnarani9 opened this issue Oct 10, 2023 · 3 comments
Assignees
Labels
api: bigquery Issues related to the googleapis/java-bigquery API. type: question Request for information or clarification. Not an issue.

Comments

@joshnarani9
Copy link

joshnarani9 commented Oct 10, 2023

please find google cloud bigquery library version.

**<dependency>
	<groupId>com.google.cloud</groupId>
	<artifactId>google-cloud-bigquery</artifactId>
	<version>1.35.0</version>
</dependency>**

Below are the functionalities used with bigquery library connection.

BQUtils.getConnection().insertAll(insertRows);
BQUtils.getConnection().getTable(tableId);

@product-auto-label product-auto-label bot added the api: bigquery Issues related to the googleapis/java-bigquery API. label Oct 10, 2023
@obada-ab obada-ab added the type: question Request for information or clarification. Not an issue. label Oct 12, 2023
@obada-ab obada-ab self-assigned this Oct 12, 2023
@obada-ab
Copy link
Member

obada-ab commented Oct 17, 2023

@joshnarani9 Thanks for posting your question. The version you're using was released in January of 2020; we recommend using a more recent version of the library if possible. If it's not possible to upgrade to v2+, then the latest v1 version (v1.137.x) would be best.

Can you provide some additional information about your use case? A code sample would be great. That will help us answer your question better.

@joshnarani9
Copy link
Author

joshnarani9 commented Oct 18, 2023

Hi @obada-ab , Thanks and please find the below code snippet which is executed by 20 worker threads at the same time. Here we are trying to insert rows data into a table using getTable and insertAll from bigquery library. Please let us know if the connections from this will be thread safe or not.

Set<Map.Entry<String, List<InsertAllRequest.RowToInsert>>> entries = mapData.entrySet();
    entries.forEach(entry -> {
      try {
        TableId tableId = "t";
        ****BQUtils.getConnection().getTable(tableId);****
        InsertAllRequest insertRows =
            InsertAllRequest.newBuilder(tableId).setTable(tableId).setTemplateSuffix(entry.getKey())
                .setIgnoreUnknownValues(true).setSkipInvalidRows(true).setRows(entry.getValue()).build();
        ****InsertAllResponse response = BQUtils.getConnection().insertAll(insertRows);****
      } catch (InterruptedException e) {
        LOGGER.error("applyInsert(): exception:", e);
      }
    });

In the above code snippet, These two functionalities are used with bigquery library called by 20 or more threads at a time.
BQUtils.getConnection().getTable(tableId);
InsertAllResponse response = BQUtils.getConnection().insertAll(insertRows);

@obada-ab
Copy link
Member

@joshnarani9 we only support the latest v2 version of the Java client library. If you are running a business/have a business reason for using an old version of the client library, please let your support POC know about your query so that they can issue an internal support case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the googleapis/java-bigquery API. type: question Request for information or clarification. Not an issue.
Projects
None yet
Development

No branches or pull requests

2 participants