GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — LoadStatistics stats = job.getStatistics() yields java.lang.ClassCastException · Issue #2652 · googleapis/google-cloud-java

LoadStatistics stats = job.getStatistics() yields java.lang.ClassCastException #2652

New issue
Copy link
New issue
Copy link
Closed
Closed
LoadStatistics stats = job.getStatistics() yields java.lang.ClassCastException#2652
Copy link
Assignees
kansuke231

Description

@kansuke231
kansuke231
opened on Nov 21, 2017
Issue body actions

Hi all,

I am trying to insert some json data into a BigQuery table with Spark. Here is a snippet of code that is supposed to be doing the insertion:

        ...
        TableId tableId = TableId.of(dataset_id, table_id);
        BigQuery bigQuery = createAuthorizedClient(credential_json, project_id);

        WriteChannelConfiguration writeChannelConfiguration =
                WriteChannelConfiguration.newBuilder(tableId)
                        .setFormatOptions(FormatOptions.json())
                        .build();
        TableDataWriteChannel writer = bigQuery.writer(writeChannelConfiguration);

        ArrayList<StatementResult> al = new ArrayList<StatementResult>();

        String jsonString = "";
        long count = 0;

        // concatenate all rows into one string.
        for (Iterator<String> iter = stringIterator; iter.hasNext();) {
            count++;
            jsonString += "\n" + iter.next();
        }

        try {

            if (count == 0) {
                StatementResult sr = new StatementResult("", 0,0);
                al.add(sr);
                return al.iterator();
            }

            writer = bigQuery.writer(writeChannelConfiguration);
            writer.write(ByteBuffer.wrap(jsonString.getBytes(Charsets.UTF_8)));

            writer.close();
            // Get load job
            Job job = writer.getJob();

            job = job.waitFor();

            LoadStatistics stats = job.getStatistics();
            long success =  stats.getOutputRows();

            StatementResult sr = new StatementResult(null, success,count - success);
            al.add(sr);


        }  catch (IOException | InterruptedException | TimeoutException e) {

            StatementResult sr = new StatementResult(e.getMessage(), 1,1);
            al.add(sr);


        } finally {
            writer.close();
        }
        return al.iterator();

However, the lineLoadStatistics stats = job.getStatistics(); yields an exception of java.lang.ClassCastException: shaded.guava.cloud.bigquery.JobStatistics$CopyStatistics cannot be cast to shaded.guava.cloud.bigquery.JobStatistics$LoadStatistics. The code structure is pretty much the same as examples I found online, so I don't know what's wrong with this. Any help would be highly appreciated. Thanks!

Activity

  1. kansuke231 commented on Nov 26, 2017

    @kansuke231
    kansuke231
    on Nov 26, 2017
    Author
    More actions

    I have figured out the root cause. The data I was trying to write into BigQuery comes from Google Spreadsheet that has 4 columns, namely Column1 ~ Column4. But the BigQuery table has only 3 columns. After getting rid of the last column in the incoming DataFrame, things work as expected.
    I close this issue as I found the solution.

  2. kansuke231
    closed this as completedon Nov 26, 2017
  3. JustinBeckwith
    assigned
    kansuke231
    on Feb 1, 2021
  4. chingor13
    added a commit that references this issue on Feb 20, 2026

    chore: Update generation configuration at Sat Sep 21 02:21:33 UTC 2024 (

    482af85
  5. chingor13
    added 3 commits that reference this issue on Mar 24, 2026

    deps: update opentelemetry-java monorepo to v1.37.0 (#2652)

    708cf7f

    chore(main): release 2.39.0 (#2594)

    3ff4744

    chore: Update generation configuration at Wed Jul 31 02:02:53 UTC 2024 (

    a01a71d
  6. meltsufin
    added 2 commits that reference this issue on Apr 29, 2026

    fix: Lower the Subscriber protocol version to disable the streaming p…

    ca99c2a

    fix: Lower the Subscriber protocol version to disable the streaming p…

    a5a96f8
  7. rahul2393
    added 2 commits that reference this issue on May 21, 2026

    chore(main): release 2.64.0 (googleapis#2652)

    d28588a

    feat: idle channel eviction (googleapis#2651)

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

Metadata

Metadata

Assignees

  • @kansuke231
    kansuke231

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.