hexspace 0.1.0 → 0.1.1

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: e6fed1043e747b39d0f3cac055db4944d36f18bfaa9acdb4fc88660ade262667
4
- data.tar.gz: a3355ff1add5cece58bc2b68914e34a2c5442f0c6f93e8f59612d0c327990b5f
3
+ metadata.gz: 46cb7c0c6c1d1839a2672e99b5daedfd952e0f31ef9fdeabe055f980c8f52aca
4
+ data.tar.gz: c16be8b8145beed444821a83b018f1d77a63db01947c1bdf6e34923bb64bc919
5
5
  SHA512:
6
- metadata.gz: 167a600cd3dd38e4659d1e6466ed0af80b3286571905777525355217c57fb3e6de1a837b38d2d6673b97758cf5c4a5b0d37fe760dc4ebd4cea4d69536758e9fc
7
- data.tar.gz: 6727b019ce070e47f1fc0244ac372e37b18dd3a319f21db038d1800fc0129a5c43b023a276afe9de8446266d2526669888a281fd4da9c0222f009abf79e432eb
6
+ metadata.gz: 2badf30752d561592c909ec3eb15b3967b0b551479563a1972742a310e5c5da297e8beb58626e14177ab894efc16645b74337bc6f64c3fd1afb80ed861fffcac
7
+ data.tar.gz: 92405d6ba47f7b3b5841250cc09638f4b44d487206a37f5dac1d8deb70ede1fb504a2635456a9e0c88a40b9e930840d6b0a8c76b4863bf658ea031ddd084dbca
@@ -1,3 +1,8 @@
1
+ ## 0.1.1 (2021-01-25)
2
+
3
+ - Improved typecasting
4
+ - Removed table prefix with Hive
5
+
1
6
  ## 0.1.0 (2021-01-24)
2
7
 
3
8
  - First release
data/README.md CHANGED
@@ -23,7 +23,7 @@ client = Hexspace::Client.new
23
23
  Execute queries
24
24
 
25
25
  ```ruby
26
- client.execute("SELECT 'world' AS hello")
26
+ client.execute("SELECT COUNT(*) FROM users")
27
27
  ```
28
28
 
29
29
  ## Connection Options
@@ -96,3 +96,9 @@ beeline -u jdbc:hive2://localhost:10000 -e 'CREATE DATABASE hexspace_test;'
96
96
  # run the tests
97
97
  bundle exec rake test
98
98
  ```
99
+
100
+ Resources
101
+
102
+ - [Spark SQL Reference](https://spark.apache.org/docs/latest/sql-ref.html)
103
+ - [Hive Language Manual](https://cwiki.apache.org/confluence/display/Hive/LanguageManual)
104
+ - [Thrift SASL Spec](https://github.com/apache/thrift/blob/master/doc/specs/thrift-sasl-spec.txt)
@@ -1,6 +1,10 @@
1
1
  # dependencies
2
2
  require "thrift"
3
3
 
4
+ # stdlib
5
+ require "bigdecimal"
6
+ require "time"
7
+
4
8
  # thrift
5
9
  require "hexspace/tcli_service_constants"
6
10
  require "hexspace/tcli_service_types"
@@ -36,18 +36,24 @@ module Hexspace
36
36
  @client = TCLIService::Client.new(protocol)
37
37
 
38
38
  req = TOpenSessionReq.new
39
- if database
40
- req.configuration = {"use:database" => database}
41
- end
39
+ configuration = {
40
+ # remove table prefix with Hive
41
+ "set:hiveconf:hive.resultset.use.unique.column.names" => "false"
42
+ }
43
+ configuration["use:database"] = database if database
44
+ req.configuration = configuration
42
45
  @session = @client.OpenSession(req)
43
46
  check_status @session
44
47
 
45
48
  ObjectSpace.define_finalizer(self, self.class.finalize(@transport, @client, @session))
46
49
  end
47
50
 
51
+ # TODO add new method that returns Result object
52
+ # so its possible to get duplicate columns
53
+ # as well as columns when there are no rows
48
54
  def execute(statement, timeout: nil)
49
55
  result = execute_statement(statement, timeout: timeout)
50
- process_result(result)
56
+ process_result(result) if result.operationHandle.hasResultSet
51
57
  end
52
58
 
53
59
  # private
@@ -87,6 +93,7 @@ module Hexspace
87
93
 
88
94
  rows = []
89
95
  columns = metadata.schema.columns.map(&:columnName)
96
+ types = metadata.schema.columns.map { |c| TYPE_NAMES[c.typeDesc.types.first.primitiveEntry.type].downcase }
90
97
 
91
98
  loop do
92
99
  req = TFetchResultsReq.new
@@ -111,9 +118,30 @@ module Hexspace
111
118
 
112
119
  offset = start_offset
113
120
  nulls = value.nulls.unpack1("b*")
114
- value.values.each do |v|
115
- rows[offset][name] = nulls[offset] == "1" ? nil : v
116
- offset += 1
121
+ values = value.values
122
+
123
+ case types[j]
124
+ # TODO decide how to handle time zones
125
+ # when "timestamp"
126
+ # values.each do |v|
127
+ # rows[offset][name] = nulls[offset] == "1" ? nil : Time.parse(v)
128
+ # offset += 1
129
+ # end
130
+ when "date"
131
+ values.each do |v|
132
+ rows[offset][name] = nulls[offset] == "1" ? nil : Date.parse(v)
133
+ offset += 1
134
+ end
135
+ when "decimal"
136
+ values.each do |v|
137
+ rows[offset][name] = nulls[offset] == "1" ? nil : BigDecimal(v)
138
+ offset += 1
139
+ end
140
+ else
141
+ values.each do |v|
142
+ rows[offset][name] = nulls[offset] == "1" ? nil : v
143
+ offset += 1
144
+ end
117
145
  end
118
146
  end
119
147
 
@@ -1,3 +1,3 @@
1
1
  module Hexspace
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hexspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane