MCPcopy Create free account
hub / github.com/apache/arrow / RunMain

Function RunMain

cpp/src/arrow/flight/sql/test_app_cli.cc:163–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161}
162
163Status RunMain() {
164#ifdef ARROW_WITH_OPENTELEMETRY
165 ARROW_ASSIGN_OR_RAISE(auto otel_scope, OtelScope::Make());
166#endif
167
168 ARROW_ASSIGN_OR_RAISE(auto location, Location::ForGrpcTcp(FLAGS_host, FLAGS_port));
169 auto client_options = FlightClientOptions::Defaults();
170 client_options.middleware.push_back(
171 arrow::flight::MakeTracingClientMiddlewareFactory());
172 ARROW_ASSIGN_OR_RAISE(auto client, FlightClient::Connect(location, client_options));
173
174 FlightCallOptions call_options;
175
176 if (!FLAGS_username.empty() || !FLAGS_password.empty()) {
177 Result<std::pair<std::string, std::string>> bearer_result =
178 client->AuthenticateBasicToken({}, FLAGS_username, FLAGS_password);
179 ARROW_RETURN_NOT_OK(bearer_result);
180
181 call_options.headers.push_back(bearer_result.ValueOrDie());
182 }
183
184 FlightSqlClient sql_client(std::move(client));
185
186 if (FLAGS_command == "ExecuteUpdate") {
187 ARROW_ASSIGN_OR_RAISE(auto rows, sql_client.ExecuteUpdate(call_options, FLAGS_query));
188
189 std::cout << "Result: " << rows << std::endl;
190
191 return Status::OK();
192 }
193
194 std::unique_ptr<FlightInfo> info;
195
196 if (FLAGS_command == "Execute") {
197 ARROW_ASSIGN_OR_RAISE(info, sql_client.Execute(call_options, FLAGS_query));
198 } else if (FLAGS_command == "GetCatalogs") {
199 ARROW_ASSIGN_OR_RAISE(info, sql_client.GetCatalogs(call_options));
200 } else if (FLAGS_command == "PreparedStatementExecute") {
201 ARROW_ASSIGN_OR_RAISE(auto prepared_statement,
202 sql_client.Prepare(call_options, FLAGS_query));
203 ARROW_ASSIGN_OR_RAISE(info, prepared_statement->Execute());
204 } else if (FLAGS_command == "PreparedStatementExecuteParameterBinding") {
205 ARROW_ASSIGN_OR_RAISE(auto prepared_statement, sql_client.Prepare({}, FLAGS_query));
206 auto parameter_schema = prepared_statement->parameter_schema();
207 auto result_set_schema = prepared_statement->dataset_schema();
208
209 std::cout << result_set_schema->ToString(false) << std::endl;
210 arrow::Int64Builder int_builder;
211 ARROW_RETURN_NOT_OK(int_builder.Append(1));
212 std::shared_ptr<arrow::Array> int_array;
213 ARROW_RETURN_NOT_OK(int_builder.Finish(&int_array));
214 std::shared_ptr<arrow::RecordBatch> result;
215 result = arrow::RecordBatch::Make(parameter_schema, 1, {int_array});
216
217 ARROW_RETURN_NOT_OK(prepared_statement->SetParameters(result));
218 ARROW_ASSIGN_OR_RAISE(info, prepared_statement->Execute());
219 } else if (FLAGS_command == "GetDbSchemas") {
220 ARROW_ASSIGN_OR_RAISE(

Callers 1

mainFunction · 0.70

Calls 15

PrintResultsFunction · 0.85
push_backMethod · 0.80
ValueOrDieMethod · 0.80
GetCatalogsMethod · 0.80
SetParametersMethod · 0.80
GetDbSchemasMethod · 0.80
GetTableTypesMethod · 0.80
GetExportedKeysMethod · 0.80
GetImportedKeysMethod · 0.80
GetPrimaryKeysMethod · 0.80
GetSqlInfoMethod · 0.80

Tested by

no test coverage detected