in spanner/spanner_samples.rb [1950:1988]
def write_read_float64_array project_id:, instance_id:, database_id:
require "google/cloud/spanner"
require "google/cloud/spanner/admin/database"
require "securerandom"
database_admin_client = Google::Cloud::Spanner::Admin::Database.database_admin
db_path = database_admin_client.database_path project: project_id,
instance: instance_id,
database: database_id
job = database_admin_client.update_database_ddl database: db_path, statements: [
"CREATE TABLE Boxes (
BoxId STRING(36) NOT NULL,
Heights ARRAY<INT64>,
Weights ARRAY<FLOAT64>,
ErrorChecks ARRAY<BOOL>
) PRIMARY KEY (BoxId)"
]
job.wait_until_done!
spanner = Google::Cloud::Spanner.new project: project_id
client = spanner.client instance_id, database_id
box_id = SecureRandom.uuid
client.insert "Boxes", [{ BoxId: box_id, Weights: [10.001, 11.1212, 104.4123101] }]
results = client.read "Boxes", [:BoxId, :Weights], keys: box_id
results.rows.each do |row|
puts row["Weights"]
end
end