@@ -20,28 +20,44 @@ public BigQueryService(GoogleBigQueryAttribute googleBigQueryAttribute, Type ite
2020 ( this . tableSchema , this . dictionaryOfProperties ) = TableSchemaBuilderService . GetTableSchema ( itemType ) ;
2121 }
2222
23- private Task < BigQueryTable > GetTable ( DateTime date , CancellationToken cancellationToken )
24- {
25- BigQueryClient client = GetClient ( ) ;
26-
27- //return client.GetOrCreateTableAsync(datasetId, tableId, tableSchema, null, new CreateTableOptions() { TimePartitioning = new TimePartitioning() { Type = "DAY" } }, cancellationToken)
28- // .ContinueWith((createTableTask) => {
29- // return client.GetTableAsync(datasetId, $"{tableId}${date:yyyyMMdd}", null, cancellationToken);
30- // }, cancellationToken).Unwrap();
23+ public Task CreateTable ( bool timePartitioning , CancellationToken cancellationToken ) {
24+
25+ BigQueryClient client = GetBiqQueryClient ( ) ;
26+
27+ return client . GetOrCreateTableAsync (
28+ googleBigQueryAttribute . DatasetId ,
29+ googleBigQueryAttribute . TableId ,
30+ tableSchema ,
31+ null ,
32+ timePartitioning ? new CreateTableOptions ( ) { TimePartitioning = new TimePartitioning ( ) { Type = "DAY" } } : null ,
33+ cancellationToken ) ;
34+
35+ }
36+
37+ public Task DeleteTable ( CancellationToken cancellationToken ) {
38+
39+ BigQueryClient client = GetBiqQueryClient ( ) ;
40+
41+ return client . DeleteTableAsync (
42+ googleBigQueryAttribute . DatasetId ,
43+ googleBigQueryAttribute . TableId ,
44+ null ,
45+ cancellationToken ) ;
46+
47+ }
48+
49+ private Task < BigQueryTable > GetTable ( DateTime date , CancellationToken cancellationToken ) {
50+ BigQueryClient client = GetBiqQueryClient ( ) ;
51+
3152 return client . GetTableAsync ( googleBigQueryAttribute . DatasetId , $ "{ googleBigQueryAttribute . TableId } ${ date : yyyyMMdd} ", null , cancellationToken ) ;
3253 }
3354
34- private BigQueryClient GetClient ( )
35- {
55+ private BigQueryClient GetBiqQueryClient ( ) {
3656 GoogleCredential googleCredential = null ;
37- if ( googleBigQueryAttribute . Credentials != null )
38- {
57+ if ( googleBigQueryAttribute . Credentials != null ) {
3958 googleCredential = GoogleCredential . FromStream ( new System . IO . MemoryStream ( googleBigQueryAttribute . Credentials ) ) ;
40- }
41- else
42- {
43- if ( ! string . IsNullOrWhiteSpace ( googleBigQueryAttribute . CredentialsFileName ) )
44- {
59+ } else {
60+ if ( ! string . IsNullOrWhiteSpace ( googleBigQueryAttribute . CredentialsFileName ) ) {
4561 var path = System . IO . Path . GetDirectoryName ( typeof ( GoogleBigQueryAttribute ) . Assembly . Location ) ;
4662 var fullPath = System . IO . Path . Combine ( path , ".." , googleBigQueryAttribute . CredentialsFileName ) ;
4763 var credentials = System . IO . File . ReadAllBytes ( fullPath ) ;
@@ -80,7 +96,7 @@ public Task InsertRowsAsync(DateTime date, IEnumerable<GoogleBigQueryRow> rows,
8096 }
8197 else {
8298
83- BigQueryClient client = GetClient ( ) ;
99+ BigQueryClient client = GetBiqQueryClient ( ) ;
84100
85101 IEnumerable < string > lines = BigQueryInsertRowService . GetBigQueryJobLines ( rows ) ;
86102
0 commit comments