Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use json gem instead of oj #75

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ PATH
remote: .
specs:
rb_snowflake_client (1.1.3)
bigdecimal (>= 3.0)
concurrent-ruby (>= 1.2)
connection_pool (>= 2.4)
dotenv (>= 2.8)
json (>= 2.1.0)
jwt (>= 2.7)
oj (>= 3.16)
retryable (>= 3.0)

GEM
Expand All @@ -19,11 +20,10 @@ GEM
connection_pool (2.4.1)
diff-lcs (1.5.1)
dotenv (3.1.2)
json (2.9.1)
jwt (2.8.2)
base64
method_source (1.1.0)
oj (3.16.4)
bigdecimal (>= 3.0)
parallel (1.25.1)
pry (0.14.2)
coderay (~> 1.1)
Expand Down
12 changes: 6 additions & 6 deletions lib/ruby_snowflake/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

require "base64"
require "benchmark"
require "bigdecimal"
require "concurrent"
require "connection_pool"
require "json"
require "logger"
require "net/http"
require "oj"
require "retryable"
require "securerandom"
require "uri"
Expand Down Expand Up @@ -68,7 +68,7 @@ class Client
# how long to wait to allow a query to complete, in seconds
DEFAULT_QUERY_TIMEOUT = 600 # 10 minutes

OJ_OPTIONS = { :bigdecimal_load => :bigdecimal }.freeze
JSON_PARSE_OPTIONS = { decimal_class: BigDecimal }.freeze
VALID_RESPONSE_CODES = %w(200 202).freeze
POLLING_RESPONSE_CODE = "202"
POLLING_INTERVAL = 2 # seconds
Expand Down Expand Up @@ -166,7 +166,7 @@ def query(query, warehouse: nil, streaming: false, database: nil, schema: nil, b
connection,
Net::HTTP::Post,
"/api/v2/statements?requestId=#{SecureRandom.uuid}&async=#{@_enable_polling_queries}",
Oj.dump(request_body)
request_body.to_json
)
end
retrieve_result_set(query_start_time, query, response, streaming)
Expand Down Expand Up @@ -290,12 +290,12 @@ def attempt_to_cancel_and_silence_errors(connection, statement_handle)
end

def retrieve_result_set(query_start_time, query, response, streaming)
json_body = Oj.load(response.body, OJ_OPTIONS)
json_body = JSON.parse(response.body, JSON_PARSE_OPTIONS)
statement_handle = json_body["statementHandle"]

if response.code == POLLING_RESPONSE_CODE
result_response = poll_for_completion_or_timeout(query_start_time, query, statement_handle)
json_body = Oj.load(result_response.body, OJ_OPTIONS)
json_body = JSON.parse(result_response.body, JSON_PARSE_OPTIONS)
end

num_threads = number_of_threads_to_use(json_body["resultSetMetaData"]["partitionInfo"].size)
Expand All @@ -321,7 +321,7 @@ def retrieve_partition_data(statement_handle, partition_index)
end

partition_json = {}
bm = Benchmark.measure { partition_json = Oj.load(partition_response.body, OJ_OPTIONS) }
bm = Benchmark.measure { partition_json = JSON.parse(partition_response.body, JSON_PARSE_OPTIONS) }
logger.debug { "JSON parsing took: #{bm.real}" }
partition_data = partition_json["data"]

Expand Down
2 changes: 1 addition & 1 deletion lib/ruby_snowflake/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module RubySnowflake
VERSION = "1.1.5"
VERSION = "1.2.0"
end
3 changes: 2 additions & 1 deletion rb_snowflake_client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ Gem::Specification.new do |s|
end

s.require_paths = ["lib"]
s.add_dependency "bigdecimal", ">= 3.0"
s.add_dependency "concurrent-ruby", ">= 1.2"
s.add_dependency "connection_pool", ">= 2.4"
s.add_dependency "dotenv", ">= 2.8"
s.add_dependency "json", ">= 2.1.0"
s.add_dependency "jwt", ">= 2.7"
s.add_dependency "oj", ">= 3.16"
s.add_dependency "retryable", ">= 3.0"
end
Loading