1 /* Copyright 2016 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 16 #ifndef TENSORFLOW_CORE_KERNELS_CLOUD_BIGQUERY_TABLE_ACCESSOR_TEST_DATA_H_ 17 #define TENSORFLOW_CORE_KERNELS_CLOUD_BIGQUERY_TABLE_ACCESSOR_TEST_DATA_H_ 18 19 #include <string> 20 21 namespace tensorflow { 22 namespace { 23 24 const string kSampleSchema = R"({ 25 "kind": "bigquery#table", 26 "etag": "\"4zcX32ezvFoFzxHoG04qJqKZk6c/MTQ1Nzk3NTgwNzE4Mw\"", 27 "id": "test-project:test-dataset.test-table", 28 "schema": { 29 "fields": [ 30 { 31 "name": "int_field", 32 "type": "INTEGER", 33 "mode": "REQUIRED" 34 },{ 35 "name": "str_field", 36 "type": "STRING", 37 "mode": "NULLABLE" 38 },{ 39 "name": "rec_field", 40 "type": "RECORD", 41 "fields": [ 42 { 43 "name": "float_field", 44 "type": "FLOAT", 45 "mode": "NULLABLE" 46 }] 47 },{ 48 "name": "bool_field", 49 "type": "BOOLEAN", 50 "mode": "NULLABLE" 51 },{ 52 "name": "bytes_field", 53 "type": "BYTES", 54 "mode": "NULLABLE" 55 },{ 56 "name": "timestamp_field", 57 "type": "TIMESTAMP", 58 "mode": "NULLABLE" 59 },{ 60 "name": "date_field", 61 "type": "DATE", 62 "mode": "NULLABLE" 63 },{ 64 "name": "time_field", 65 "type": "TIME", 66 "mode": "NULLABLE" 67 },{ 68 "name": "datetime_field", 69 "type": "DATETIME", 70 "mode": "NULLABLE" 71 }] 72 }, 73 "numRows": "4" 74 })"; 75 76 const string kSampleSchemaTwoRecords = R"({ 77 "kind": "bigquery#table", 78 "etag": "\"4zcX32ezvFoFzxHoG04qJqKZk6c/MTQ1Nzk3NTgwNzE4Mw\"", 79 "id": "test-project:test-dataset.test-table", 80 "schema": { 81 "fields": [ 82 { 83 "name": "rec_field1", 84 "type": "RECORD", 85 "fields": [ 86 { 87 "name": "int_field", 88 "type": "INTEGER", 89 "mode": "NULLABLE" 90 }, { 91 "name": "float_field", 92 "type": "FLOAT", 93 "mode": "NULLABLE" 94 }] 95 },{ 96 "name": "rec_field2", 97 "type": "RECORD", 98 "fields": [ 99 { 100 "name": "bool_field", 101 "type": "BOOLEAN", 102 "mode": "NULLABLE" 103 },{ 104 "name": "bytes_field", 105 "type": "BYTES", 106 "mode": "NULLABLE" 107 }] 108 }] 109 }, 110 "numRows": "4" 111 })"; 112 113 const string kTestRow = R"({ 114 "kind": "bigquery#table", 115 "etag": "\"4zcX32ezvFoFzxHoG04qJqKZk6c/MTQ1Nzk3NTgwNzE4Mw\"", 116 "id": "test-project:test-dataset.test-table", 117 "rows": [ 118 { 119 "f": [ 120 { 121 "v": "1234" 122 },{ 123 "v": "" 124 },{ 125 "v": { 126 "f": [ 127 { 128 "v": "1.23456" 129 }] 130 } 131 },{ 132 "v": "true" 133 },{ 134 "v": "01010100101" 135 },{ 136 "v": "timestamp" 137 },{ 138 "v": "date" 139 },{ 140 "v": "time" 141 },{ 142 "v": "datetime" 143 }]}]})"; 144 145 const string kBrokenTestRow = R"({ 146 "kind": "bigquery#table", 147 "etag": "\"4zcX32ezvFoFzxHoG04qJqKZk6c/MTQ1Nzk3NTgwNzE4Mw\"", 148 "id": "test-project:test-dataset.test-table", 149 "rows": [ 150 { 151 "f": [ 152 { 153 "v": "1-234" // This does not parse as integer. 154 },{ 155 "v": "" 156 },{ 157 },{ 158 "v": "true" 159 },{ 160 "v": "01010100101" 161 },{ 162 "v": "timestamp" 163 },{ 164 "v": "date" 165 },{ 166 "v": "time" 167 },{ 168 "v": "datetime" 169 }]}]})"; 170 171 const string kTestRowWithNulls = R"({ 172 "kind": "bigquery#table", 173 "etag": "\"4zcX32ezvFoFzxHoG04qJqKZk6c/MTQ1Nzk3NTgwNzE4Mw\"", 174 "id": "test-project:test-dataset.test-table", 175 "rows": [ 176 { 177 "f": [ 178 { 179 "v": "1234" 180 },{ 181 "v": "string" 182 },{ 183 "v": null 184 },{ 185 "v": "true" 186 },{ 187 "v": "01010100101" 188 },{ 189 "v": "" 190 },{ 191 "v": null 192 },{ 193 "v": null 194 },{ 195 "v": "datetime" 196 }]}]})"; 197 198 // Example proto corresponding to kTestRow. 199 const string kTestExampleProto = R"(features { 200 feature { 201 key: "bool_field" 202 value { 203 int64_list { 204 value: 1 205 } 206 } 207 } 208 feature { 209 key: "bytes_field" 210 value { 211 bytes_list { 212 value: "01010100101" 213 } 214 } 215 } 216 feature { 217 key: "date_field" 218 value { 219 bytes_list { 220 value: "date" 221 } 222 } 223 } 224 feature { 225 key: "datetime_field" 226 value { 227 bytes_list { 228 value: "datetime" 229 } 230 } 231 } 232 feature { 233 key: "int_field" 234 value { 235 int64_list { 236 value: 1234 237 } 238 } 239 } 240 feature { 241 key: "rec_field.float_field" 242 value { 243 float_list { 244 value: 1.23456 245 } 246 } 247 } 248 feature { 249 key: "str_field" 250 value { 251 bytes_list { 252 value: "" 253 } 254 } 255 } 256 feature { 257 key: "time_field" 258 value { 259 bytes_list { 260 value: "time" 261 } 262 } 263 } 264 feature { 265 key: "timestamp_field" 266 value { 267 bytes_list { 268 value: "timestamp" 269 } 270 } 271 } 272 } 273 )"; 274 275 // Example proto corresponding to kTestRowWithNulls. 276 const string kTestExampleProtoWithNulls = R"(features { 277 feature { 278 key: "bool_field" 279 value { 280 int64_list { 281 value: 1 282 } 283 } 284 } 285 feature { 286 key: "bytes_field" 287 value { 288 bytes_list { 289 value: "01010100101" 290 } 291 } 292 } 293 feature { 294 key: "datetime_field" 295 value { 296 bytes_list { 297 value: "datetime" 298 } 299 } 300 } 301 feature { 302 key: "int_field" 303 value { 304 int64_list { 305 value: 1234 306 } 307 } 308 } 309 feature { 310 key: "timestamp_field" 311 value { 312 bytes_list { 313 value: "" 314 } 315 } 316 } 317 feature { 318 key: "str_field" 319 value { 320 bytes_list { 321 value: "string" 322 } 323 } 324 } 325 } 326 )"; 327 328 // Example proto corresponding to part of kTestRow. 329 const string kTestPartialExampleProto = R"(features { 330 feature { 331 key: "bool_field" 332 value { 333 int64_list { 334 value: 1 335 } 336 } 337 } 338 feature { 339 key: "rec_field.float_field" 340 value { 341 float_list { 342 value: 1.23456 343 } 344 } 345 } 346 } 347 )"; 348 349 const string kTestExampleProtoWithTwoRecords = R"(features { 350 feature { 351 key: "rec_field1.float_field" 352 value { 353 float_list { 354 value: 1.23456 355 } 356 } 357 } 358 feature { 359 key: "rec_field2.bool_field" 360 value { 361 int64_list { 362 value: 1 363 } 364 } 365 } 366 } 367 )"; 368 369 const string kTestTwoRows = R"({ 370 "kind": "bigquery#table", 371 "etag": "\"4zcX32ezvFoFzxHoG04qJqKZk6c/MTQ1Nzk3NTgwNzE4Mw\"", 372 "pageToken": "next_page", 373 "id": "test-project:test-dataset.test-table", 374 "rows": [ 375 {"f": [{"v": "1111"},{},{},{},{},{},{},{},{}]}, 376 {"f": [{"v": "2222"},{},{},{},{},{},{},{},{}]} 377 ]})"; 378 379 const string kTestRowWithTwoRecords = R"({ 380 "kind": "bigquery#table", 381 "etag": "\"4zcX32ezvFoFzxHoG04qJqKZk6c/MTQ1Nzk3NTgwNzE4Mw\"", 382 "id": "test-project:test-dataset.test-table", 383 "rows": [ 384 { 385 "f": [ 386 {"v": {"f": [{}, {"v": "1.23456"}]}}, 387 {"v": {"f": [{"v": "true"}, {}]} 388 }]}]})"; 389 390 const string kTestEmptyRow = R"({ 391 "kind": "bigquery#table", 392 "etag": "\"4zcX32ezvFoFzxHoG04qJqKZk6c/MTQ1Nzk3NTgwNzE4Mw\"", 393 "id": "test-project:test-dataset.test-table", 394 "rows": [ 395 { 396 "f": [ 397 {"v": {"f": [{}, {}]}}, 398 {"v": {"f": [{"v": null}, {}]} 399 }]}]})"; 400 401 } // namespace 402 } // namespace tensorflow 403 404 #endif // TENSORFLOW_CORE_KERNELS_CLOUD_BIGQUERY_TABLE_ACCESSOR_TEST_DATA_H_ 405