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 +4 -4
- data/ChangeLog +13 -0
- data/README.md +1 -1
- data/lib/presto_sql_parser.rb +10 -1
- data/lib/presto_sql_parser/support_process.rb +7 -4
- data/lib/presto_sql_parser/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8b741335f41c8bc843227d596cf676fe8dd100416ac711c7fb1f07a2d88d56d4
|
4
|
+
data.tar.gz: e05a50a413fcbfb5a8f766230cca38b365e8dbd9da39dd3318b2f06e8f34aab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 598c067b8400698a8f98891d1613e3fce210dd74d89caee448c3893dec92b55a7a1a8bdfe59d1e922c0b674168ea5f667a149b9622ac83f230d0fa93fa9b2a6c
|
7
|
+
data.tar.gz: 7875622888caa489ddfc863a5a68fccb26cdf95610ecc46226d35f85ffe08b2aeec3e5460d8f564ef5057bb0a696c2ef5983bfcb1d83441b981ca0ac0edcee76
|
data/ChangeLog
ADDED
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
|
```
|
data/lib/presto_sql_parser.rb
CHANGED
@@ -10,9 +10,15 @@ class PrestoSqlParser
|
|
10
10
|
|
11
11
|
extend ClassMethods
|
12
12
|
|
13
|
-
self.java_cmd =
|
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')
|
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.
|
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
|