| 327 | } |
| 328 | |
| 329 | std::uint8_t postgresql_parser::parse_cudf_string( |
| 330 | void * src, std::size_t col, std::size_t row, cudf_string_col * v) { |
| 331 | PGresult * pgResult = static_cast<PGresult *>(src); |
| 332 | |
| 333 | Oid oid = PQftype(pgResult, col); |
| 334 | if (oid == InvalidOid) { throw std::runtime_error("Bad postgresql type"); } |
| 335 | |
| 336 | if (PQgetisnull(pgResult, row, col)) { |
| 337 | v->offsets.push_back(v->offsets.back()); |
| 338 | return 0; |
| 339 | } |
| 340 | const char * result = PQgetvalue(pgResult, row, col); |
| 341 | std::string data; |
| 342 | |
| 343 | // TODO(cristhian): convert oid to data type using postgresql pgtype table |
| 344 | // https://www.postgresql.org/docs/13/catalog-pg-type.html |
| 345 | switch (oid) { |
| 346 | case 1082: { // date |
| 347 | const std::int32_t value = |
| 348 | ntohl(*reinterpret_cast<const std::int32_t *>(result)); |
| 349 | data = date_to_string(value); |
| 350 | break; |
| 351 | } |
| 352 | case 1114: { // timestamp |
| 353 | const std::int64_t value = |
| 354 | __builtin_bswap64(*reinterpret_cast<const std::int64_t *>(result)); |
| 355 | data = timestamp_to_string(value); |
| 356 | break; |
| 357 | } |
| 358 | default: data = result; |
| 359 | } |
| 360 | |
| 361 | v->chars.insert(v->chars.end(), data.cbegin(), data.cend()); |
| 362 | v->offsets.push_back(v->offsets.back() + data.length()); |
| 363 | return 1; |
| 364 | } |
| 365 | |
| 366 | |
| 367 | } // namespace io |
nothing calls this directly
no test coverage detected