google / google/googlesql

Add stdin support?

Open Beginner friendly
#169 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
2.6k
Forks
260
PR merge metrics
No merged PRs in 30d

Description

It would be quite helpful if the `execute_query` binary supported reading queries from stdin – especially for very long queries where we might hit system argv limits. Something like `echo "SELECT 1 + 1" | execute_query -`.

This would only require a minor change to `execute_query.cc` to read from stdin. Would you accept a PR? The relevant code changes are also below, which I've tested and validated on my own fork:

```cc
// Added to includes

#include

// Updated RunTool fn:

absl::Status RunTool(const std::vector& args) {
ExecuteQueryConfig config;

GOOGLESQL_RETURN_IF_ERROR(InitializeExecuteQueryConfig(config));

GOOGLESQL_ASSIGN_OR_RETURN(std::unique_ptr writer,
MakeWriterFromFlags(config, std::cout));

if (absl::GetFlag(FLAGS_web)) {
return RunExecuteQueryWebServer(absl::GetFlag(FLAGS_port));
}

std::string sql;
if (args.size() == 1 && args[0] == "-") {
// Read SQL from stdin
std::ostringstream ss;
ss << std::cin.rdbuf();
sql = ss.str();
} else {
sql = absl::StrJoin(args, " ");
}
return ExecuteQuery(sql, config, *writer);
}

// Updated usage string:

const char kUsage[] =
"Usage: execute_query "
"{ \"\" | - | {--web [--port=] } }\n";
```

Contributor guide

Open the contributing guide

Research direction

Start in execute_query.cc, particularly RunTool and the usage string shown in the issue. Review the existing argument handling, then run the relevant execute_query tests or binary checks; done means a query supplied through stdin with '-' executes while existing SQL arguments and web usage remain unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.