async def insert_rows( self, table: str, rows, row_ids=None, skipInvalidRows=False, ignoreUnknownValues=False, templateSuffix=None, ): ep = EndPoint().insert_all.format(**self.parse_table_name(table)) table_json = await self.get_table(table) schema = _parse_schema_resource( table_json["schema"]) # 外部ライブラリーの低レベルメソッドなので危険かも rows_info = [] json_rows = [_record_field_to_json(schema, row) for row in rows] for index, row in enumerate(json_rows): info = {"json": row} if row_ids is not None: info["insertId"] = row_ids[index] else: info["insertId"] = str(uuid.uuid4()) rows_info.append(info) params = dict( rows=rows_info, skipInvalidRows=skipInvalidRows, ignoreUnknownValues=ignoreUnknownValues, ) if templateSuffix is not None: params["templateSuffix"] = templateSuffix def error(r): errors = [] for error in r.json().get("insertErrors", ()): errors.append({ "index": int(error["index"]), "errors": error["errors"] }) if len(errors) > 0: logger.error(errors) r = await self.post(endpoint=ep, json=params, call_back=error) return r.json()
def _call_fut(self, field, value): from google.cloud.bigquery._helpers import _record_field_to_json return _record_field_to_json(field, value)
def _call_fut(self, field, value): from google.cloud.bigquery._helpers import _record_field_to_json return _record_field_to_json(field, value)