From: John Kitchin <jkitchin@andrew.cmu.edu>
To: emacs-orgmode@gnu.org
Subject: Re: Org Babel: Submit SQL to command line app & capture results
Date: Mon, 24 Feb 2020 08:13:44 -0500 [thread overview]
Message-ID: <m2h7zgqgaf.fsf@andrew.cmu.edu> (raw)
In-Reply-To: <CAC=HedCgFr=pPtU9w0A9TJkEW1eX-4jRz0-SEFJx0yWKKJ6Paw@mail.gmail.com>
I think you can do something like this. I don't have impala-shell, so
I wasn't able to test this. It worked using another executable though.
This is pretty bare bones, no sessions, etc.
(require 'org)
(require 'ob)
(defun org-babel-execute:impala (body params)
(let* ((code (org-babel-expand-body:generic body params))
(src-dir (make-temp-file "ob-impala-" t))
(src-file (f-join src-dir (concat (file-name-nondirectory src-dir) ".imp"))))
(with-temp-file src-file
(insert code))
;; Compile step
(org-babel-eval
(format "impala-shell %s" src-file)
"")))
;;;###autoload
(eval-after-load 'org
'(add-to-list 'org-src-lang-modes '("impala" . impala)))
(add-to-list 'org-src-lang-modes '("impala" . sql))
Nathan Neff <nathan.neff@gmail.com> writes:
> Hello all,
>
> I would like to use org-babel to have SQL code like this:
>
> * Some heading
>
> #+begin_src something
> SELECT COUNT(*) FROM some_table;
> #+end_src
>
> I would like to have the code highlighted as SQL. However, I'm not reading
> from a DB matching the requirements of
> https://orgmode.org/worg/org-contrib/babel/languages/ob-doc-sql.html
>
> What I would like to do when I run the code above is to:
> 1) simply take the contents of the code and push it into a tmp file
> 2) run a shell program on the tmp file:
> impala-shell -f tmp file.txt
> 3) Capture the STDOUT from the above command
>
> How would I do this using org-babel? Create a new "language"?
> Are there already similar implementations which basically take the contents
> of the source code, save to a temp file then execute a standalone program
> and capture results?
>
> Again, I would like to have SQL style highlighting.
>
> Thanks for pointers -- I'm sure this is something that's reasonably easy
> to implement - I just don't want to start off on the wrong foo.t
> --Nate
--
Professor John Kitchin
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
@johnkitchin
http://kitchingroup.cheme.cmu.edu
prev parent reply other threads:[~2020-02-24 13:13 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-23 19:49 Org Babel: Submit SQL to command line app & capture results Nathan Neff
2020-02-24 13:13 ` John Kitchin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2h7zgqgaf.fsf@andrew.cmu.edu \
--to=jkitchin@andrew.cmu.edu \
--cc=emacs-orgmode@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).