| 31 | } |
| 32 | |
| 33 | bool parseOptions(int* argc, char** argv[], uint64_t* batchSize, |
| 34 | orc::RowReaderOptions* rowReaderOpts, bool* showMetrics) { |
| 35 | static struct option longOptions[] = {{"help", no_argument, nullptr, 'h'}, |
| 36 | {"batch", required_argument, nullptr, 'b'}, |
| 37 | {"columns", required_argument, nullptr, 'c'}, |
| 38 | {"columnTypeIds", required_argument, nullptr, 't'}, |
| 39 | {"columnNames", required_argument, nullptr, 'n'}, |
| 40 | {"metrics", no_argument, nullptr, 'm'}, |
| 41 | {nullptr, 0, nullptr, 0}}; |
| 42 | std::list<uint64_t> cols; |
| 43 | std::list<std::string> colNames; |
| 44 | int opt; |
| 45 | char* tail; |
| 46 | do { |
| 47 | opt = getopt_long(*argc, *argv, "hb:c:t:n:m", longOptions, nullptr); |
| 48 | switch (opt) { |
| 49 | case '?': |
| 50 | case 'h': |
| 51 | return false; |
| 52 | case 'b': |
| 53 | *batchSize = strtoul(optarg, &tail, 10); |
| 54 | if (*tail != '\0') { |
| 55 | fprintf(stderr, "The --batch parameter requires an integer option.\n"); |
| 56 | return false; |
| 57 | } |
| 58 | break; |
| 59 | case 't': |
| 60 | case 'c': |
| 61 | case 'n': { |
| 62 | bool empty = true; |
| 63 | char* col = std::strtok(optarg, ","); |
| 64 | while (col) { |
| 65 | if (opt == 'n') { |
| 66 | colNames.emplace_back(col); |
| 67 | } else { |
| 68 | cols.emplace_back(static_cast<uint64_t>(std::atoi(col))); |
| 69 | } |
| 70 | empty = false; |
| 71 | col = std::strtok(nullptr, ","); |
| 72 | } |
| 73 | if (!empty) { |
| 74 | if (opt == 'c') { |
| 75 | rowReaderOpts->include(cols); |
| 76 | } else if (opt == 't') { |
| 77 | rowReaderOpts->includeTypes(cols); |
| 78 | } else { |
| 79 | rowReaderOpts->include(colNames); |
| 80 | } |
| 81 | } |
| 82 | break; |
| 83 | } |
| 84 | case 'm': { |
| 85 | *showMetrics = true; |
| 86 | break; |
| 87 | } |
| 88 | default: |
| 89 | break; |
| 90 | } |