| 38 | DEFINE_string(query, "SELECT * FROM intTable WHERE value >= 0", "The query to execute."); |
| 39 | |
| 40 | arrow::Status Main() { |
| 41 | ARROW_ASSIGN_OR_RAISE(auto location, |
| 42 | flight::Location::ForGrpcTcp(FLAGS_host, FLAGS_port)); |
| 43 | std::cout << "Connecting to " << location.ToString() << std::endl; |
| 44 | |
| 45 | // Set up the Flight SQL client |
| 46 | std::unique_ptr<flight::FlightClient> flight_client; |
| 47 | ARROW_ASSIGN_OR_RAISE(flight_client, flight::FlightClient::Connect(location)); |
| 48 | std::unique_ptr<flightsql::FlightSqlClient> client( |
| 49 | new flightsql::FlightSqlClient(std::move(flight_client))); |
| 50 | |
| 51 | flight::FlightCallOptions call_options; |
| 52 | |
| 53 | // Execute the query, getting a FlightInfo describing how to fetch the results |
| 54 | std::cout << "Executing query: '" << FLAGS_query << "'" << std::endl; |
| 55 | ARROW_ASSIGN_OR_RAISE(std::unique_ptr<flight::FlightInfo> flight_info, |
| 56 | client->Execute(call_options, FLAGS_query)); |
| 57 | |
| 58 | // Fetch each partition sequentially (though this can be done in parallel) |
| 59 | for (const flight::FlightEndpoint& endpoint : flight_info->endpoints()) { |
| 60 | // Here we assume each partition is on the same server we originally queried, but this |
| 61 | // isn't true in general: the server may split the query results between multiple |
| 62 | // other servers, which we would have to connect to. |
| 63 | |
| 64 | // The "ticket" in the endpoint is opaque to the client. The server uses it to |
| 65 | // identify which part of the query results to return. |
| 66 | ARROW_ASSIGN_OR_RAISE(auto stream, client->DoGet(call_options, endpoint.ticket)); |
| 67 | // Read all results into an Arrow Table, though we can iteratively process record |
| 68 | // batches as they arrive as well |
| 69 | ARROW_ASSIGN_OR_RAISE(auto table, stream->ToTable()); |
| 70 | std::cout << "Read one chunk:" << std::endl; |
| 71 | std::cout << table->ToString() << std::endl; |
| 72 | } |
| 73 | |
| 74 | return arrow::Status::OK(); |
| 75 | } |
| 76 | |
| 77 | int main(int argc, char** argv) { |
| 78 | gflags::ParseCommandLineFlags(&argc, &argv, true); |
no test coverage detected