class Relationize::BqRelationizer

Constants

BQ_TS_FMT
CAST
DEFAULT_TYPES

Public Class Methods

to_text_literal(obj) click to toggle source
# File lib/relationize/bq_relationizer.rb, line 22
def self.to_text_literal(obj)
  obj.nil? ? 'NULL' : obj.to_s.gsub(/'/, "\\'").tap { |s| break "'#{s}'" }
end
to_timestamp_string(obj) click to toggle source
# File lib/relationize/bq_relationizer.rb, line 26
def self.to_timestamp_string(obj)
  to_text_literal(obj.is_a?(Time) ? obj.strftime(BQ_TS_FMT) : obj)
end

Public Instance Methods

to_row(((val, col), type)) click to toggle source
# File lib/relationize/bq_relationizer.rb, line 45
def to_row(((val, col), type))
  CAST[type][val, col]
end
to_s() click to toggle source
# File lib/relationize/bq_relationizer.rb, line 38
def to_s
  rows = @tuples.map { |tuple|
    "(SELECT #{tuple.zip(@columns).zip(oriented_types).map(&method(:to_row)).join(', ')})"
  }.join(', ')
  "SELECT * FROM (SELECT * FROM #{rows}) AS #{@name}"
end