bug#3887: [PATCH] Hive support for sql-mode

Ian Eure <[email protected]>
Newsgroups gmane.emacs.bugs,gmane.emacs.pretest.bugs
Message-ID <[email protected]>
I added basic support for Hive to sql-mode. Hive is a SQL-like  
interface for querying data stored in Hadoop, a distributed storage  
framework and map/reduce engine.

Patch against recent CVS HEAD.
sql-hive.patch (application/octet-stream, 4.2 KB)
diff --git a/sql.el b/sql.el
index da0794b..609eec6 100644
--- a/sql.el
+++ b/sql.el
@@ -283,6 +283,7 @@ highlighted properly when you open them."
 		 (const :tag "PostGres" postgres)
 		 (const :tag "Solid" solid)
 		 (const :tag "SQLite" sqlite)
+		 (const :tag "Hive" hive)
 		 (const :tag "Sybase" sybase))
   :group 'SQL)
 
@@ -360,6 +361,11 @@ highlighted properly when you open them."
      :sqli-connect sql-connect-sqlite
      :sqli-prompt-regexp "^sqlite> "
      :sqli-prompt-length 8)
+    (hive
+     :font-lock sql-mode-hive-font-lock-keywords
+     :sqli-connect sql-connect-hive
+     :sqli-prompt-range "^hive> "
+     :sqli-prompt-length 6)
     (sybase
      :font-lock sql-mode-sybase-font-lock-keywords
      :sqli-login (server user password database)
@@ -549,6 +555,21 @@ on Windows: \"-C\" \"-t\" \"-f\" \"-n\"."
   :version "20.8"
   :group 'SQL)
 
+;; Customization for Hive
+
+(defcustom sql-hive-program "hive"
+  "*Command to start hive.
+
+Starts `sql-interactive-mode' after doing some setup."
+  :type 'file
+  :group 'SQL)
+
+(defcustom sql-hive-options nil
+  "*List of additional options for `sql-hive-program'."
+  :type '(repeat string)
+  :version "20.8"
+  :group 'SQL)
+
 ;; Customization for MySql
 
 (defcustom sql-mysql-program "mysql"
@@ -840,6 +861,9 @@ Based on `comint-mode-map'.")
     ["SQLite" sql-highlight-sqlite-keywords
      :style radio
      :selected (eq sql-product 'sqlite)]
+    ["Hive" sql-highlight-hive-keywords
+     :style radio
+     :selected (eq sql-product 'hive)]
     ["Sybase" sql-highlight-sybase-keywords
      :style radio
      :selected (eq sql-product 'sybase)]
@@ -1637,6 +1661,14 @@ regular expressions are created during compilation by calling the
 function `regexp-opt'.  Therefore, take a look at the source before
 you define your own sql-mode-sqlite-font-lock-keywords.")
 
+(defvar sql-mode-hive-font-lock-keywords nil
+  "Hive SQL keywords used by font-lock.
+
+This variable is used by `sql-mode' and `sql-interactive-mode'.  The
+regular expressions are created during compilation by calling the
+function `regexp-opt'.  Therefore, take a look at the source before
+you define your own sql-mode-sqlite-font-lock-keywords.")
+
 (defvar sql-mode-db2-font-lock-keywords nil
   "DB2 SQL keywords used by font-lock.
 
@@ -1830,6 +1862,11 @@ highlighting."
   (interactive)
   (sql-set-product 'sqlite))
 
+(defun sql-highlight-hive-keywords ()
+  "Highlight Hive SQL keywords."
+  (interactive)
+  (sql-set-product 'hive))
+
 (defun sql-highlight-db2-keywords ()
   "Highlight DB2 SQL keywords."
   (interactive)
@@ -2614,7 +2651,48 @@ parameters and command options."
     (if (not (null sql-sqlite-options))
 	(setq params (append sql-sqlite-options params)))
     (set-buffer (apply 'make-comint "SQL" sql-sqlite-program
-		       nil params))))
+                       nil params))))
+
+
+
+;;;###autoload
+(defun sql-hive ()
+  "Run hive as an inferior process.
+
+Hive is free software.
+
+If buffer `*SQL*' exists but no process is running, make a new process.
+If buffer exists and a process is running, just switch to buffer
+`*SQL*'.
+
+Interpreter used comes from variable
+`sql-hive-program'. Additional command line parameters can be
+stored in the list `sql-hive-options'.
+
+The buffer is put in sql-interactive-mode, giving commands for sending
+input.  See `sql-interactive-mode'.
+
+To specify a coding system for converting non-ASCII characters
+in the input and output to the process, use \\[universal-coding-system-argument]
+before \\[sql-hive].  You can also specify this with \\[set-buffer-process-coding-system]
+in the SQL buffer, after you start the process.
+The default comes from `process-coding-system-alist' and
+`default-process-coding-system'.
+
+\(Type \\[describe-mode] in the SQL buffer for a list of commands.)"
+  (interactive)
+  (sql-product-interactive 'hive))
+
+(defun sql-connect-hive ()
+  "Create comint buffer and connect to Hive using the login
+parameters and command options."
+  ;; Put all parameters to the program (if defined) in a list and call
+  ;; make-comint.
+  (let ((params))
+    (if (not (null sql-hive-options))
+        (setq params (append sql-hive-options params)))
+    (set-buffer (apply 'make-comint "SQL" sql-hive-program
+                       nil params))))
 
 
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.