google-cloud-bigquery 1.42.0 → 1.43.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -263,6 +263,53 @@ module Google
263
263
  @gapi.update! policy_tags: policy_tag_list
264
264
  end
265
265
 
266
+ ##
267
+ # The default value of a field using a SQL expression. It can only
268
+ # be set for top level fields (columns). Default value for the entire struct or
269
+ # array is set using a struct or array expression. The valid SQL expressions are:
270
+ # - Literals for all data types, including STRUCT and ARRAY.
271
+ # - The following functions:
272
+ # `CURRENT_TIMESTAMP`
273
+ # `CURRENT_TIME`
274
+ # `CURRENT_DATE`
275
+ # `CURRENT_DATETIME`
276
+ # `GENERATE_UUID`
277
+ # `RAND`
278
+ # `SESSION_USER`
279
+ # `ST_GEOPOINT`
280
+ # - Struct or array composed with the above allowed functions, for example:
281
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
282
+ #
283
+ # @return [String] The default value expression of the field.
284
+ #
285
+ def default_value_expression
286
+ @gapi.default_value_expression
287
+ end
288
+
289
+ ##
290
+ # Updates the default value expression of the field.
291
+ #
292
+ # @param default_value_expression [String] The default value of a field
293
+ # using a SQL expression. It can only be set for top level fields (columns).
294
+ # Use a struct or array expression to specify default value for the entire struct or
295
+ # array. The valid SQL expressions are:
296
+ # - Literals for all data types, including STRUCT and ARRAY.
297
+ # - The following functions:
298
+ # `CURRENT_TIMESTAMP`
299
+ # `CURRENT_TIME`
300
+ # `CURRENT_DATE`
301
+ # `CURRENT_DATETIME`
302
+ # `GENERATE_UUID`
303
+ # `RAND`
304
+ # `SESSION_USER`
305
+ # `ST_GEOPOINT`
306
+ # - Struct or array composed with the above allowed functions, for example:
307
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
308
+ #
309
+ def default_value_expression= default_value_expression
310
+ @gapi.update! default_value_expression: default_value_expression
311
+ end
312
+
266
313
  ##
267
314
  # The maximum length of values of this field for {#string?} or {bytes?} fields. If `max_length` is not
268
315
  # specified, no maximum length constraint is imposed on this field. If type = `STRING`, then `max_length`
@@ -300,14 +300,31 @@ module Google
300
300
  # At most 1 policy tag is currently allowed.
301
301
  # @param [Integer] max_length The maximum UTF-8 length of strings
302
302
  # allowed in the field.
303
- #
304
- def string name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
305
- add_field name,
306
- :string,
303
+ # @param default_value_expression [String] The default value of a field
304
+ # using a SQL expression. It can only be set for top level fields (columns).
305
+ # Use a struct or array expression to specify default value for the entire struct or
306
+ # array. The valid SQL expressions are:
307
+ # - Literals for all data types, including STRUCT and ARRAY.
308
+ # - The following functions:
309
+ # `CURRENT_TIMESTAMP`
310
+ # `CURRENT_TIME`
311
+ # `CURRENT_DATE`
312
+ # `CURRENT_DATETIME`
313
+ # `GENERATE_UUID`
314
+ # `RAND`
315
+ # `SESSION_USER`
316
+ # `ST_GEOPOINT`
317
+ # - Struct or array composed with the above allowed functions, for example:
318
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
319
+ #
320
+ def string name, description: nil, mode: :nullable, policy_tags: nil,
321
+ max_length: nil, default_value_expression: nil
322
+ add_field name, :string,
307
323
  description: description,
308
324
  mode: mode,
309
325
  policy_tags: policy_tags,
310
- max_length: max_length
326
+ max_length: max_length,
327
+ default_value_expression: default_value_expression
311
328
  end
312
329
 
313
330
  ##
@@ -325,9 +342,30 @@ module Google
325
342
  # single policy tag for the field. Policy tag identifiers are of
326
343
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
327
344
  # At most 1 policy tag is currently allowed.
328
- #
329
- def integer name, description: nil, mode: :nullable, policy_tags: nil
330
- add_field name, :integer, description: description, mode: mode, policy_tags: policy_tags
345
+ # @param default_value_expression [String] The default value of a field
346
+ # using a SQL expression. It can only be set for top level fields (columns).
347
+ # Use a struct or array expression to specify default value for the entire struct or
348
+ # array. The valid SQL expressions are:
349
+ # - Literals for all data types, including STRUCT and ARRAY.
350
+ # - The following functions:
351
+ # `CURRENT_TIMESTAMP`
352
+ # `CURRENT_TIME`
353
+ # `CURRENT_DATE`
354
+ # `CURRENT_DATETIME`
355
+ # `GENERATE_UUID`
356
+ # `RAND`
357
+ # `SESSION_USER`
358
+ # `ST_GEOPOINT`
359
+ # - Struct or array composed with the above allowed functions, for example:
360
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
361
+ #
362
+ def integer name, description: nil, mode: :nullable,
363
+ policy_tags: nil, default_value_expression: nil
364
+ add_field name, :integer,
365
+ description: description,
366
+ mode: mode,
367
+ policy_tags: policy_tags,
368
+ default_value_expression: default_value_expression
331
369
  end
332
370
 
333
371
  ##
@@ -345,9 +383,30 @@ module Google
345
383
  # single policy tag for the field. Policy tag identifiers are of
346
384
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
347
385
  # At most 1 policy tag is currently allowed.
348
- #
349
- def float name, description: nil, mode: :nullable, policy_tags: nil
350
- add_field name, :float, description: description, mode: mode, policy_tags: policy_tags
386
+ # @param default_value_expression [String] The default value of a field
387
+ # using a SQL expression. It can only be set for top level fields (columns).
388
+ # Use a struct or array expression to specify default value for the entire struct or
389
+ # array. The valid SQL expressions are:
390
+ # - Literals for all data types, including STRUCT and ARRAY.
391
+ # - The following functions:
392
+ # `CURRENT_TIMESTAMP`
393
+ # `CURRENT_TIME`
394
+ # `CURRENT_DATE`
395
+ # `CURRENT_DATETIME`
396
+ # `GENERATE_UUID`
397
+ # `RAND`
398
+ # `SESSION_USER`
399
+ # `ST_GEOPOINT`
400
+ # - Struct or array composed with the above allowed functions, for example:
401
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
402
+ #
403
+ def float name, description: nil, mode: :nullable,
404
+ policy_tags: nil, default_value_expression: nil
405
+ add_field name, :float,
406
+ description: description,
407
+ mode: mode,
408
+ policy_tags: policy_tags,
409
+ default_value_expression: default_value_expression
351
410
  end
352
411
 
353
412
  ##
@@ -386,15 +445,32 @@ module Google
386
445
  # must be: `1 ≤ (precision - scale) ≤ 29`. Values for scale must
387
446
  # be: `0 ≤ scale ≤ 9`. If the scale value is set, the precision
388
447
  # value must be set as well.
389
- #
390
- def numeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil
391
- add_field name,
392
- :numeric,
448
+ # @param default_value_expression [String] The default value of a field
449
+ # using a SQL expression. It can only be set for top level fields (columns).
450
+ # Use a struct or array expression to specify default value for the entire struct or
451
+ # array. The valid SQL expressions are:
452
+ # - Literals for all data types, including STRUCT and ARRAY.
453
+ # - The following functions:
454
+ # `CURRENT_TIMESTAMP`
455
+ # `CURRENT_TIME`
456
+ # `CURRENT_DATE`
457
+ # `CURRENT_DATETIME`
458
+ # `GENERATE_UUID`
459
+ # `RAND`
460
+ # `SESSION_USER`
461
+ # `ST_GEOPOINT`
462
+ # - Struct or array composed with the above allowed functions, for example:
463
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
464
+ #
465
+ def numeric name, description: nil, mode: :nullable, policy_tags: nil,
466
+ precision: nil, scale: nil, default_value_expression: nil
467
+ add_field name, :numeric,
393
468
  description: description,
394
469
  mode: mode,
395
470
  policy_tags: policy_tags,
396
471
  precision: precision,
397
- scale: scale
472
+ scale: scale,
473
+ default_value_expression: default_value_expression
398
474
  end
399
475
 
400
476
  ##
@@ -433,15 +509,32 @@ module Google
433
509
  # must be: `1 ≤ (precision - scale) ≤ 38`. Values for scale must
434
510
  # be: `0 ≤ scale ≤ 38`. If the scale value is set, the precision
435
511
  # value must be set as well.
436
- #
437
- def bignumeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil
438
- add_field name,
439
- :bignumeric,
512
+ # @param default_value_expression [String] The default value of a field
513
+ # using a SQL expression. It can only be set for top level fields (columns).
514
+ # Use a struct or array expression to specify default value for the entire struct or
515
+ # array. The valid SQL expressions are:
516
+ # - Literals for all data types, including STRUCT and ARRAY.
517
+ # - The following functions:
518
+ # `CURRENT_TIMESTAMP`
519
+ # `CURRENT_TIME`
520
+ # `CURRENT_DATE`
521
+ # `CURRENT_DATETIME`
522
+ # `GENERATE_UUID`
523
+ # `RAND`
524
+ # `SESSION_USER`
525
+ # `ST_GEOPOINT`
526
+ # - Struct or array composed with the above allowed functions, for example:
527
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
528
+ #
529
+ def bignumeric name, description: nil, mode: :nullable, policy_tags: nil,
530
+ precision: nil, scale: nil, default_value_expression: nil
531
+ add_field name, :bignumeric,
440
532
  description: description,
441
533
  mode: mode,
442
534
  policy_tags: policy_tags,
443
535
  precision: precision,
444
- scale: scale
536
+ scale: scale,
537
+ default_value_expression: default_value_expression
445
538
  end
446
539
 
447
540
  ##
@@ -459,9 +552,30 @@ module Google
459
552
  # single policy tag for the field. Policy tag identifiers are of
460
553
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
461
554
  # At most 1 policy tag is currently allowed.
462
- #
463
- def boolean name, description: nil, mode: :nullable, policy_tags: nil
464
- add_field name, :boolean, description: description, mode: mode, policy_tags: policy_tags
555
+ # @param default_value_expression [String] The default value of a field
556
+ # using a SQL expression. It can only be set for top level fields (columns).
557
+ # Use a struct or array expression to specify default value for the entire struct or
558
+ # array. The valid SQL expressions are:
559
+ # - Literals for all data types, including STRUCT and ARRAY.
560
+ # - The following functions:
561
+ # `CURRENT_TIMESTAMP`
562
+ # `CURRENT_TIME`
563
+ # `CURRENT_DATE`
564
+ # `CURRENT_DATETIME`
565
+ # `GENERATE_UUID`
566
+ # `RAND`
567
+ # `SESSION_USER`
568
+ # `ST_GEOPOINT`
569
+ # - Struct or array composed with the above allowed functions, for example:
570
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
571
+ #
572
+ def boolean name, description: nil, mode: :nullable, policy_tags: nil,
573
+ default_value_expression: nil
574
+ add_field name, :boolean,
575
+ description: description,
576
+ mode: mode,
577
+ policy_tags: policy_tags,
578
+ default_value_expression: default_value_expression
465
579
  end
466
580
 
467
581
  ##
@@ -481,9 +595,31 @@ module Google
481
595
  # At most 1 policy tag is currently allowed.
482
596
  # @param [Integer] max_length The maximum the maximum number of
483
597
  # bytes in the field.
484
- #
485
- def bytes name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
486
- add_field name, :bytes, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length
598
+ # @param default_value_expression [String] The default value of a field
599
+ # using a SQL expression. It can only be set for top level fields (columns).
600
+ # Use a struct or array expression to specify default value for the entire struct or
601
+ # array. The valid SQL expressions are:
602
+ # - Literals for all data types, including STRUCT and ARRAY.
603
+ # - The following functions:
604
+ # `CURRENT_TIMESTAMP`
605
+ # `CURRENT_TIME`
606
+ # `CURRENT_DATE`
607
+ # `CURRENT_DATETIME`
608
+ # `GENERATE_UUID`
609
+ # `RAND`
610
+ # `SESSION_USER`
611
+ # `ST_GEOPOINT`
612
+ # - Struct or array composed with the above allowed functions, for example:
613
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
614
+ #
615
+ def bytes name, description: nil, mode: :nullable,
616
+ policy_tags: nil, max_length: nil, default_value_expression: nil
617
+ add_field name, :bytes,
618
+ description: description,
619
+ mode: mode,
620
+ policy_tags: policy_tags,
621
+ max_length: max_length,
622
+ default_value_expression: default_value_expression
487
623
  end
488
624
 
489
625
  ##
@@ -501,9 +637,30 @@ module Google
501
637
  # single policy tag for the field. Policy tag identifiers are of
502
638
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
503
639
  # At most 1 policy tag is currently allowed.
504
- #
505
- def timestamp name, description: nil, mode: :nullable, policy_tags: nil
506
- add_field name, :timestamp, description: description, mode: mode, policy_tags: policy_tags
640
+ # @param default_value_expression [String] The default value of a field
641
+ # using a SQL expression. It can only be set for top level fields (columns).
642
+ # Use a struct or array expression to specify default value for the entire struct or
643
+ # array. The valid SQL expressions are:
644
+ # - Literals for all data types, including STRUCT and ARRAY.
645
+ # - The following functions:
646
+ # `CURRENT_TIMESTAMP`
647
+ # `CURRENT_TIME`
648
+ # `CURRENT_DATE`
649
+ # `CURRENT_DATETIME`
650
+ # `GENERATE_UUID`
651
+ # `RAND`
652
+ # `SESSION_USER`
653
+ # `ST_GEOPOINT`
654
+ # - Struct or array composed with the above allowed functions, for example:
655
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
656
+ #
657
+ def timestamp name, description: nil, mode: :nullable,
658
+ policy_tags: nil, default_value_expression: nil
659
+ add_field name, :timestamp,
660
+ description: description,
661
+ mode: mode,
662
+ policy_tags: policy_tags,
663
+ default_value_expression: default_value_expression
507
664
  end
508
665
 
509
666
  ##
@@ -521,9 +678,30 @@ module Google
521
678
  # single policy tag for the field. Policy tag identifiers are of
522
679
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
523
680
  # At most 1 policy tag is currently allowed.
524
- #
525
- def time name, description: nil, mode: :nullable, policy_tags: nil
526
- add_field name, :time, description: description, mode: mode, policy_tags: policy_tags
681
+ # @param default_value_expression [String] The default value of a field
682
+ # using a SQL expression. It can only be set for top level fields (columns).
683
+ # Use a struct or array expression to specify default value for the entire struct or
684
+ # array. The valid SQL expressions are:
685
+ # - Literals for all data types, including STRUCT and ARRAY.
686
+ # - The following functions:
687
+ # `CURRENT_TIMESTAMP`
688
+ # `CURRENT_TIME`
689
+ # `CURRENT_DATE`
690
+ # `CURRENT_DATETIME`
691
+ # `GENERATE_UUID`
692
+ # `RAND`
693
+ # `SESSION_USER`
694
+ # `ST_GEOPOINT`
695
+ # - Struct or array composed with the above allowed functions, for example:
696
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
697
+ #
698
+ def time name, description: nil, mode: :nullable,
699
+ policy_tags: nil, default_value_expression: nil
700
+ add_field name, :time,
701
+ description: description,
702
+ mode: mode,
703
+ policy_tags: policy_tags,
704
+ default_value_expression: default_value_expression
527
705
  end
528
706
 
529
707
  ##
@@ -541,9 +719,30 @@ module Google
541
719
  # single policy tag for the field. Policy tag identifiers are of
542
720
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
543
721
  # At most 1 policy tag is currently allowed.
544
- #
545
- def datetime name, description: nil, mode: :nullable, policy_tags: nil
546
- add_field name, :datetime, description: description, mode: mode, policy_tags: policy_tags
722
+ # @param default_value_expression [String] The default value of a field
723
+ # using a SQL expression. It can only be set for top level fields (columns).
724
+ # Use a struct or array expression to specify default value for the entire struct or
725
+ # array. The valid SQL expressions are:
726
+ # - Literals for all data types, including STRUCT and ARRAY.
727
+ # - The following functions:
728
+ # `CURRENT_TIMESTAMP`
729
+ # `CURRENT_TIME`
730
+ # `CURRENT_DATE`
731
+ # `CURRENT_DATETIME`
732
+ # `GENERATE_UUID`
733
+ # `RAND`
734
+ # `SESSION_USER`
735
+ # `ST_GEOPOINT`
736
+ # - Struct or array composed with the above allowed functions, for example:
737
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
738
+ #
739
+ def datetime name, description: nil, mode: :nullable,
740
+ policy_tags: nil, default_value_expression: nil
741
+ add_field name, :datetime,
742
+ description: description,
743
+ mode: mode,
744
+ policy_tags: policy_tags,
745
+ default_value_expression: default_value_expression
547
746
  end
548
747
 
549
748
  ##
@@ -561,9 +760,30 @@ module Google
561
760
  # single policy tag for the field. Policy tag identifiers are of
562
761
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
563
762
  # At most 1 policy tag is currently allowed.
564
- #
565
- def date name, description: nil, mode: :nullable, policy_tags: nil
566
- add_field name, :date, description: description, mode: mode, policy_tags: policy_tags
763
+ # @param default_value_expression [String] The default value of a field
764
+ # using a SQL expression. It can only be set for top level fields (columns).
765
+ # Use a struct or array expression to specify default value for the entire struct or
766
+ # array. The valid SQL expressions are:
767
+ # - Literals for all data types, including STRUCT and ARRAY.
768
+ # - The following functions:
769
+ # `CURRENT_TIMESTAMP`
770
+ # `CURRENT_TIME`
771
+ # `CURRENT_DATE`
772
+ # `CURRENT_DATETIME`
773
+ # `GENERATE_UUID`
774
+ # `RAND`
775
+ # `SESSION_USER`
776
+ # `ST_GEOPOINT`
777
+ # - Struct or array composed with the above allowed functions, for example:
778
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
779
+ #
780
+ def date name, description: nil, mode: :nullable,
781
+ policy_tags: nil, default_value_expression: nil
782
+ add_field name, :date,
783
+ description: description,
784
+ mode: mode,
785
+ policy_tags: policy_tags,
786
+ default_value_expression: default_value_expression
567
787
  end
568
788
 
569
789
  ##
@@ -583,9 +803,30 @@ module Google
583
803
  # single policy tag for the field. Policy tag identifiers are of
584
804
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
585
805
  # At most 1 policy tag is currently allowed.
586
- #
587
- def geography name, description: nil, mode: :nullable, policy_tags: nil
588
- add_field name, :geography, description: description, mode: mode, policy_tags: policy_tags
806
+ # @param default_value_expression [String] The default value of a field
807
+ # using a SQL expression. It can only be set for top level fields (columns).
808
+ # Use a struct or array expression to specify default value for the entire struct or
809
+ # array. The valid SQL expressions are:
810
+ # - Literals for all data types, including STRUCT and ARRAY.
811
+ # - The following functions:
812
+ # `CURRENT_TIMESTAMP`
813
+ # `CURRENT_TIME`
814
+ # `CURRENT_DATE`
815
+ # `CURRENT_DATETIME`
816
+ # `GENERATE_UUID`
817
+ # `RAND`
818
+ # `SESSION_USER`
819
+ # `ST_GEOPOINT`
820
+ # - Struct or array composed with the above allowed functions, for example:
821
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
822
+ #
823
+ def geography name, description: nil, mode: :nullable,
824
+ policy_tags: nil, default_value_expression: nil
825
+ add_field name, :geography,
826
+ description: description,
827
+ mode: mode,
828
+ policy_tags: policy_tags,
829
+ default_value_expression: default_value_expression
589
830
  end
590
831
 
591
832
  ##
@@ -603,6 +844,23 @@ module Google
603
844
  # @param [Symbol] mode The field's mode. The possible values are
604
845
  # `:nullable`, `:required`, and `:repeated`. The default value is
605
846
  # `:nullable`.
847
+ # @param default_value_expression [String] The default value of a field
848
+ # using a SQL expression. It can only be set for top level fields (columns).
849
+ # Use a struct or array expression to specify default value for the entire struct or
850
+ # array. The valid SQL expressions are:
851
+ # - Literals for all data types, including STRUCT and ARRAY.
852
+ # - The following functions:
853
+ # `CURRENT_TIMESTAMP`
854
+ # `CURRENT_TIME`
855
+ # `CURRENT_DATE`
856
+ # `CURRENT_DATETIME`
857
+ # `GENERATE_UUID`
858
+ # `RAND`
859
+ # `SESSION_USER`
860
+ # `ST_GEOPOINT`
861
+ # - Struct or array composed with the above allowed functions, for example:
862
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
863
+ #
606
864
  # @yield [field] a block for setting the nested record's schema
607
865
  # @yieldparam [Field] field the object accepting the
608
866
  # nested schema
@@ -622,11 +880,15 @@ module Google
622
880
  # end
623
881
  # end
624
882
  #
625
- def record name, description: nil, mode: nil
883
+ def record name, description: nil, mode: nil,
884
+ default_value_expression: nil
626
885
  # TODO: do we need to raise if no block was given?
627
886
  raise ArgumentError, "a block is required" unless block_given?
628
887
 
629
- nested_field = add_field name, :record, description: description, mode: mode
888
+ nested_field = add_field name, :record,
889
+ description: description,
890
+ mode: mode,
891
+ default_value_expression: default_value_expression
630
892
  yield nested_field
631
893
  nested_field
632
894
  end
@@ -675,7 +937,8 @@ module Google
675
937
  policy_tags: nil,
676
938
  max_length: nil,
677
939
  precision: nil,
678
- scale: nil
940
+ scale: nil,
941
+ default_value_expression: nil
679
942
  frozen_check!
680
943
 
681
944
  new_gapi = Google::Apis::BigqueryV2::TableFieldSchema.new(
@@ -692,6 +955,7 @@ module Google
692
955
  new_gapi.max_length = max_length if max_length
693
956
  new_gapi.precision = precision if precision
694
957
  new_gapi.scale = scale if scale
958
+ new_gapi.default_value_expression = default_value_expression if default_value_expression
695
959
  # Remove any existing field of this name
696
960
  @gapi.fields ||= []
697
961
  @gapi.fields.reject! { |f| f.name == new_gapi.name }