Bigqueryreservation在创建分配时给出400无效参数错误



我得到这个错误时,试图实现BigQuery槽位预约从谷歌云在python解释如下:https://cloud.google.com/python/docs/reference/bigqueryreservation/latest/google.cloud.bigquery_reservation_v1.services.reservation_service.ReservationServiceClient

我也试着运行这个博客中描述的代码:https://medium.com/google-cloud/optimize-bigquery-costs-with-flex-slots-e06ec5e4aa90

据我所知,我使用了正确的方法和参数,在发出请求时出现了错误。当我运行

assign_config = Assignment(job_type='QUERY',
assignee='projects/{}'.format(user_project))
assign = res_api.create_assignment(parent=reservation_id,
assignment=assign_config)

我得到这个错误

InactiveRpcError Traceback(最近一次调用最后一次)/usr/local/lib/python3.7/dist-packages/谷歌/api_core/grpc_helpers.py在error_remapped_callable(*args, **kwargs)中66年试题:——比;返回可调用对象(*args, **kwargs)除了grpc。RpcError为exc:

6 frames/usr/local/lib/python3.7/dist-packages/grpc/_channel.py调用(self, request, timeout, metadata, credentials, wait_for_ready, compression)945 wait_for_ready,压缩)——比;946 return _end_unary_response_blocking(state, call, False, None)947

/usr/地方/lib/python3.7/dist-packages/grpc _channel.py_end_unary_response_blocking(state, call, with_call, deadline)848年:——比;849 raise _InactiveRpcError(state)850

_InactiveRpcError: <_InactiveRpcError of RPC,以:status = StatusCode终止。请求包含一个参数无效的论点!"debug_error_string ={"created";@1650884667.228899135";description"同行ipv4:142.250.141.95:443"file":"src/核心/lib/表面/call.cc"file_line": 903年,"grpc_message":"请求包含无效参数。","grpc_status":3}">

上述异常是导致以下异常的直接原因:

InvalidArgument回溯(最近的调用)in () in ()5)6——比;assign = client。create_assignment(父= res_id赋值= assign_config)

/usr/地方/lib/python3.7/dist-packages/谷歌云/bigquery_reservation_v1/服务/reservation_service/client.py在create_assignment(self, request, parent, assignment, retry)中,超时,元数据)1871 1872 #发送请求→1873 response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) 1874 1875 #完成;返回响应。

/usr/地方/lib/python3.7/dist-packages/谷歌/api_core/gapic_v1/method.py电话在(self, *args, *kwargs)143 kwargs["metadata"] =元数据144——比;145返回wrapped_func(*args, **kwargs)146147

/usr/地方/lib/python3.7/dist-packages/谷歌/api_core/grpc_helpers.py在error_remapped_callable(*args, **kwargs)中返回callable_(*args, **kwargs)除了grpc。RpcError为exc:——比;69 6 .raise_from(exceptions.from_grpc_error(exc), exc)7071 return error_remapped_callable

/usr/local/lib/python3.7/dist-packages/six.py in raise_from(value,from_value)

InvalidArgument: 400请求包含无效参数。

我的完整代码:

!pip install protobuf==3.19.0
!pip install google-api-python-client==2.45.0
!pip install google-cloud-bigquery-reservation
from google.colab import auth
auth.authenticate_user()
project_id = 'my-id'
region = 'EU'
parent_arg = "projects/{}/locations/{}".format(project_id, 
region)
!gcloud config set project {project_id}
from google.cloud import bigquery_reservation_v1
from google.cloud.bigquery_reservation_v1 import *
from google.cloud import bigquery
client = bigquery_reservation_v1.ReservationServiceClient()
def purchase_commitment(slots=500):
commit_config = CapacityCommitment(plan='FLEX', slot_count=slots)
commit = client.create_capacity_commitment(parent=parent_arg,
capacity_commitment=commit_config)
print(commit)
return commit.name
def create_reservation(reservation_name, slots=500):
res_config = Reservation(slot_capacity=slots, ignore_idle_slots=False)
res = client.create_reservation(parent=parent_arg, 
reservation_id=reservation_name,
reservation=res_config)  
print(res)
return res.name
def create_assignment(reservation_id, user_project):
assign_config = bigquery_reservation_v1.Assignment(
#job_type=bigquery_reservation_v1.types.Assignment.JobType(2), 
job_type="QUERY", 
assignee=f"projects/{project_id}"
)
assign = client.create_assignment(parent=res_id, assignment=assign_config)
print(assign)
return assign.name
reservation_name = 'sample-reservation'
slots = 500
commit_id = purchase_commitment(slots)
res_id = create_reservation(reservation_name, slots)
assign_id = create_assignment(res_id, project_id)

没有使用上面的代码进行赋值,而是使用下面的代码:

assignment_config = Assignment(job_type='QUERY', assignee='projects/{}'.format(project_id))
assignment = client.create_assignment(CreateAssignmentRequest(
parent=res_id,
assignment=assignment_config,
))

同样,我没有使用数字格式的project_id,而是使用了项目的全名。这个

相关内容

  • 没有找到相关文章

最新更新