Class: Google::Cloud::Bigquery::Schema
- Inherits:
 - 
      Object
      
        
- Object
 - Google::Cloud::Bigquery::Schema
 
 
- Defined in:
 - lib/google/cloud/bigquery/schema.rb,
lib/google/cloud/bigquery/schema/field.rb 
Overview
Table Schema
A builder for BigQuery table schemas, passed to block arguments to Dataset#create_table and Table#schema. Supports nested and repeated fields via a nested block.
Defined Under Namespace
Classes: Field
Instance Method Summary collapse
- 
  
    
      #boolean(name, description: nil, mode: :nullable)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Adds a boolean field to the schema.
 - 
  
    
      #bytes(name, description: nil, mode: :nullable)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Adds a bytes field to the schema.
 - 
  
    
      #date(name, description: nil, mode: :nullable)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Adds a date field to the schema.
 - 
  
    
      #datetime(name, description: nil, mode: :nullable)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Adds a datetime field to the schema.
 - 
  
    
      #empty?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Whether the schema has no fields defined.
 - 
  
    
      #field(name) {|f| ... } ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Retreive a fields by name.
 - 
  
    
      #fields  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
The fields of the table schema.
 - 
  
    
      #float(name, description: nil, mode: :nullable)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Adds a floating-point number field to the schema.
 - 
  
    
      #headers  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
The names of the fields as symbols.
 - 
  
    
      #integer(name, description: nil, mode: :nullable)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Adds an integer field to the schema.
 - 
  
    
      #record(name, description: nil, mode: nil) {|field| ... } ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Adds a record field to the schema.
 - 
  
    
      #string(name, description: nil, mode: :nullable)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Adds a string field to the schema.
 - 
  
    
      #time(name, description: nil, mode: :nullable)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Adds a time field to the schema.
 - 
  
    
      #timestamp(name, description: nil, mode: :nullable)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Adds a timestamp field to the schema.
 
Instance Method Details
#boolean(name, description: nil, mode: :nullable) ⇒ Object
Adds a boolean field to the schema.
      134 135 136  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 134 def boolean name, description: nil, mode: :nullable add_field name, :boolean, description: description, mode: mode end  | 
  
#bytes(name, description: nil, mode: :nullable) ⇒ Object
Adds a bytes field to the schema.
      149 150 151  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 149 def bytes name, description: nil, mode: :nullable add_field name, :bytes, description: description, mode: mode end  | 
  
#date(name, description: nil, mode: :nullable) ⇒ Object
Adds a date field to the schema.
      209 210 211  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 209 def date name, description: nil, mode: :nullable add_field name, :date, description: description, mode: mode end  | 
  
#datetime(name, description: nil, mode: :nullable) ⇒ Object
Adds a datetime field to the schema.
      194 195 196  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 194 def datetime name, description: nil, mode: :nullable add_field name, :datetime, description: description, mode: mode end  | 
  
#empty? ⇒ Boolean
Whether the schema has no fields defined.
      74 75 76  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 74 def empty? fields.empty? end  | 
  
#field(name) {|f| ... } ⇒ Object
Retreive a fields by name.
      65 66 67 68 69 70  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 65 def field name f = fields.find { |fld| fld.name == name.to_s } return nil if f.nil? yield f if block_given? f end  | 
  
#fields ⇒ Object
The fields of the table schema.
      49 50 51 52 53 54 55  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 49 def fields if frozen? Array(@gapi.fields).map { |f| Field.from_gapi(f).freeze }.freeze else Array(@gapi.fields).map { |f| Field.from_gapi f } end end  | 
  
#float(name, description: nil, mode: :nullable) ⇒ Object
Adds a floating-point number field to the schema.
      119 120 121  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 119 def float name, description: nil, mode: :nullable add_field name, :float, description: description, mode: mode end  | 
  
#headers ⇒ Object
The names of the fields as symbols.
      59 60 61  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 59 def headers fields.map(&:name).map(&:to_sym) end  | 
  
#integer(name, description: nil, mode: :nullable) ⇒ Object
Adds an integer field to the schema.
      104 105 106  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 104 def integer name, description: nil, mode: :nullable add_field name, :integer, description: description, mode: mode end  | 
  
#record(name, description: nil, mode: nil) {|field| ... } ⇒ Object
Adds a record field to the schema. A block must be passed describing the nested fields of the record. For more information about nested and repeated records, see Preparing Data for BigQuery .
      246 247 248 249 250 251 252 253 254  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 246 def record name, description: nil, mode: nil # TODO: do we need to fail if no block was given? fail ArgumentError, "a block is required" unless block_given? nested_field = add_field name, :record, description: description, mode: mode yield nested_field nested_field end  | 
  
#string(name, description: nil, mode: :nullable) ⇒ Object
Adds a string field to the schema.
      89 90 91  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 89 def string name, description: nil, mode: :nullable add_field name, :string, description: description, mode: mode end  | 
  
#time(name, description: nil, mode: :nullable) ⇒ Object
Adds a time field to the schema.
      179 180 181  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 179 def time name, description: nil, mode: :nullable add_field name, :time, description: description, mode: mode end  | 
  
#timestamp(name, description: nil, mode: :nullable) ⇒ Object
Adds a timestamp field to the schema.
      164 165 166  | 
    
      # File 'lib/google/cloud/bigquery/schema.rb', line 164 def name, description: nil, mode: :nullable add_field name, :timestamp, description: description, mode: mode end  |