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

Problem inserting into a REPEATED RECORD column #68

Closed
jussikuosa opened this issue Oct 28, 2022 · 2 comments · Fixed by #74
Closed

Problem inserting into a REPEATED RECORD column #68

jussikuosa opened this issue Oct 28, 2022 · 2 comments · Fixed by #74

Comments

@jussikuosa
Copy link

Hi, I'm in a project that uses a metadata column of type repeated record:

bq show project:dataset.table
...
+- metadata: record (repeated)
 |  |- name: string (required)
 |  |- value: string

I've been able to create our table with bigquery-emulator but I'm not able to get the values properly from the metadata column.

./bigquery-emulator --project=test_project --log-level=debug
# ...
bq --api http://0.0.0.0:9050 mk --project_id=test_project --dataset test_dataset 

bq --api http://0.0.0.0:9050 mk --project_id=test_project --table test_project:test_dataset.test_metadata ./metadata_schema.json
bq --api http://0.0.0.0:9050 show --project_id=test_project --schema test_project:test_dataset.test_metadata
# [{"fields":[{"mode":"REQUIRED","name":"name","type":"STRING"},{"mode":"NULLABLE","name":"value","type":"STRING"}],"mode":"REPEATED","name":"metadata","type":"RECORD"}]
bq --api http://0.0.0.0:9050 query --project_id=test_project 'INSERT INTO test_dataset.test_metadata (metadata) VALUES (ARRAY[ STRUCT("FOO","BAR") ])'
bq --api http://0.0.0.0:9050 query --project_id=test_project 'SELECT * FROM test_dataset.test_metadata'
# +--------------+
# |  metadata    |
# +--------------+
# | [{"":"BAR"}] |
# +--------------+

The schema file is as follows:

[
  {
    "fields": [
      {
        "mode": "REQUIRED",
        "name": "name",
        "type": "STRING"
      },
      {
        "mode": "NULLABLE",
        "name": "value",
        "type": "STRING"
      }
    ],
    "mode": "REPEATED",
    "name": "metadata",
    "type": "RECORD"
  }
]

and when I query our test table, I get:

+-----------+-----------------------------------------+
|  service  |        metadata                         |
+-----------+-----------------------------------------+
| XxxxXxxx  | [{"name":"NNNNNNN","value":"VVVVVVV1"}] |
| XxxxXxxx  | [{"name":"NNNNNNN","value":"VVVVVVV2"}] |
+-----------+-----------------------------------------+

Am I doing the insert correctly and can I achieve the same result as google bigquery?

@goccy
Copy link
Owner

goccy commented Nov 3, 2022

Thank you for your report !
I fixed this problem with v0.1.21 . Please confirm it 😄

@jussikuosa
Copy link
Author

Thank you @goccy! The simple test passes now perfectly. I'll try to finish the service integration in docker-compose next 👍

...
bq --api http://0.0.0.0:9050 query --project_id=test_project 'INSERT INTO test_dataset.test_metadata (mmetadata) VALUES (ARRAY[ STRUCT("FOO","BAR") ])'

bq --api http://0.0.0.0:9050 query --project_id=test_project 'SELECT * FROM test_dataset.test_metadata'
# +--------------------------------+
# |           metadata             |
# +--------------------------------+
# | [{"name":"FOO","value":"BAR"}] |
# +--------------------------------+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants