You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "armanm (via GitHub)" <gi...@apache.org> on 2023/05/04 13:02:28 UTC

[GitHub] [arrow-datafusion] armanm opened a new issue, #6227: What is the easiest way to turn statements into JSON?

armanm opened a new issue, #6227:
URL: https://github.com/apache/arrow-datafusion/issues/6227

   I know very little Rust so apologies for noobe question. I'm using DataFusion through Elixir and want to analyse user statements before passing them along to actually perform the query. How do I convert the output of `parser::DFParser::parse_sql` into JSON?
   
   ```rs
   parser::DFParser::parse_sql("
       CREATE EXTERNAL TABLE foo(c1 int) STORED AS CSV LOCATION 'foo.csv';
       select * from foo;
       DESCRIBE table;
       INSERT INTO users (ss) values ('sdsd');
     ")
   ```
   
   I noticed the underlying `sqlparser` crate supports serde trait for statements but from what I see `datafusion-sql` adds support for a couple more statements (CREATE EXTERNAL... and DESCRIBE ...) and that crate doesn't support serde.
   
   What are some options for me?


-- 
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.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow-datafusion] alamb commented on issue #6227: What is the easiest way to turn statements into JSON?

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on issue #6227:
URL: https://github.com/apache/arrow-datafusion/issues/6227#issuecomment-1534970219

   Can you start with just supporting Statement::Statement?
   
   So something like (untested)
   
   ```
   let statement = parser::DFParser::parse_sql("
       CREATE EXTERNAL TABLE foo(c1 int) STORED AS CSV LOCATION 'foo.csv';
       select * from foo;
       DESCRIBE table;
       INSERT INTO users (ss) values ('sdsd');
     ")
   
   let json = match statement {
      Statement::Statement(sql_statement) =>  serde_json::to_string_pretty(sql_statement).unwrap()
      Statement::CreateExternalTable(..) => "{}".to_string(),
      Statement::DescribeTableStmt(..) => "{}".to_string(),
   }
   ```
   
   That might be enough to get you unblocked -- then perhaps we can add serde support to https://docs.rs/datafusion-sql/23.0.0/datafusion_sql/parser/enum.Statement.html in DataFusion directly
   


-- 
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


[GitHub] [arrow-datafusion] armanm commented on issue #6227: What is the easiest way to turn statements into JSON?

Posted by "armanm (via GitHub)" <gi...@apache.org>.
armanm commented on issue #6227:
URL: https://github.com/apache/arrow-datafusion/issues/6227#issuecomment-1536967893

   Thank you for that example. Although `Statement::Statement` is useful, I'm mainly interested in the `CREATE EXTERNAL TABLE` statements because I intend to block those specifically 😓 


-- 
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