You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "berkaysynnada (via GitHub)" <gi...@apache.org> on 2024/03/28 07:08:12 UTC
[PR] CLI Sequential "Create External Table" Command Support [arrow-datafusion]
berkaysynnada opened a new pull request, #9831:
URL: https://github.com/apache/arrow-datafusion/pull/9831
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
-->
While we can write CLI commands sequentially such as:
```
CREATE TABLE test1 (
c1 VARCHAR(255),
c2 INT,
c3 INT
);
INSERT INTO test1 (c1, c2, c3) VALUES ('c', 2, 1);
SELECT * FROM test1;
```
CLI gives error to write more commands after "CREATE EXTERNAL TABLE":
```
CREATE EXTERNAL TABLE test1 (
c1 VARCHAR(255),
c2 INT,
c3 INT,
...
)
STORED AS CSV
WITH HEADER ROW
LOCATION '/Users/berkaysahin/Desktop/datafusion-upstream/testing/data/csv/aggregate_test_100.csv';
SELECT * FROM test1;
```
`🤔 Invalid statement: sql parser error: Expected end of statement, found: SELECT`
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
This PR addresses the issue that we needed to enter commands one by one for creating external tables. It resolves this by splitting the entire string at semicolons, ensuring each segment passes parser checks one by one, and then executing them sequentially.
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] datafusion-cli support for multiple commands in a single line [arrow-datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #9831:
URL: https://github.com/apache/arrow-datafusion/pull/9831#discussion_r1543908224
##########
datafusion-cli/src/helper.rs:
##########
@@ -197,6 +204,19 @@ pub fn unescape_input(input: &str) -> datafusion::error::Result<String> {
Ok(result)
}
+/// Splits a string which consists of multiple queries.
+pub(crate) fn split_from_semicolon(sql: String) -> Vec<String> {
+ sql.split(';')
Review Comment:
We may want to add a test? Just wondering if it will work for query
```
select ';'
```
?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] datafusion-cli support for multiple commands in a single line [arrow-datafusion]
Posted by "mustafasrepo (via GitHub)" <gi...@apache.org>.
mustafasrepo merged PR #9831:
URL: https://github.com/apache/arrow-datafusion/pull/9831
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] CLI Sequential "Create External Table" Command Support [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9831:
URL: https://github.com/apache/arrow-datafusion/pull/9831#discussion_r1543800474
##########
datafusion-cli/src/helper.rs:
##########
@@ -197,6 +204,19 @@ pub fn unescape_input(input: &str) -> datafusion::error::Result<String> {
Ok(result)
}
+/// Splits a string which consists of multiple queries.
+pub(crate) fn split_from_semicolon(sql: String) -> Vec<String> {
Review Comment:
You can probably avoid a copy here if you passed in a reference
```suggestion
pub(crate) fn split_from_semicolon(sql: &str) -> Vec<&str> {
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] datafusion-cli support for multiple commands in a single line [arrow-datafusion]
Posted by "berkaysynnada (via GitHub)" <gi...@apache.org>.
berkaysynnada commented on code in PR #9831:
URL: https://github.com/apache/arrow-datafusion/pull/9831#discussion_r1544222926
##########
datafusion-cli/src/helper.rs:
##########
@@ -197,6 +204,19 @@ pub fn unescape_input(input: &str) -> datafusion::error::Result<String> {
Ok(result)
}
+/// Splits a string which consists of multiple queries.
+pub(crate) fn split_from_semicolon(sql: String) -> Vec<String> {
+ sql.split(';')
Review Comment:
I will send a commit excluding semicolons if they are in "_" or '_', and some tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] datafusion-cli support for multiple commands in a single line [arrow-datafusion]
Posted by "berkaysynnada (via GitHub)" <gi...@apache.org>.
berkaysynnada commented on code in PR #9831:
URL: https://github.com/apache/arrow-datafusion/pull/9831#discussion_r1544221706
##########
datafusion-cli/src/helper.rs:
##########
@@ -197,6 +204,19 @@ pub fn unescape_input(input: &str) -> datafusion::error::Result<String> {
Ok(result)
}
+/// Splits a string which consists of multiple queries.
+pub(crate) fn split_from_semicolon(sql: String) -> Vec<String> {
Review Comment:
I cannot find a copy here. If pass the reference, I also need to copy it for `exec_and_print()`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] datafusion-cli support for multiple commands in a single line [arrow-datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #9831:
URL: https://github.com/apache/arrow-datafusion/pull/9831#discussion_r1544372141
##########
datafusion-cli/src/helper.rs:
##########
@@ -292,4 +330,39 @@ mod tests {
Ok(())
}
+
+ #[test]
Review Comment:
👍 thank you for the tests 👍
##########
datafusion-cli/src/helper.rs:
##########
@@ -197,6 +204,37 @@ pub fn unescape_input(input: &str) -> datafusion::error::Result<String> {
Ok(result)
}
+/// Splits a string which consists of multiple queries.
+pub(crate) fn split_from_semicolon(sql: String) -> Vec<String> {
+ let mut commands = Vec::new();
+ let mut current_command = String::new();
+ let mut in_single_quote = false;
+ let mut in_double_quote = false;
+
+ for c in sql.chars() {
Review Comment:
This is likely pretty brittle (likely won't handle all crazy corner cases, like for example when there are escaped quotes `\\'`, but I think it is better than what we have now.
Thanks @berkaysynnada
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org