hexspace 0.2.0 → 0.2.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: 22ba7e18e6dec1e5c97403f0fc8ce08580309f750058137576c51208da225ee4
4
- data.tar.gz: 3cc3bd22042aac858407961d5ef71eaa820f6c96381442b694f2cc8e9808f318
3
+ metadata.gz: b01d38959d851e6e96d16a2230b62e6f659089f855307959a4c27585c32a6550
4
+ data.tar.gz: 5515be12059303b0e6ee12222caf04896ec8c79b23ffe519b8e9f213f957e257
5
5
  SHA512:
6
- metadata.gz: e158652968097ceb7590d26a6523a43525316991a60e122e02d911959938652864442ade94d751ba834eb43b09311ad7da243b7995e7e27be8e2b7277d85b887
7
- data.tar.gz: 22b6218778f4b8b62575ab2da576da126671867033a0c35e8963147f84ac000b77910699b30923c10236e335217382543176f8fe1201db281d556ca47a7145f4
6
+ metadata.gz: 7cbfb5be0c692cae31a82b7fc9a817ea443b13549ad92d73ac3d40db371b3ecdba0cc2f7f73dec9407043d5938f00519e6cdc40f990cb9b1cd1c82e544c44e54
7
+ data.tar.gz: 43fd8714dd9126d3a51246ed7f500a4da7640f2d72c039ea511dfccbd0799bb4103492eccf87ed03ea4dae09eb64c79b20a797e25d84c248596b47319a85f3d8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.2.1 (2023-11-12)
2
+
3
+ - Added `result_object` option
4
+
1
5
  ## 0.2.0 (2023-05-07)
2
6
 
3
7
  - Fixed error with Spark 3.4.0
data/README.md CHANGED
@@ -46,6 +46,24 @@ Supported modes are `:sasl`, `:nosasl`, `:http`, and `:https`. Please create an
46
46
 
47
47
  The timeout is in seconds and only applies to `:sasl` and `:nosasl`.
48
48
 
49
+ ## Query Options
50
+
51
+ Set a timeout
52
+
53
+ ```ruby
54
+ client.execute(statement, timeout: 10)
55
+ ```
56
+
57
+ Get a `Hexspace::Result` object instead of an array of hashes
58
+
59
+ ```ruby
60
+ result = client.execute(statement, result_object: true)
61
+ result.rows
62
+ result.columns
63
+ result.column_types
64
+ result.to_a
65
+ ```
66
+
49
67
  ## Spark SQL Setup
50
68
 
51
69
  Download [Apache Spark](https://spark.apache.org/downloads.html) and start the [Thift server](https://spark.apache.org/docs/latest/sql-distributed-sql-engine.html).
@@ -48,12 +48,12 @@ module Hexspace
48
48
  ObjectSpace.define_finalizer(self, self.class.finalize(@transport, @client, @session))
49
49
  end
50
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
54
- def execute(statement, timeout: nil)
51
+ def execute(statement, timeout: nil, result_object: false)
55
52
  result = execute_statement(statement, timeout: timeout)
56
- process_result(result) if result.operationHandle.hasResultSet
53
+ if result.operationHandle.hasResultSet
54
+ result = process_result(result)
55
+ result_object ? result : result.to_a
56
+ end
57
57
  end
58
58
 
59
59
  # private
@@ -113,7 +113,7 @@ module Hexspace
113
113
  if j == 0
114
114
  new_rows = value.values.size
115
115
  new_rows.times do
116
- rows << {}
116
+ rows << []
117
117
  end
118
118
  end
119
119
 
@@ -130,17 +130,17 @@ module Hexspace
130
130
  # end
131
131
  when "date"
132
132
  values.each do |v|
133
- rows[offset][name] = nulls[offset] == "1" ? nil : Date.parse(v)
133
+ rows[offset][j] = nulls[offset] == "1" ? nil : Date.parse(v)
134
134
  offset += 1
135
135
  end
136
136
  when "decimal"
137
137
  values.each do |v|
138
- rows[offset][name] = nulls[offset] == "1" ? nil : BigDecimal(v)
138
+ rows[offset][j] = nulls[offset] == "1" ? nil : BigDecimal(v)
139
139
  offset += 1
140
140
  end
141
141
  else
142
142
  values.each do |v|
143
- rows[offset][name] = nulls[offset] == "1" ? nil : v
143
+ rows[offset][j] = nulls[offset] == "1" ? nil : v
144
144
  offset += 1
145
145
  end
146
146
  end
@@ -153,7 +153,7 @@ module Hexspace
153
153
  req.operationHandle = stmt.operationHandle
154
154
  check_status client.CloseOperation(req)
155
155
 
156
- rows
156
+ Result.new(rows, columns, types)
157
157
  end
158
158
  end
159
159
  end
@@ -0,0 +1,17 @@
1
+ module Hexspace
2
+ class Result
3
+ attr_reader :rows, :columns, :column_types
4
+
5
+ def initialize(rows, columns, column_types)
6
+ @rows = rows
7
+ @columns = columns
8
+ @column_types = column_types
9
+ end
10
+
11
+ def to_a
12
+ @rows.map do |row|
13
+ @columns.zip(row).to_h
14
+ end
15
+ end
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module Hexspace
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/hexspace.rb CHANGED
@@ -12,6 +12,7 @@ require_relative "hexspace/tcli_service"
12
12
 
13
13
  # modules
14
14
  require_relative "hexspace/client"
15
+ require_relative "hexspace/result"
15
16
  require_relative "hexspace/sasl_transport"
16
17
  require_relative "hexspace/version"
17
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hexspace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-05-08 00:00:00.000000000 Z
11
+ date: 2023-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thrift
@@ -35,6 +35,7 @@ files:
35
35
  - README.md
36
36
  - lib/hexspace.rb
37
37
  - lib/hexspace/client.rb
38
+ - lib/hexspace/result.rb
38
39
  - lib/hexspace/sasl_transport.rb
39
40
  - lib/hexspace/tcli_service.rb
40
41
  - lib/hexspace/tcli_service_constants.rb