0

I want to access the bitcoin bigquery dataset and convert it to dataframe in format.

timestamp, transaction_id, input_addr

when i write the query for it referring to the docs

from google.cloud import bigquery

# Construct a BigQuery client object.
client = bigquery.Client()


query1 = '''SELECT
  transaction_id,
  timestamp,
  inputs.input_pubkey_base58
FROM bigquery-public-data.bitcoin_blockchain.transactions
WHERE timestamp < 1588879614 AND timestamp > 1572480000
         '''

dataframe = (
     client.query(query1)
    .result()
    .to_dataframe(bqstorage_client=bqstorageclient)
)
print(dataframe.head())

i get below error. how to resolve it.

---------------------------------------------------------------------------
BadRequest                                Traceback (most recent call last)
<ipython-input-20-2ca06d198e09> in <module>()
      1 dataframe = (
----> 2      client.query(query1)
      3     .result()
      4     .to_dataframe(bqstorage_client=bqstorageclient)
      5 )

BadRequest: 400 Cannot access field input_pubkey_base58 on a value with type ARRAY<STRUCT<input_script_bytes BYTES, input_script_string STRING, input_script_string_error STRING, ...>> at [4:10]

1 Answer 1

1

Cannot access field input_pubkey_base58 on a value with type ARRAY> at [4:10]

You should correct your select statement by unnesting first array(repeated field) as below

SELECT
  transaction_id,
  TIMESTAMP,
  input.input_pubkey_base58
FROM bigquery-public-data.bitcoin_blockchain.transactions,
UNNEST(inputs) input
WHERE TIMESTAMP < 1588879614 AND TIMESTAMP > 1572480000    
Sign up to request clarification or add additional context in comments.

6 Comments

ContextualVersionConflict: (google-api-core 1.6.0 (/opt/conda/lib/python3.6/site-packages), Requirement.parse('google-api-core[grpc]<2.0.0dev,>=1.14.0'), {'google-cloud-bigquery-storage'})
Empty DataFrame Columns: [transaction_id, TIMESTAMP, input_pubkey_base58] Index: []
i got an empty dataframe. with column heading but no rows
have you tried to run just this exact query in BQ UI? please do
Hi i tried it Query complete (0.5 sec elapsed, 48.1 GB processed) .This query returned no results.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.