forked from googleapis/google-cloud-ruby
-
Notifications
You must be signed in to change notification settings - Fork 2
/
load_job.rb
1923 lines (1824 loc) · 76.6 KB
/
load_job.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2015 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require "google/cloud/bigquery/service"
require "google/cloud/bigquery/encryption_configuration"
module Google
module Cloud
module Bigquery
##
# # LoadJob
#
# A {Job} subclass representing a load operation that may be performed
# on a {Table}. A LoadJob instance is created when you call
# {Table#load_job}.
#
# @see https://cloud.google.com/bigquery/loading-data
# Loading Data Into BigQuery
# @see https://cloud.google.com/bigquery/docs/reference/v2/jobs Jobs API
# reference
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# dataset = bigquery.dataset "my_dataset"
#
# gcs_uri = "gs://my-bucket/file-name.csv"
# load_job = dataset.load_job "my_new_table", gcs_uri do |schema|
# schema.string "first_name", mode: :required
# schema.record "cities_lived", mode: :repeated do |nested_schema|
# nested_schema.string "place", mode: :required
# nested_schema.integer "number_of_years", mode: :required
# end
# end
#
# load_job.wait_until_done!
# load_job.done? #=> true
#
#
class LoadJob < Job
##
# The URI or URIs representing the Google Cloud Storage files from which
# the operation loads data.
def sources
Array @gapi.configuration.load.source_uris
end
##
# The table into which the operation loads data. This is the table on
# which {Table#load_job} was invoked.
#
# @return [Table] A table instance.
#
def destination
table = @gapi.configuration.load.destination_table
return nil unless table
retrieve_table table.project_id, table.dataset_id, table.table_id
end
##
# The delimiter used between fields in the source data. The default is a
# comma (,).
#
# @return [String] A string containing the character, such as `","`.
#
def delimiter
@gapi.configuration.load.field_delimiter || ","
end
##
# The number of rows at the top of a CSV file that BigQuery will skip
# when loading the data. The default value is 0. This property is useful
# if you have header rows in the file that should be skipped.
#
# @return [Integer] The number of header rows at the top of a CSV file
# to skip.
#
def skip_leading_rows
@gapi.configuration.load.skip_leading_rows || 0
end
##
# Checks if the character encoding of the data is UTF-8. This is the
# default.
#
# @return [Boolean] `true` when the character encoding is UTF-8,
# `false` otherwise.
#
def utf8?
val = @gapi.configuration.load.encoding
return true if val.nil?
val == "UTF-8"
end
##
# Checks if the character encoding of the data is ISO-8859-1.
#
# @return [Boolean] `true` when the character encoding is ISO-8859-1,
# `false` otherwise.
#
def iso8859_1?
@gapi.configuration.load.encoding == "ISO-8859-1"
end
##
# The value that is used to quote data sections in a CSV file. The
# default value is a double-quote (`"`). If your data does not contain
# quoted sections, the value should be an empty string. If your data
# contains quoted newline characters, {#quoted_newlines?} should return
# `true`.
#
# @return [String] A string containing the character, such as `"\""`.
#
def quote
val = @gapi.configuration.load.quote
val = "\"" if val.nil?
val
end
##
# The maximum number of bad records that the load operation can ignore.
# If the number of bad records exceeds this value, an error is returned.
# The default value is `0`, which requires that all records be valid.
#
# @return [Integer] The maximum number of bad records.
#
def max_bad_records
val = @gapi.configuration.load.max_bad_records
val = 0 if val.nil?
val
end
##
# Specifies a string that represents a null value in a CSV file. For
# example, if you specify `\N`, BigQuery interprets `\N` as a null value
# when loading a CSV file. The default value is the empty string. If you
# set this property to a custom value, BigQuery throws an error if an
# empty string is present for all data types except for STRING and BYTE.
# For STRING and BYTE columns, BigQuery interprets the empty string as
# an empty value.
#
# @return [String] A string representing null value in a CSV file.
#
def null_marker
val = @gapi.configuration.load.null_marker
val = "" if val.nil?
val
end
##
# Checks if quoted data sections may contain newline characters in a CSV
# file. The default is `false`.
#
# @return [Boolean] `true` when quoted newlines are allowed, `false`
# otherwise.
#
def quoted_newlines?
val = @gapi.configuration.load.allow_quoted_newlines
val = false if val.nil?
val
end
##
# Checks if BigQuery should automatically infer the options and schema
# for CSV and JSON sources. The default is `false`.
#
# @return [Boolean] `true` when autodetect is enabled, `false`
# otherwise.
#
def autodetect?
val = @gapi.configuration.load.autodetect
val = false if val.nil?
val
end
##
# Checks if the format of the source data is [newline-delimited
# JSON](http://jsonlines.org/). The default is `false`.
#
# @return [Boolean] `true` when the source format is
# `NEWLINE_DELIMITED_JSON`, `false` otherwise.
#
def json?
@gapi.configuration.load.source_format == "NEWLINE_DELIMITED_JSON"
end
##
# Checks if the format of the source data is CSV. The default is `true`.
#
# @return [Boolean] `true` when the source format is `CSV`, `false`
# otherwise.
#
def csv?
val = @gapi.configuration.load.source_format
return true if val.nil?
val == "CSV"
end
##
# Checks if the source data is a Google Cloud Datastore backup.
#
# @return [Boolean] `true` when the source format is `DATASTORE_BACKUP`,
# `false` otherwise.
#
def backup?
@gapi.configuration.load.source_format == "DATASTORE_BACKUP"
end
##
# Checks if the source format is ORC.
#
# @return [Boolean] `true` when the source format is `ORC`,
# `false` otherwise.
#
def orc?
@gapi.configuration.load.source_format == "ORC"
end
##
# Checks if the source format is Parquet.
#
# @return [Boolean] `true` when the source format is `PARQUET`,
# `false` otherwise.
#
def parquet?
@gapi.configuration.load.source_format == "PARQUET"
end
##
# Checks if the load operation accepts rows that are missing trailing
# optional columns. The missing values are treated as nulls. If `false`,
# records with missing trailing columns are treated as bad records, and
# if there are too many bad records, an error is returned. The default
# value is `false`. Only applicable to CSV, ignored for other formats.
#
# @return [Boolean] `true` when jagged rows are allowed, `false`
# otherwise.
#
def allow_jagged_rows?
val = @gapi.configuration.load.allow_jagged_rows
val = false if val.nil?
val
end
##
# Checks if the load operation allows extra values that are not
# represented in the table schema. If `true`, the extra values are
# ignored. If `false`, records with extra columns are treated as bad
# records, and if there are too many bad records, an invalid error is
# returned. The default is `false`.
#
# @return [Boolean] `true` when unknown values are ignored, `false`
# otherwise.
#
def ignore_unknown_values?
val = @gapi.configuration.load.ignore_unknown_values
val = false if val.nil?
val
end
##
# The schema for the destination table. The schema can be omitted if the
# destination table already exists, or if you're loading data from
# Google Cloud Datastore.
#
# The returned object is frozen and changes are not allowed. Use
# {Table#schema} to update the schema.
#
# @return [Schema, nil] A schema object, or `nil`.
#
def schema
Schema.from_gapi(@gapi.configuration.load.schema).freeze
end
##
# Allows the schema of the destination table to be updated as a side
# effect of the load job if a schema is autodetected or supplied in the
# job configuration. Schema update options are supported in two cases:
# when write disposition is `WRITE_APPEND`; when write disposition is
# `WRITE_TRUNCATE` and the destination table is a partition of a table,
# specified by partition decorators. For normal tables, `WRITE_TRUNCATE`
# will always overwrite the schema. One or more of the following values
# are specified:
#
# * `ALLOW_FIELD_ADDITION`: allow adding a nullable field to the schema.
# * `ALLOW_FIELD_RELAXATION`: allow relaxing a required field in the
# original schema to nullable.
#
# @return [Array<String>] An array of strings.
#
def schema_update_options
Array @gapi.configuration.load.schema_update_options
end
##
# The number of source data files in the load job.
#
# @return [Integer] The number of source files.
#
def input_files
Integer @gapi.statistics.load.input_files
rescue StandardError
nil
end
##
# The number of bytes of source data in the load job.
#
# @return [Integer] The number of bytes.
#
def input_file_bytes
Integer @gapi.statistics.load.input_file_bytes
rescue StandardError
nil
end
##
# The number of rows that have been loaded into the table. While an
# import job is in the running state, this value may change.
#
# @return [Integer] The number of rows that have been loaded.
#
def output_rows
Integer @gapi.statistics.load.output_rows
rescue StandardError
nil
end
##
# The encryption configuration of the destination table.
#
# @return [Google::Cloud::BigQuery::EncryptionConfiguration] Custom
# encryption configuration (e.g., Cloud KMS keys).
#
# @!group Attributes
def encryption
EncryptionConfiguration.from_gapi(
@gapi.configuration.load.destination_encryption_configuration
)
end
##
# The number of bytes that have been loaded into the table. While an
# import job is in the running state, this value may change.
#
# @return [Integer] The number of bytes that have been loaded.
#
def output_bytes
Integer @gapi.statistics.load.output_bytes
rescue StandardError
nil
end
###
# Checks if hive partitioning options are set.
#
# @see https://cloud.google.com/bigquery/docs/hive-partitioned-loads-gcs Loading externally partitioned data
#
# @return [Boolean] `true` when hive partitioning options are set, or `false` otherwise.
#
# @!group Attributes
#
def hive_partitioning?
!@gapi.configuration.load.hive_partitioning_options.nil?
end
###
# The mode of hive partitioning to use when reading data. The following modes are supported:
#
# 1. `AUTO`: automatically infer partition key name(s) and type(s).
# 2. `STRINGS`: automatically infer partition key name(s). All types are interpreted as strings.
# 3. `CUSTOM`: partition key schema is encoded in the source URI prefix.
#
# @see https://cloud.google.com/bigquery/docs/hive-partitioned-loads-gcs Loading externally partitioned data
#
# @return [String, nil] The mode of hive partitioning, or `nil` if not set.
#
# @!group Attributes
#
def hive_partitioning_mode
@gapi.configuration.load.hive_partitioning_options.mode if hive_partitioning?
end
###
# The common prefix for all source uris when hive partition detection is requested. The prefix must end
# immediately before the partition key encoding begins. For example, consider files following this data layout:
#
# ```
# gs://bucket/path_to_table/dt=2019-01-01/country=BR/id=7/file.avro
# gs://bucket/path_to_table/dt=2018-12-31/country=CA/id=3/file.avro
# ```
#
# When hive partitioning is requested with either `AUTO` or `STRINGS` mode, the common prefix can be either of
# `gs://bucket/path_to_table` or `gs://bucket/path_to_table/` (trailing slash does not matter).
#
# @see https://cloud.google.com/bigquery/docs/hive-partitioned-loads-gcs Loading externally partitioned data
#
# @return [String, nil] The common prefix for all source uris, or `nil` if not set.
#
# @!group Attributes
#
def hive_partitioning_source_uri_prefix
@gapi.configuration.load.hive_partitioning_options.source_uri_prefix if hive_partitioning?
end
###
# Checks if the destination table will be range partitioned. See [Creating and using integer range partitioned
# tables](https://cloud.google.com/bigquery/docs/creating-integer-range-partitions).
#
# @return [Boolean] `true` when the table is range partitioned, or `false` otherwise.
#
# @!group Attributes
#
def range_partitioning?
!@gapi.configuration.load.range_partitioning.nil?
end
###
# The field on which the destination table will be range partitioned, if any. The field must be a
# top-level `NULLABLE/REQUIRED` field. The only supported type is `INTEGER/INT64`. See
# [Creating and using integer range partitioned
# tables](https://cloud.google.com/bigquery/docs/creating-integer-range-partitions).
#
# @return [String, nil] The partition field, if a field was configured, or `nil` if not range partitioned.
#
# @!group Attributes
#
def range_partitioning_field
@gapi.configuration.load.range_partitioning.field if range_partitioning?
end
###
# The start of range partitioning, inclusive. See [Creating and using integer range partitioned
# tables](https://cloud.google.com/bigquery/docs/creating-integer-range-partitions).
#
# @return [Integer, nil] The start of range partitioning, inclusive, or `nil` if not range partitioned.
#
# @!group Attributes
#
def range_partitioning_start
@gapi.configuration.load.range_partitioning.range.start if range_partitioning?
end
###
# The width of each interval. See [Creating and using integer range partitioned
# tables](https://cloud.google.com/bigquery/docs/creating-integer-range-partitions).
#
# @return [Integer, nil] The width of each interval, for data in range partitions, or `nil` if not range
# partitioned.
#
# @!group Attributes
#
def range_partitioning_interval
return nil unless range_partitioning?
@gapi.configuration.load.range_partitioning.range.interval
end
###
# The end of range partitioning, exclusive. See [Creating and using integer range partitioned
# tables](https://cloud.google.com/bigquery/docs/creating-integer-range-partitions).
#
# @return [Integer, nil] The end of range partitioning, exclusive, or `nil` if not range partitioned.
#
# @!group Attributes
#
def range_partitioning_end
@gapi.configuration.load.range_partitioning.range.end if range_partitioning?
end
###
# Checks if the destination table will be time partitioned. See
# [Partitioned Tables](https://cloud.google.com/bigquery/docs/partitioned-tables).
#
# @return [Boolean, nil] `true` when the table will be time-partitioned,
# or `false` otherwise.
#
# @!group Attributes
#
def time_partitioning?
!@gapi.configuration.load.time_partitioning.nil?
end
###
# The period for which the destination table will be time partitioned, if
# any. See [Partitioned Tables](https://cloud.google.com/bigquery/docs/partitioned-tables).
#
# @return [String, nil] The time partition type. The supported types are `DAY`,
# `HOUR`, `MONTH`, and `YEAR`, which will generate one partition per day,
# hour, month, and year, respectively; or `nil` if not present.
#
# @!group Attributes
#
def time_partitioning_type
@gapi.configuration.load.time_partitioning.type if time_partitioning?
end
###
# The field on which the destination table will be time partitioned, if any.
# If not set, the destination table will be time partitioned by pseudo column
# `_PARTITIONTIME`; if set, the table will be time partitioned by this field.
# See [Partitioned Tables](https://cloud.google.com/bigquery/docs/partitioned-tables).
#
# @return [String, nil] The time partition field, if a field was configured.
# `nil` if not time partitioned or not set (partitioned by pseudo column
# '_PARTITIONTIME').
#
# @!group Attributes
#
def time_partitioning_field
@gapi.configuration.load.time_partitioning.field if time_partitioning?
end
###
# The expiration for the destination table time partitions, if any, in
# seconds. See [Partitioned
# Tables](https://cloud.google.com/bigquery/docs/partitioned-tables).
#
# @return [Integer, nil] The expiration time, in seconds, for data in
# time partitions, or `nil` if not present.
#
# @!group Attributes
#
def time_partitioning_expiration
return nil unless time_partitioning?
return nil if @gapi.configuration.load.time_partitioning.expiration_ms.nil?
@gapi.configuration.load.time_partitioning.expiration_ms / 1_000
end
###
# If set to true, queries over the destination table will require a
# time partition filter that can be used for partition elimination to be
# specified. See [Partitioned
# Tables](https://cloud.google.com/bigquery/docs/partitioned-tables).
#
# @return [Boolean] `true` when a time partition filter will be required,
# or `false` otherwise.
#
# @!group Attributes
#
def time_partitioning_require_filter?
tp = @gapi.configuration.load.time_partitioning
return false if tp.nil? || tp.require_partition_filter.nil?
tp.require_partition_filter
end
###
# Checks if the destination table will be clustered.
#
# See {LoadJob::Updater#clustering_fields=}, {Table#clustering_fields} and
# {Table#clustering_fields=}.
#
# @see https://cloud.google.com/bigquery/docs/clustered-tables
# Introduction to clustered tables
# @see https://cloud.google.com/bigquery/docs/creating-clustered-tables
# Creating and using clustered tables
#
# @return [Boolean, nil] `true` when the table will be clustered,
# or `false` otherwise.
#
# @!group Attributes
#
def clustering?
!@gapi.configuration.load.clustering.nil?
end
###
# One or more fields on which the destination table should be clustered.
# Must be specified with time-based partitioning, data in the table will
# be first partitioned and subsequently clustered. The order of the
# returned fields determines the sort order of the data.
#
# BigQuery supports clustering for both partitioned and non-partitioned
# tables.
#
# See {LoadJob::Updater#clustering_fields=}, {Table#clustering_fields} and
# {Table#clustering_fields=}.
#
# @see https://cloud.google.com/bigquery/docs/clustered-tables
# Introduction to clustered tables
# @see https://cloud.google.com/bigquery/docs/creating-clustered-tables
# Creating and using clustered tables
#
# @return [Array<String>, nil] The clustering fields, or `nil` if the
# destination table will not be clustered.
#
# @!group Attributes
#
def clustering_fields
@gapi.configuration.load.clustering.fields if clustering?
end
##
# Yielded to a block to accumulate changes for a patch request.
class Updater < LoadJob
##
# A list of attributes that were updated.
attr_reader :updates
##
# @private Create an Updater object.
def initialize gapi
super()
@updates = []
@gapi = gapi
@schema = nil
end
##
# Returns the table's schema. This method can also be used to set,
# replace, or add to the schema by passing a block. See {Schema} for
# available methods.
#
# @param [Boolean] replace Whether to replace the existing schema with
# the new schema. If `true`, the fields will replace the existing
# schema. If `false`, the fields will be added to the existing
# schema. When a table already contains data, schema changes must be
# additive. Thus, the default value is `false`.
# @yield [schema] a block for setting the schema
# @yieldparam [Schema] schema the object accepting the schema
#
# @return [Google::Cloud::Bigquery::Schema]
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# dataset = bigquery.dataset "my_dataset"
# job = dataset.load_job "my_table", "gs://abc/file" do |j|
# j.schema do |s|
# s.string "first_name", mode: :required
# s.record "cities_lived", mode: :repeated do |r|
# r.string "place", mode: :required
# r.integer "number_of_years", mode: :required
# end
# end
# end
#
# @!group Schema
#
def schema replace: false
# Same as Table#schema, but not frozen
# TODO: make sure to call ensure_full_data! on Dataset#update
@schema ||= Schema.from_gapi @gapi.configuration.load.schema
if block_given?
@schema = Schema.from_gapi if replace
yield @schema
check_for_mutated_schema!
end
# Do not freeze on updater, allow modifications
@schema
end
##
# Sets the schema of the destination table.
#
# @param [Google::Cloud::Bigquery::Schema] new_schema The schema for
# the destination table. Optional. The schema can be omitted if the
# destination table already exists, or if you're loading data from a
# source that includes a schema, such as Avro or a Google Cloud
# Datastore backup.
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# schema = bigquery.schema do |s|
# s.string "first_name", mode: :required
# s.record "cities_lived", mode: :repeated do |nested_schema|
# nested_schema.string "place", mode: :required
# nested_schema.integer "number_of_years", mode: :required
# end
# end
# dataset = bigquery.dataset "my_dataset"
# job = dataset.load_job "my_table", "gs://abc/file" do |j|
# j.schema = schema
# end
#
# @!group Schema
#
def schema= new_schema
@schema = new_schema
end
##
# Adds a string field to the schema.
#
# See {Schema#string}.
#
# @param [String] name The field name. The name must contain only
# letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
# start with a letter or underscore. The maximum length is 128
# characters.
# @param [String] description A description of the field.
# @param [Symbol] mode The field's mode. The possible values are
# `:nullable`, `:required`, and `:repeated`. The default value is
# `:nullable`.
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# dataset = bigquery.dataset "my_dataset"
# job = dataset.load_job "my_table", "gs://abc/file" do |schema|
# schema.string "first_name", mode: :required
# end
#
# @!group Schema
def string name, description: nil, mode: :nullable
schema.string name, description: description, mode: mode
end
##
# Adds an integer field to the schema.
#
# See {Schema#integer}.
#
# @param [String] name The field name. The name must contain only
# letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
# start with a letter or underscore. The maximum length is 128
# characters.
# @param [String] description A description of the field.
# @param [Symbol] mode The field's mode. The possible values are
# `:nullable`, `:required`, and `:repeated`. The default value is
# `:nullable`.
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# dataset = bigquery.dataset "my_dataset"
# job = dataset.load_job "my_table", "gs://abc/file" do |schema|
# schema.integer "age", mode: :required
# end
#
# @!group Schema
def integer name, description: nil, mode: :nullable
schema.integer name, description: description, mode: mode
end
##
# Adds a floating-point number field to the schema.
#
# See {Schema#float}.
#
# @param [String] name The field name. The name must contain only
# letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
# start with a letter or underscore. The maximum length is 128
# characters.
# @param [String] description A description of the field.
# @param [Symbol] mode The field's mode. The possible values are
# `:nullable`, `:required`, and `:repeated`. The default value is
# `:nullable`.
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# dataset = bigquery.dataset "my_dataset"
# job = dataset.load_job "my_table", "gs://abc/file" do |schema|
# schema.float "price", mode: :required
# end
#
# @!group Schema
def float name, description: nil, mode: :nullable
schema.float name, description: description, mode: mode
end
##
# Adds a numeric number field to the schema. `NUMERIC` is a decimal
# type with fixed precision and scale. Precision is the number of
# digits that the number contains. Scale is how many of these
# digits appear after the decimal point. It supports:
#
# Precision: 38
# Scale: 9
# Min: -9.9999999999999999999999999999999999999E+28
# Max: 9.9999999999999999999999999999999999999E+28
#
# This type can represent decimal fractions exactly, and is suitable
# for financial calculations.
#
# See {Schema#numeric}
#
# @param [String] name The field name. The name must contain only
# letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
# start with a letter or underscore. The maximum length is 128
# characters.
# @param [String] description A description of the field.
# @param [Symbol] mode The field's mode. The possible values are
# `:nullable`, `:required`, and `:repeated`. The default value is
# `:nullable`.
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# dataset = bigquery.dataset "my_dataset"
# job = dataset.load_job "my_table", "gs://abc/file" do |schema|
# schema.numeric "total_cost", mode: :required
# end
#
# @!group Schema
def numeric name, description: nil, mode: :nullable
schema.numeric name, description: description, mode: mode
end
##
# Adds a bignumeric number field to the schema. `BIGNUMERIC` is a
# decimal type with fixed precision and scale. Precision is the
# number of digits that the number contains. Scale is how many of
# these digits appear after the decimal point. It supports:
#
# Precision: 76.76 (the 77th digit is partial)
# Scale: 38
# Min: -5.7896044618658097711785492504343953926634992332820282019728792003956564819968E+38
# Max: 5.7896044618658097711785492504343953926634992332820282019728792003956564819967E+38
#
# This type can represent decimal fractions exactly, and is suitable
# for financial calculations.
#
# See {Schema#bignumeric}
#
# @param [String] name The field name. The name must contain only
# letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
# start with a letter or underscore. The maximum length is 128
# characters.
# @param [String] description A description of the field.
# @param [Symbol] mode The field's mode. The possible values are
# `:nullable`, `:required`, and `:repeated`. The default value is
# `:nullable`.
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# dataset = bigquery.dataset "my_dataset"
# job = dataset.load_job "my_table", "gs://abc/file" do |schema|
# schema.bignumeric "total_cost", mode: :required
# end
#
# @!group Schema
def bignumeric name, description: nil, mode: :nullable
schema.bignumeric name, description: description, mode: mode
end
##
# Adds a boolean field to the schema.
#
# See {Schema#boolean}.
#
# @param [String] name The field name. The name must contain only
# letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
# start with a letter or underscore. The maximum length is 128
# characters.
# @param [String] description A description of the field.
# @param [Symbol] mode The field's mode. The possible values are
# `:nullable`, `:required`, and `:repeated`. The default value is
# `:nullable`.
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# dataset = bigquery.dataset "my_dataset"
# job = dataset.load_job "my_table", "gs://abc/file" do |schema|
# schema.boolean "active", mode: :required
# end
#
# @!group Schema
def boolean name, description: nil, mode: :nullable
schema.boolean name, description: description, mode: mode
end
##
# Adds a bytes field to the schema.
#
# See {Schema#bytes}.
#
# @param [String] name The field name. The name must contain only
# letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
# start with a letter or underscore. The maximum length is 128
# characters.
# @param [String] description A description of the field.
# @param [Symbol] mode The field's mode. The possible values are
# `:nullable`, `:required`, and `:repeated`. The default value is
# `:nullable`.
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# dataset = bigquery.dataset "my_dataset"
# job = dataset.load_job "my_table", "gs://abc/file" do |schema|
# schema.bytes "avatar", mode: :required
# end
#
# @!group Schema
def bytes name, description: nil, mode: :nullable
schema.bytes name, description: description, mode: mode
end
##
# Adds a timestamp field to the schema.
#
# See {Schema#timestamp}.
#
# @param [String] name The field name. The name must contain only
# letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
# start with a letter or underscore. The maximum length is 128
# characters.
# @param [String] description A description of the field.
# @param [Symbol] mode The field's mode. The possible values are
# `:nullable`, `:required`, and `:repeated`. The default value is
# `:nullable`.
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# dataset = bigquery.dataset "my_dataset"
# job = dataset.load_job "my_table", "gs://abc/file" do |schema|
# schema.timestamp "creation_date", mode: :required
# end
#
# @!group Schema
def timestamp name, description: nil, mode: :nullable
schema.timestamp name, description: description, mode: mode
end
##
# Adds a time field to the schema.
#
# See {Schema#time}.
#
# @param [String] name The field name. The name must contain only
# letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
# start with a letter or underscore. The maximum length is 128
# characters.
# @param [String] description A description of the field.
# @param [Symbol] mode The field's mode. The possible values are
# `:nullable`, `:required`, and `:repeated`. The default value is
# `:nullable`.
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# dataset = bigquery.dataset "my_dataset"
# job = dataset.load_job "my_table", "gs://abc/file" do |schema|
# schema.time "duration", mode: :required
# end
#
# @!group Schema
def time name, description: nil, mode: :nullable
schema.time name, description: description, mode: mode
end
##
# Adds a datetime field to the schema.
#
# See {Schema#datetime}.
#
# @param [String] name The field name. The name must contain only
# letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
# start with a letter or underscore. The maximum length is 128
# characters.
# @param [String] description A description of the field.
# @param [Symbol] mode The field's mode. The possible values are
# `:nullable`, `:required`, and `:repeated`. The default value is
# `:nullable`.
#
# @example
# require "google/cloud/bigquery"
#
# bigquery = Google::Cloud::Bigquery.new
# dataset = bigquery.dataset "my_dataset"
# job = dataset.load_job "my_table", "gs://abc/file" do |schema|
# schema.datetime "target_end", mode: :required
# end
#
# @!group Schema
def datetime name, description: nil, mode: :nullable
schema.datetime name, description: description, mode: mode
end
##