presto_sql_parser 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bcc623f7e4f77f063485f8eafd7fede9613dda7d12392477d1be5cf6ef998cbb
4
- data.tar.gz: 261c0520a92e6f5a85a3035385255e051afc103e57c29a3b31930e74ca811522
3
+ metadata.gz: 8b741335f41c8bc843227d596cf676fe8dd100416ac711c7fb1f07a2d88d56d4
4
+ data.tar.gz: e05a50a413fcbfb5a8f766230cca38b365e8dbd9da39dd3318b2f06e8f34aab2
5
5
  SHA512:
6
- metadata.gz: 73572412ca1bc6b2f467dd5dd7798fda5f8f77e3b4532454da3a879b172cb0523baa1e8be8c1a42c36d561bdfe34ae22826ca6a229dc743b269ec2a2018ef52c
7
- data.tar.gz: 1da0c97bcaea5cf0c35172db1b4d98fcb85939a0c958d611b4b048c1a0ecdf5e6bfd7f9790dc74fb055876ea80f3620d7891b7b3d018cc9c9d2daeae71a27fe8
6
+ metadata.gz: 598c067b8400698a8f98891d1613e3fce210dd74d89caee448c3893dec92b55a7a1a8bdfe59d1e922c0b674168ea5f667a149b9622ac83f230d0fa93fa9b2a6c
7
+ data.tar.gz: 7875622888caa489ddfc863a5a68fccb26cdf95610ecc46226d35f85ffe08b2aeec3e5460d8f564ef5057bb0a696c2ef5983bfcb1d83441b981ca0ac0edcee76
@@ -0,0 +1,13 @@
1
+
2
+ 2019-08-02 version 0.3.0:
3
+
4
+ * Added support for PRESTO_SQL_PARSER_JAVA env var
5
+
6
+ 2019-08-02 version 0.2.0:
7
+
8
+ * Fixed PrestoSqlParser.java_args to work
9
+
10
+ 2019-08-01 version 0.1.0:
11
+
12
+ * The first release
13
+
data/README.md CHANGED
@@ -79,7 +79,7 @@ p statements[1]['tokens']
79
79
  ## Options
80
80
 
81
81
  ```ruby
82
- PrestoSqlParser.java_cmd = "java" # java command
82
+ PrestoSqlParser.java_cmd = "java" # java command (default: PRESTO_SQL_PARSER_JAVA env var or "java")
83
83
  PrestoSqlParser.java_args = [] # command-line arguments of java_cmd
84
84
  PrestoSqlParser.java_env = {} # environment variables given to java_cmd
85
85
  ```
@@ -10,9 +10,15 @@ class PrestoSqlParser
10
10
 
11
11
  extend ClassMethods
12
12
 
13
- self.java_cmd = "java"
13
+ self.java_cmd = ENV['PRESTO_SQL_PARSER_JAVA']
14
+ if self.java_cmd == nil || self.java_cmd.strip.empty?
15
+ self.java_cmd = "java"
16
+ end
17
+
14
18
  self.java_args = []
19
+
15
20
  self.java_env = {}
21
+
16
22
  self.jar_path = File.join(File.dirname(__FILE__), "presto_sql_parser/presto-sql-parser.jar")
17
23
 
18
24
  class ParseError < StandardError
@@ -34,6 +40,9 @@ class PrestoSqlParser
34
40
  end
35
41
 
36
42
  def parse(sql)
43
+ unless sql.is_a?(String)
44
+ raise ArgumentError, "SQL must be a String but got #{sql.class}"
45
+ end
37
46
  request_line = JSON.dump({"sql" => sql})
38
47
 
39
48
  success = false
@@ -1,3 +1,5 @@
1
+ require 'shellwords'
2
+
1
3
  class PrestoSqlParser
2
4
  class SupportProcess
3
5
  def initialize(idle_wait: 2, with_tokens:)
@@ -12,13 +14,14 @@ class PrestoSqlParser
12
14
  def start!
13
15
  return if @pipe
14
16
 
15
- cmd =
17
+ cmd = (
16
18
  [PrestoSqlParser.java_cmd] +
17
- PrestoSqlParser.java_args +
18
- ["-jar", PrestoSqlParser.jar_path]
19
+ PrestoSqlParser.java_args.map {|arg| Shellwords.escape(arg) } +
20
+ ["-jar", Shellwords.escape(PrestoSqlParser.jar_path)]
21
+ ).join(' ')
19
22
 
20
23
  if @with_tokens
21
- cmd << "--with-tokens"
24
+ cmd << " --with-tokens"
22
25
  end
23
26
 
24
27
  @pipe = IO.popen(PrestoSqlParser.java_env, cmd, "r+", external_encoding: 'UTF-8')
@@ -1,3 +1,3 @@
1
1
  class PrestoSqlParser
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: presto_sql_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sadayuki Furuhashi
@@ -62,6 +62,7 @@ extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
64
  - ".gitignore"
65
+ - ChangeLog
65
66
  - Gemfile
66
67
  - LICENSE
67
68
  - README.md