{"id":19561359,"url":"https://github.com/m-mizutani/bqs","last_synced_at":"2025-09-06T11:44:42.714Z","repository":{"id":220754335,"uuid":"751617276","full_name":"m-mizutani/bqs","owner":"m-mizutani","description":"BigQuery Schema utility in Go","archived":false,"fork":false,"pushed_at":"2025-07-13T00:03:18.000Z","size":104,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-01T03:37:44.088Z","etag":null,"topics":["bigquery","bigquery-schema","go"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/m-mizutani.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-02T00:41:32.000Z","updated_at":"2025-07-13T00:02:03.000Z","dependencies_parsed_at":"2024-02-20T04:21:51.143Z","dependency_job_id":"0e7dd719-89d1-4c41-afeb-dfffb5a67181","html_url":"https://github.com/m-mizutani/bqs","commit_stats":null,"previous_names":["m-mizutani/bqs"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/m-mizutani/bqs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-mizutani%2Fbqs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-mizutani%2Fbqs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-mizutani%2Fbqs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-mizutani%2Fbqs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/m-mizutani","download_url":"https://codeload.github.com/m-mizutani/bqs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/m-mizutani%2Fbqs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273899057,"owners_count":25187733,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-06T02:00:13.247Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bigquery","bigquery-schema","go"],"created_at":"2024-11-11T05:11:12.126Z","updated_at":"2025-09-06T11:44:42.660Z","avatar_url":"https://github.com/m-mizutani.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# bqs\n[![Go Reference](https://pkg.go.dev/badge/github.com/m-mizutani/bqs.svg)](https://pkg.go.dev/github.com/m-mizutani/bqs) [![test](https://github.com/m-mizutani/bqs/actions/workflows/test.yml/badge.svg)](https://github.com/m-mizutani/bqs/actions/workflows/test.yml) [![gosec](https://github.com/m-mizutani/bqs/actions/workflows/gosec.yml/badge.svg)](https://github.com/m-mizutani/bqs/actions/workflows/gosec.yml) [![trivy](https://github.com/m-mizutani/bqs/actions/workflows/trivy.yml/badge.svg)](https://github.com/m-mizutani/bqs/actions/workflows/trivy.yml) [![lint](https://github.com/m-mizutani/bqs/actions/workflows/lint.yml/badge.svg)](https://github.com/m-mizutani/bqs/actions/workflows/lint.yml)\n\nUtility for inferring, merging and comparing BigQuery schema in Go. BigQuery provides a feature to infer schema, such as [bigquery.InferSchema](https://pkg.go.dev/cloud.google.com/go/bigquery#InferSchema) and [schema auto detection](https://cloud.google.com/bigquery/docs/schema-detect). However, `bigquery.InferSchema` does not support nested struct and map. schema auto detection is not available in the Go client library. This library provides a way to infer BigQuery schema from nested Go struct and map.\n\n## Features\n\n- [x] Infer BigQuery schema from **nested** Go struct and map\n- [x] Merge BigQuery schema\n- [x] Compare BigQuery schema\n\n## Example\n\n```go\n// Row is a map[string]any, implemented as bigquery.ValueSaver\nrows := []Row{\n    {\n        \"CreatedAt\": time.Now(),\n        \"Name\":      \"Alice\",\n        \"Preferences\": map[string]any{\n            \"Color\": \"Red\",\n        },\n    },\n    {\n        \"CreatedAt\": time.Now(),\n        \"Name\":      \"Bob\",\n        \"Age\":       30,\n    },\n}\n\nvar mergedSchema bigquery.Schema\nfor _, row := range rows {\n    // If you use bigquery.InferSchema, it will fail to infer the schema of nested struct.\n    schema, err := bqs.Infer(row)\n    if err != nil {\n        return err\n    }\n\n    // Merge the schema of each row\n    mergedSchema, err = bqs.Merge(mergedSchema, schema)\n    if err != nil {\n        return err\n    }\n}\n\n// Create a new table with the schema that is combined from all rows\nnewMeta := \u0026bigquery.TableMetadata{Schema: mergedSchema}\nif err := table.Create(ctx, newMeta); err != nil {\n    return err\n}\n\n// Insert all rows to the created table\nif err := table.Inserter().Put(ctx, rows); err != nil {\n    return err\n}\n```\n\nThis will create a table with the following schema and insert the rows.\n\n| CreatedAt                  | Name  | Age | Preferences.Color |\n|----------------------------|-------|-------|-------------------|\n| 2024-02-04 03:29:55.504942 | Alice | *null*    | Red               |\n| 2024-02-04 03:29:55.504943 | Bob   | 30  | *null*                 |\n\n## CLI\n\n### Install\n\n```bash\ngo install github.com/m-mizutani/bqs/cmd/bqs@latest\n```\n\n### Example\n\n```bash\n$ cat test.jsonl\n{\"color\":\"blue\", \"number\":5, \"property\":{\"age\": 18}}\n{\"color\":\"green\", \"number\":1, \"property\":{\"name\":\"Alice\"}}\n$ bqs infer test.jsonl\n[\n {\n  \"name\": \"color\",\n  \"type\": \"STRING\"\n },\n {\n  \"name\": \"number\",\n  \"type\": \"FLOAT\"\n },\n {\n  \"fields\": [\n   {\n    \"name\": \"name\",\n    \"type\": \"STRING\"\n   },\n   {\n    \"name\": \"age\",\n    \"type\": \"FLOAT\"\n   }\n  ],\n  \"name\": \"property\",\n  \"type\": \"RECORD\"\n }\n]\n```\n\n## License\n\nApache License 2.0\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm-mizutani%2Fbqs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fm-mizutani%2Fbqs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fm-mizutani%2Fbqs/lists"}