private InsertAllRequest CreateInsertAllRequest(TableReference tableReference, IEnumerable <BigQueryInsertRow> rows, InsertOptions options, out bool hasRows)
        {
            GaxPreconditions.CheckNotNull(tableReference, nameof(tableReference));
            GaxPreconditions.CheckNotNull(rows, nameof(rows));

            var insertRows = rows.Select(row =>
            {
                GaxPreconditions.CheckArgument(row != null, nameof(rows), "Entries must not be null");
                return(row.ToRowsData());
            }).ToList();
            var body = new TableDataInsertAllRequest
            {
                Rows = insertRows
            };

            // It's annoying to use an out parameter for this, but InsertAllRequest doesn't allow access to the body.
            hasRows = body.Rows.Any();
            options?.ModifyRequest(body);
            var request = Service.Tabledata.InsertAll(body, tableReference.ProjectId, tableReference.DatasetId, tableReference.TableId);

            request.ModifyRequest += _versionHeaderAction;
            // We ensure that every row has an insert ID, so we can always retry.
            RetryHandler.MarkAsRetriable(request);
            return(request);
        }
Example #2
0
        private InsertAllRequest CreateInsertAllRequest(TableReference tableReference, IEnumerable <BigQueryInsertRow> rows, InsertOptions options)
        {
            GaxPreconditions.CheckNotNull(tableReference, nameof(tableReference));
            GaxPreconditions.CheckNotNull(rows, nameof(rows));

            var insertRows = rows.Select(row =>
            {
                GaxPreconditions.CheckArgument(row != null, nameof(rows), "Entries must not be null");
                return(row.ToRowsData());
            }).ToList();
            var body = new TableDataInsertAllRequest
            {
                Rows = insertRows
            };

            options?.ModifyRequest(body);
            var request = Service.Tabledata.InsertAll(body, tableReference.ProjectId, tableReference.DatasetId, tableReference.TableId);

            request.ModifyRequest += _versionHeaderAction;
            if (insertRows.All(ir => ir.InsertId != null))
            {
                RetryHandler.MarkAsRetriable(request);
            }
            return(request);
        }
        private InsertAllRequest CreateInsertAllRequest(TableReference tableReference, IEnumerable <BigQueryInsertRow> rows, InsertOptions options, out IReadOnlyList <BigQueryInsertRow> validatedRows)
        {
            GaxPreconditions.CheckNotNull(tableReference, nameof(tableReference));
            GaxPreconditions.CheckNotNull(rows, nameof(rows));

            validatedRows = rows.Select(row =>
            {
                GaxPreconditions.CheckArgument(row != null, nameof(rows), "Entries must not be null");
                return(row);
            }).ToList().AsReadOnly();
            var body = new TableDataInsertAllRequest
            {
                Rows = new RawRowList(validatedRows, options?.AllowEmptyInsertIds ?? false)
            };

            options?.ModifyRequest(body);
            var request = Service.Tabledata.InsertAll(body, tableReference.ProjectId, tableReference.DatasetId, tableReference.TableId);

            // Even though empty InsertIds might be allowed, this can be retried as per guidance from
            // the API team. Previous de-duplicating was on a best effort basis anyways and client code
            // needs to explicitly allow for empty InsertId and should be aware that doing so will be at
            // the expense of de-duplication efforts.
            RetryHandler.MarkAsRetriable(request);
            request.PrettyPrint = PrettyPrint;
            return(request);
        }
Example #4
0
        private InsertAllRequest CreateInsertAllRequest(TableReference tableReference, IEnumerable <BigQueryInsertRow> rows, InsertOptions options, out bool hasRows)
        {
            GaxPreconditions.CheckNotNull(tableReference, nameof(tableReference));
            GaxPreconditions.CheckNotNull(rows, nameof(rows));

            var insertRows = rows.Select(row =>
            {
                GaxPreconditions.CheckArgument(row != null, nameof(rows), "Entries must not be null");
                return(row.ToRowsData(options?.AllowEmptyInsertIds ?? false));
            }).ToList();
            var body = new TableDataInsertAllRequest
            {
                Rows = insertRows
            };

            // It's annoying to use an out parameter for this, but InsertAllRequest doesn't allow access to the body.
            hasRows = body.Rows.Any();
            options?.ModifyRequest(body);
            var request = Service.Tabledata.InsertAll(body, tableReference.ProjectId, tableReference.DatasetId, tableReference.TableId);

            // Even though empty InsertIds might be allowed, this can be retried as per guidance from
            // the API team. Previous de-duplicating was on a best effort basis anyways and client code
            // needs to explicitly allow for empty InsertId and should be aware that doing so will be at
            // the expense of de-duplication efforts.
            RetryHandler.MarkAsRetriable(request);
            return(request);
        }
        /// <inheritdoc />
        public override void Insert(TableReference tableReference, IEnumerable <BigQueryInsertRow> rows, InsertOptions options = null)
        {
            GaxPreconditions.CheckNotNull(tableReference, nameof(tableReference));
            GaxPreconditions.CheckNotNull(rows, nameof(rows));

            var body = new TableDataInsertAllRequest
            {
                Rows = rows.Select(row =>
                {
                    GaxPreconditions.CheckArgument(row != null, nameof(rows), "Entries must not be null");
                    return(row.ToRowsData());
                }).ToList()
            };

            options?.ModifyRequest(body);
            var request  = Service.Tabledata.InsertAll(body, tableReference.ProjectId, tableReference.DatasetId, tableReference.TableId);
            var response = request.Execute();

            HandleInsertAllResponse(response);
        }
        /// <inheritdoc />
        public override async Task InsertAsync(TableReference tableReference, IEnumerable <BigQueryInsertRow> rows,
                                               InsertOptions options = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            GaxPreconditions.CheckNotNull(tableReference, nameof(tableReference));
            GaxPreconditions.CheckNotNull(rows, nameof(rows));

            var body = new TableDataInsertAllRequest
            {
                Rows = rows.Select(row =>
                {
                    GaxPreconditions.CheckArgument(row != null, nameof(rows), "Entries must not be null");
                    return(row.ToRowsData());
                }).ToList()
            };

            options?.ModifyRequest(body);
            var request  = Service.Tabledata.InsertAll(body, tableReference.ProjectId, tableReference.DatasetId, tableReference.TableId);
            var response = await request.ExecuteAsync(cancellationToken).ConfigureAwait(false);

            HandleInsertAllResponse(response);
        }