From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: Org Babel: Submit SQL to command line app & capture results Date: Mon, 24 Feb 2020 08:13:44 -0500 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:37804) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j6DYS-0001Ar-Pg for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 08:13:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j6DYR-0002sS-Mq for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 08:13:48 -0500 Received: from mail-qt1-x82d.google.com ([2607:f8b0:4864:20::82d]:42330) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1j6DYR-0002rW-Ik for emacs-orgmode@gnu.org; Mon, 24 Feb 2020 08:13:47 -0500 Received: by mail-qt1-x82d.google.com with SMTP id r5so6474042qtt.9 for ; Mon, 24 Feb 2020 05:13:47 -0800 (PST) Received: from Johns-MacBook-Air.local (c-67-171-67-30.hsd1.pa.comcast.net. [67.171.67.30]) by smtp.gmail.com with ESMTPSA id k4sm5850619qtj.74.2020.02.24.05.13.45 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Feb 2020 05:13:45 -0800 (PST) In-reply-to: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane-mx.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org 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 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