Skip to content

Commit b136cb8

Browse files
committed
support of rows without insertId
1 parent eba75be commit b136cb8

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

AzureFunctions.Extensions.GoogleBigQuery/AsyncCollector.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Task IAsyncCollector<GoogleBigQueryRow>.FlushAsync(CancellationToken cancellatio
6262

6363
//items with date
6464
{
65-
var groups = items.Where(c=> c.Date.HasValue).GroupBy(c => c.Date.Value.Date);
65+
var groups = items.Where(c => c.Date.HasValue).GroupBy(c => c.Date.Value.Date);
6666
foreach (var group in groups)
6767
{
6868
tasks.Add(bqService.InsertRowsAsync(group.Key, group, cancellationToken));
@@ -71,7 +71,14 @@ Task IAsyncCollector<GoogleBigQueryRow>.FlushAsync(CancellationToken cancellatio
7171

7272
}
7373

74-
return Task.WhenAll(tasks);
74+
return Task.WhenAll(tasks)
75+
.ContinueWith((allTasks) =>
76+
{
77+
if (allTasks.IsFaulted)
78+
{
79+
throw allTasks.Exception.InnerException;
80+
}
81+
});
7582
}
7683

7784
}

AzureFunctions.Extensions.GoogleBigQuery/BigQueryInsertRowService.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ internal static BigQueryInsertRow GetBigQueryInsertRow(GoogleBigQueryRow row, ID
2020

2121
IDictionary<string, object> dic = GetDictionaryOfValues(dictionaryOfProperties, row);
2222

23-
return new BigQueryInsertRow(row.InsertId) { dic };
23+
if (string.IsNullOrWhiteSpace(row.InsertId))
24+
{
25+
return new BigQueryInsertRow() { dic };
26+
}
27+
else
28+
{
29+
return new BigQueryInsertRow(row.InsertId) { dic };
30+
}
31+
2432
}
2533

2634
private static IDictionary<string, object> GetDictionaryOfValues(IDictionary<string, IEnumerable<PropertyInfo>> dictionaryOfProperties, object obj)

AzureFunctions.Extensions.GoogleBigQuery/BigQueryService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,19 @@ public Task InsertRowsAsync(DateTime date, IEnumerable<GoogleBigQueryRow> rows,
149149
return Task.CompletedTask;
150150
}
151151

152-
public async Task InsertRowsAsync(IEnumerable<GoogleBigQueryRow> rows, CancellationToken cancellationToken)
152+
public Task InsertRowsAsync(IEnumerable<GoogleBigQueryRow> rows, CancellationToken cancellationToken)
153153
{
154154

155155
if (rows != null && rows.Count() > 0)
156156
{
157157

158-
await GetTableAsync(cancellationToken)
158+
return GetTableAsync(cancellationToken)
159159
.ContinueWith((tableTask) =>
160160
{
161161
BigQueryTable table = tableTask.Result;
162162

163163
var bigQueryRows = rows.Select(c => BigQueryInsertRowService.GetBigQueryInsertRow(c, dictionaryOfProperties)).ToArray();
164-
164+
165165
return table.InsertRowsAsync(bigQueryRows, new InsertOptions() { AllowUnknownFields = false }, cancellationToken)
166166
.ContinueWith((insertRowsTask) =>
167167
{
@@ -174,7 +174,8 @@ await GetTableAsync(cancellationToken)
174174

175175
}
176176

177-
//return Task.CompletedTask;
177+
return Task.CompletedTask;
178178
}
179+
179180
}
180181
}

AzureFunctions.Extensions.GoogleBigQuery/GoogleBigQueryRow.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ namespace AzureFunctions.Extensions.GoogleBigQuery {
44
public class GoogleBigQueryRow {
55

66
public GoogleBigQueryRow(DateTime? date, string insertId) {
7-
if (string.IsNullOrWhiteSpace(insertId)) { throw new ArgumentNullException(nameof(insertId)); }
8-
97
Date = date;
108
InsertId = insertId;
119
}

0 commit comments

Comments
 (0)