Skip to content

Commit bd58490

Browse files
chore: Add integration test for JSON uploads over 5MB
1 parent 488c7dd commit bd58490

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

google-cloud-bigquery/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ gem "google-cloud-bigquery-connection-v1", ">= 1.3.0", "< 1.5"
2525
gem "google-cloud-data_catalog", path: "../google-cloud-data_catalog"
2626
gem "google-cloud-storage", path: "../google-cloud-storage"
2727
gem "google-style", "~> 1.30.1"
28+
gem "httpclient", "~> 2.8", group: :development
2829
gem "minitest", "~> 5.16"
2930
gem "minitest-autotest", "~> 1.0"
3031
gem "minitest-focus", "~> 1.1"
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
require "bigquery_helper"
16+
require "securerandom"
17+
require "json"
18+
require "httpclient"
19+
20+
describe "BigQuery Large JSON", :bigquery do
21+
let(:dataset_id) { "ruby_acceptance_#{SecureRandom.hex(4)}" }
22+
let(:dataset) do
23+
d = bigquery.dataset dataset_id
24+
if d.nil?
25+
d = bigquery.create_dataset dataset_id, location: "US"
26+
end
27+
d
28+
end
29+
let(:table_id) { "large_json_test_#{SecureRandom.hex(4)}" }
30+
let(:table) do
31+
t = dataset.table table_id
32+
if t.nil?
33+
t = dataset.create_table table_id do |schema|
34+
schema.string "id", mode: :required
35+
schema.json "data", mode: :required
36+
end
37+
end
38+
t
39+
end
40+
41+
after do
42+
dataset.delete force: true
43+
end
44+
45+
it "inserts a large JSON object successfully" do
46+
# Generate a 8MB JSON object
47+
large_string = "a" * (8 * 1024 * 1024)
48+
json_data = { "large_string" => large_string }.to_json
49+
puts "Generated JSON size: #{json_data.bytesize / (1024 * 1024)} MB"
50+
51+
row = { "id" => SecureRandom.uuid, "data" => json_data }
52+
53+
begin
54+
table.insert [row]
55+
rescue Google::Cloud::Error => e
56+
puts "Google::Cloud::Error encountered: #{e.message}"
57+
puts "Error body: #{e.body}"
58+
raise
59+
end
60+
end
61+
end

0 commit comments

Comments
 (0)