@@ -81,12 +81,21 @@ private Task<BigQueryTable> GetTable(DateTime date, CancellationToken cancellati
8181 }
8282 var client = Google . Cloud . BigQuery . V2 . BigQueryClient . Create ( projectId , googleCredential ) ;
8383
84+
85+ //client.GetTable
86+
87+ //tableSchema.Fields.Insert(0, new TableFieldSchema() { Name = "_PARTITIONTIME", Mode = "REQUIRED", Type = "DATE" });
88+
8489 return client . GetOrCreateTableAsync (
8590 datasetId ,
8691 $ "{ tableId } ${ date . ToString ( "yyyyMMdd" ) } ",
92+ //tableId,
8793 tableSchema ,
8894 new GetTableOptions ( ) ,
89- new CreateTableOptions ( ) ,
95+ new CreateTableOptions ( ) {
96+ FriendlyName = $ "{ tableId } ${ date . ToString ( "yyyyMMdd" ) } ",
97+ TimePartitioning = new TimePartitioning ( ) { Type = "DAY" /*, Field = "_PARTITIONTIME"*/ }
98+ } ,
9099 cancellationToken ) ;
91100 }
92101
@@ -103,7 +112,7 @@ public Task InsertRowsAsync(DateTime date, IEnumerable<GoogleBigQueryRow> rows,
103112
104113 return GetTable ( date , cancellationToken )
105114 . ContinueWith ( ( tableTask ) => {
106- var table = tableTask . Result ;
115+ BigQueryTable table = tableTask . Result ;
107116 return table . InsertRowsAsync ( bigQueryRows , new InsertOptions ( ) { AllowUnknownFields = true } , cancellationToken ) ;
108117 } , cancellationToken ) . Unwrap ( ) ;
109118
@@ -115,9 +124,37 @@ public Task InsertRowsAsync(DateTime date, IEnumerable<GoogleBigQueryRow> rows,
115124
116125 private object GetBigQueryValue ( PropertyInfo property , GoogleBigQueryRow row ) {
117126 switch ( property . PropertyType . Name . ToUpper ( ) ) {
127+ case "BYTE" :
128+ return ( int ) ( byte ) property . GetValue ( row ) ;
129+ case "CHAR" :
130+ return ( ( char ) property . GetValue ( row ) ) . ToString ( ) ;
131+ case "CHAR[]" :
132+ return ( ( char [ ] ) property . GetValue ( row ) ) . ToString ( ) ;
118133 case "DATETIME" :
119- var value = ( DateTime ) property . GetValue ( row ) ;
120- return value . ToString ( BigQueryDateTimeFormat , cultureUS ) ;
134+ var datetimeValue = ( DateTime ) property . GetValue ( row ) ;
135+ return datetimeValue . ToString ( BigQueryDateTimeFormat , cultureUS ) ;
136+ case "DECIMAL" :
137+ return ( float ) ( decimal ) property . GetValue ( row ) ;
138+ case "GUID" :
139+ return ( ( Guid ) property . GetValue ( row ) ) . ToString ( ) ;
140+ case "UINT64" :
141+ return ( int ) ( UInt64 ) property . GetValue ( row ) ;
142+ case "IENUMERABLE`1" :
143+ var enumerableValue = property . GetValue ( row ) ;
144+ Type innerPropertyType = property . PropertyType . GenericTypeArguments [ 0 ] ;
145+ switch ( innerPropertyType . Name . ToUpper ( ) ) {
146+ case "BOOLEAN" :
147+ return new bool [ ] { } ;
148+ case "CHAR" :
149+ return ( ( char [ ] ) enumerableValue ) . ToString ( ) ;
150+ case "DECIMAL" :
151+ return ( ( decimal [ ] ) enumerableValue ) . Select ( c => ( float ) c ) ;
152+ case "SINGLE" :
153+ //return ((Single[])enumerableValue).Select(c => (float)c);
154+ return new float [ ] { } ;
155+ }
156+
157+ return enumerableValue ;
121158 default :
122159 return property . GetValue ( row ) ;
123160 }
0 commit comments