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 — Schema needed when uploading AVRO file from local filesystem, but not from GCS. · Issue #3416 · googleapis/google-cloud-python

Schema needed when uploading AVRO file from local filesystem, but not from GCS. #3416

New issue
Copy link
New issue
Copy link
Closed
Closed
Schema needed when uploading AVRO file from local filesystem, but not from GCS.#3416
Copy link
Assignees
tseaver
Labels
api: bigqueryIssues related to the BigQuery API.backend

Description

@tweeter0830
tweeter0830
opened on May 15, 2017
Issue body actions

I'm trying to upload an avro file from my local filesystem using the following code:

  random_table_name = make_random_string()
  table = dataset_.table(name=random_table_name)

  with open(schema_filepath, 'rb') as file_:
    schema = avro.schema.parse(file_.read())

  with tempfile.NamedTemporaryFile() as temp_file:
    with open(temp_file.name, 'wb') as file_:
      writer = avro.datafile.DataFileWriter(
          file_, avro.io.DatumWriter(), schema)
      writer.close()

    with open(temp_file.name, 'rb') as file_:
      job = table.upload_from_file(file_, source_format='AVRO')
    wait_for_job_to_finish(job)

I get the following error:

google.cloud.exceptions.BadRequest: 400 Empty schema specified for the load job. Please specify a schema that describes the data being loaded. (https://www.googleapis.com/upload/bigquery/v2/projects/aircraft-audio-classification/jobs?uploadType=multipart)

I don't need to specify a schema when using the web api or when uploading a file from GCS.

Activity

  1. tseaver
    added
    api: bigqueryIssues related to the BigQuery API.
    backend
    on May 15, 2017
  2. tweeter0830 commented on May 15, 2017

    @tweeter0830
    tweeter0830
    on May 15, 2017
    Author
    More actions

    For reference, the following code works when pointed at a file on GCS.

      job = client_.load_table_from_storage(
          'load-from-storage-job-' + destination_table.name,
          destination_table,
          gcs_path,
      )
      job.source_format = 'AVRO'
      job.begin()
      wait_for_job_to_finish(job)
  3. tseaver commented on May 15, 2017

    @tseaver
    tseaver
    on May 15, 2017
    Contributor
    More actions

    I realize that AVRO is supposed to be self-describing, but that error message is being generated on the back-end. The only thing I can see that we might be able to fix on the client side is to omit sending the schema=[] field at all if the schema isn't set. However, the docs for client.load indicate that schema:

    The schema can be omitted if the destination table already exists, or if you're loading data from Google Cloud Datastore.

  4. tweeter0830 commented on May 15, 2017

    @tweeter0830
    tweeter0830
    on May 15, 2017
    Author
    More actions

    Interesting, that is a weird restriction. It certainly makes my workflow harder. I need to bounce the file to some temporary location in gcs and then upload from there. At the very least, this should be in the documentation for upload_from_file.

  5. tseaver commented on May 15, 2017

    @tseaver
    tseaver
    on May 15, 2017
    Contributor
    More actions

    @tweeter0830 Could you apply the following patch and let me know if it works for you?

    diff --git a/bigquery/google/cloud/bigquery/table.py b/bigquery/google/cloud/big
    index 3b0346f..c599f5f 100644
    --- a/bigquery/google/cloud/bigquery/table.py
    +++ b/bigquery/google/cloud/bigquery/table.py
    @@ -918,9 +918,6 @@ class Table(object):
                 'configuration': {
                     'load': {
                         'sourceFormat': source_format,
    -                    'schema': {
    -                        'fields': _build_schema_resource(self._schema),
    -                    },
                         'destinationTable': {
                             'projectId': self._dataset.project,
                             'datasetId': self._dataset.name,
    @@ -930,6 +927,10 @@ class Table(object):
                 }
             }
     
    +        if len(self._schema) > 0:
    +            load_config = metadata['configuration']['load']
    +            load_config['schema'] = _build_schema_resource(self._schema)
    +
             _configure_job_metadata(metadata, allow_jagged_rows,
                                     allow_quoted_newlines, create_disposition,
                                     encoding, field_delimiter,

    If so, I will add tests for this case and create a PR.

  6. tweeter0830 commented on May 15, 2017

    @tweeter0830
    tweeter0830
    on May 15, 2017
    Author
    More actions

    No luck. Got the same error.

  7. tseaver commented on May 16, 2017

    @tseaver
    tseaver
    on May 16, 2017
    Contributor
    More actions

    @lukesneeringer Who is the current back-end contact for BigQuery?

  8. dhermes commented on May 16, 2017

    @dhermes
    dhermes
    on May 16, 2017
    Contributor
    More actions

    @tswast Is DevRel on BigQuery and he's the best

  9. tswast commented on May 16, 2017

    @tswast
    tswast
    on May 16, 2017
    Contributor
    More actions

    I'm looking into this. I'm making some Avro test data for use in integration tests and so I can get a better look at the request google-cloud-bigquery is generating.

  10. tswast
    added a commit that references this issue on May 16, 2017

    Add test to reproduce googleapis#3416.

    dcb05b3
  11. tseaver
    closed this as completedin #3427on May 16, 2017
  12. JustinBeckwith
    assigned
    tseaver
    on Feb 1, 2021
  13. parthea
    added a commit that references this issue on Sep 22, 2023

    chore: move samples from python-docs-sample (#33)

    This issue will close once commit 69c4425 is merged into the 'main' branch.
    69c4425
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @tseaver
    tseaver

Labels

api: bigqueryIssues related to the BigQuery API.backend

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.