通过创建脚本并运行脚本,通过Google (BigQuery数据传输服务)调度作业,脚本使用protobuf消息时间戳类型来设置开始日期和结束日期。我无法将它更改为当前的时间戳。
检查以下资源:
我尝试过像下面这样设置属性,但这会引发“请求包含无效参数”的错误。
now = time.time()
seconds = int(now)
start_time = Timestamp(seconds=seconds, nanos=0)
end_time = Timestamp(seconds=seconds, nanos=0)见下面的工作示例:
#!/usr/bin/env python
from google.cloud import bigquery_datatransfer
from google.protobuf.timestamp_pb2 import Timestamp
client = bigquery_datatransfer.DataTransferServiceClient()
start_time = Timestamp()
end_time = Timestamp()
client.schedule_transfer_runs(client.get_transfer_config("projects/{project_id}/locations/europe/transferConfigs/{transfer_id}").name,
start_time=start_time,
end_time=end_time)这是可行的,但将请求发送给API,以获得1970-01-01T00:00:00Z的时间戳,用于开始和结束时间--我希望能够将其更改为当前的时间戳。
发布于 2019-03-25 18:44:01
正如在 docs中所指出的,有几种方法可以做到这一点。如果您只想用当前时间构建时间戳,只需使用timestamp_message.GetCurrentTime()即可。如果希望使用seconds值填充时间戳,则只需使用timestamp_message.FromSeconds(seconds)即可。
作为一个更完整的例子
start_time = Timestamp()
start_time.GetCurrentTime() # Stores the current time in start_time.
end_time = Timestamp()
seconds = 12345
end_time.FromSeconds(seconds) # Stores the number of seconds in end_time.对于您的具体实例,您应该能够做到
#!/usr/bin/env python
from google.cloud import bigquery_datatransfer
from google.protobuf.timestamp_pb2 import Timestamp
client = bigquery_datatransfer.DataTransferServiceClient()
start_time = Timestamp()
start_time.GetCurrentTime()
end_time = Timestamp()
end_time.GetCurrentTime()
client.schedule_transfer_runs(client.get_transfer_config("projects/{project_id}/locations/europe/transferConfigs/{transfer_id}").name,
start_time=start_time,
end_time=end_time)https://stackoverflow.com/questions/55341989
复制相似问题