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

Can you help me the JAVA API to update the table rows using google cloud bigquery #413

Description

@shrgupta28

Hi Team,

We are doing the POC with the new Bigquery API https://github.com/googleapis/java-bigquery

Can you please help me how I can update the table rows using this.

Env:
Java 1.8
Google Cloud Bigquery

Thanks,
Shruti

Activity

  1. pmakani commented on Jun 4, 2020

    @pmakani
    Contributor

    @shrgupta28 samples on README please check on that repo.

  2. shrgupta28 commented on Jun 4, 2020

    @shrgupta28
    Author

    @pmakani There is no sample for updating the table content.
    There are samples to update the dataset structure and table structure.
    I am looking for the code using which I can perform update operation on the table data, like updating the record.
    I basically need to execute the below operation using the API:
    update dataset.Student set Stud_Name = "NewName11", Stud_Class="II" where Stud_Id = 2002

    can you help me with this, please.

    Thanks.

  3. stephaniewang526 commented on Jun 4, 2020

    @stephaniewang526
    Contributor
  4. shrgupta28 commented on Jun 7, 2020

    @shrgupta28
    Author

    Hi @stephaniewang526 , Any update on how we can perform the Update Operation using the cloud bigquery API.
    We are in the final development phase, and this is blocking us. I request your help. Thanks.

  5. stephaniewang526 commented on Jun 8, 2020

    @stephaniewang526
    Contributor

    PTAL sample linked above.

  6. added a commit that references this issue on Jun 8, 2020
    3902ba1
  7. shrgupta28 commented on Jun 9, 2020

    @shrgupta28
    Author

    Hi @stephaniewang526
    The sample UpdateTableDML.java that you provided updates the data in the table..
    But is there an API that tells me the number of rows updated in the DB..

    While using the BigQuery V2 API, I was able to trace the number of rows updated using the queryResponse.getNumDmlAffectedRows()

    Can you tell me the similar API here.. We need to know the number of Affected Rows.

    Also, in case of any errors, the BigQuery V2 API used to return the queryResponse.getErrors()
    Can you help with this as well.

    Thanks.

  8. reopened this on Jun 9, 2020
  9. self-assigned this
    on Jun 9, 2020
  10. added
    type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.
    and removed
    triage meI really want to be triaged.
    on Jun 9, 2020
  11. removed their assignment
    on Jun 9, 2020
  12. shrgupta28 commented on Jun 9, 2020

    @shrgupta28
    Author

    Hi @stephaniewang526 @pmakani Can you help me with the requirement stated above.

  13. added a commit that references this issue on Jun 9, 2020
  14. pmakani commented on Jun 10, 2020

    @pmakani
    Contributor

    @shrgupta28 when you are executing query job, it's return QueryStatistics, then you will able to get
    getNumDmlAffectedRows(), please take a look below example.

    JobStatistics.QueryStatistics statistics = job.getStatistics();
    long numDmlAffectedRows = statistics.getNumDmlAffectedRows();
  15. shrgupta28 commented on Jun 10, 2020

    @shrgupta28
    Author

    @pmakani PFA the sample I am using to update the DML. I am not able to work with this API here in my code. Can you please help me.. Thanks.
    SampleUpdateDML.txt

  16. pmakani commented on Jun 10, 2020

    @pmakani
    Contributor

    @shrgupta28 please use this example.

        String tableName = "test_table";
        String dataset = "test_dataset";
        String query = "SELECT TimestampField, StringField, BooleanField FROM test_dataset.test_table";
        TableId destinationTable = TableId.of(dataset, tableName);
        QueryJobConfiguration configuration =
            QueryJobConfiguration.newBuilder(query)
                .setDefaultDataset(DatasetId.of(DATASET))
                .setDestinationTable(destinationTable)
                .build();
        Job job = bigquery.create(JobInfo.of(configuration));
        JobStatistics.QueryStatistics statistics = job.getStatistics();
        long numDmlAffectedRows = statistics.getNumDmlAffectedRows();
  17. shrgupta28 commented on Jun 10, 2020

    @shrgupta28
    Author

    @pmakani The code snippet you have shared above is for Select statement. I am trying to perform the update operation. I am trying to do something similar as you said. Please check the below code - Does this seem okay? Still, I am not getting the statistics.getNumDmlAffectedRows(); It is null every time.

    String dmlQuery = String.format("update dataset.Student  set Stud_Name = \"Nalini\", Stud_Class=\"II\" where Stud_Id = 300", datasetName, tableName);
    
    			QueryJobConfiguration configuration =
    					QueryJobConfiguration.newBuilder(dmlQuery)
    					.build();
    			Job job = bigquery.create(JobInfo.of(configuration));
    			JobStatistics.QueryStatistics statistics = job.getStatistics();
    			TableResult result = bigquery.query(configuration);
    			System.out.println(statistics.getNumDmlAffectedRows().intValue());
    
  18. shrgupta28 commented on Jun 11, 2020

    @shrgupta28
    Author

    Hi, @pmakani Could you please help with this. This is at a high priority from our development perspective.

  19. stephaniewang526 commented on Jun 11, 2020

    @stephaniewang526
    Contributor

    Please use Github to raise bug report or feature request only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

api: bigqueryIssues related to the googleapis/java-bigquery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions