Title: schema built when creating a view in bigquery · Issue #1701 · googleapis/google-cloud-python · GitHub
Open Graph Title: schema built when creating a view in bigquery · Issue #1701 · googleapis/google-cloud-python
X Title: schema built when creating a view in bigquery · Issue #1701 · googleapis/google-cloud-python
Description: Calling create on a table with view_query set fails, as _build_resource sets the schema. Running new_table = dataset.table('test_view') table.view_query = query_string new_table.create() gives the following error: BadRequest: 400 { "erro...
Open Graph Description: Calling create on a table with view_query set fails, as _build_resource sets the schema. Running new_table = dataset.table('test_view') table.view_query = query_string new_table.create() gives the ...
X Description: Calling create on a table with view_query set fails, as _build_resource sets the schema. Running new_table = dataset.table('test_view') table.view_query = query_string new_table.create() gi...
Opengraph URL: https://github.com/googleapis/google-cloud-python/issues/1701
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"schema built when creating a view in bigquery","articleBody":"Calling create on a table with view_query set fails, as _build_resource sets the schema. Running\n\n``` python\nnew_table = dataset.table('test_view')\ntable.view_query = query_string\nnew_table.create()\n```\n\ngives the following error:\n\n```\nBadRequest: 400 {\n \"error\": {\n \"errors\": [\n {\n \"domain\": \"global\",\n \"reason\": \"invalid\",\n \"message\": \"Schema field shouldn't be used as input with a view\"\n }\n ],\n \"code\": 400,\n \"message\": \"Schema field shouldn't be used as input with a view\"\n }\n}\n```\n\nOne fix that works is only setting `schema` if `view_query` is `None` in `_build_resource` in [`gcloud/bigquery/table.py`](https://github.com/GoogleCloudPlatform/gcloud-python/blob/188515f192e3823ce21a47df2d4742995d08f109/gcloud/bigquery/table.py#L397), e.g.:\n\n``` python\n def _build_resource(self):\n \"\"\"Generate a resource for ``create`` or ``update``.\"\"\"\n resource = {\n 'tableReference': {\n 'projectId': self._dataset.project,\n 'datasetId': self._dataset.name,\n 'tableId': self.name},\n }\n if self.description is not None:\n resource['description'] = self.description\n\n if self.expires is not None:\n value = _millis_from_datetime(self.expires)\n resource['expirationTime'] = value\n\n if self.friendly_name is not None:\n resource['friendlyName'] = self.friendly_name\n\n if self.location is not None:\n resource['location'] = self.location\n\n if self.view_query is not None:\n view = resource['view'] = {}\n view['query'] = self.view_query\n else:\n resource['schema'] = {'fields': _build_schema_resource(self._schema)}\n\n return resource\n```\n","author":{"url":"https://github.com/jeremyjamesmitchell","@type":"Person","name":"jeremyjamesmitchell"},"datePublished":"2016-04-07T15:13:55.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1701/google-cloud-python/issues/1701"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:fca640fd-8c7e-73ca-e789-870d617cf2a7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D0F6:3733D4:FBD5F:157C6B:6A4D2FAF |
| html-safe-nonce | ff37ef3a921471dab9d3ab922b629496f3d6b3af6339586bdff2aeb7e5765b66 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMEY2OjM3MzNENDpGQkQ1RjoxNTdDNkI6NkE0RDJGQUYiLCJ2aXNpdG9yX2lkIjoiNDgwNDg5NDY0NzI4MDAyMTQyMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 273053ad97fbd0cd5c152a03d9c20aca55eec8f7cdbc0d7f48175ee9f0bb7b48 |
| hovercard-subject-tag | issue:146655224 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/googleapis/google-cloud-python/1701/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a750546cd3309a6c3441d75ca3af0e25f823634049ad25056a04b7e34d43f2c1/googleapis/google-cloud-python/issues/1701 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a750546cd3309a6c3441d75ca3af0e25f823634049ad25056a04b7e34d43f2c1/googleapis/google-cloud-python/issues/1701 |
| og:image:alt | Calling create on a table with view_query set fails, as _build_resource sets the schema. Running new_table = dataset.table('test_view') table.view_query = query_string new_table.create() gives the ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jeremyjamesmitchell |
| hostname | github.com |
| expected-hostname | github.com |
| None | 92571a8944142227b7e19cd10918b1ddd06e5066c1ad5bc7e4769cf6140a87e6 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/google-cloud-python git https://github.com/googleapis/google-cloud-python.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 16316451 |
| octolytics-dimension-repository_nwo | googleapis/google-cloud-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 16316451 |
| octolytics-dimension-repository_network_root_nwo | googleapis/google-cloud-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 93f17a978ee60bc4668e1d7b90e6bd2d622261fd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width