google-cloud-bigquery 1.42.0 → 1.49.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2372,6 +2372,11 @@ module Google
2372
2372
  # @param [Boolean] dryrun If set, don't actually run this job. Behavior
2373
2373
  # is undefined however for non-query jobs and may result in an error.
2374
2374
  # Deprecated.
2375
+ # @param [Boolean] create_session If set to true a new session will be created
2376
+ # and the load job will happen in the table created within that session.
2377
+ # Note: This will work only for tables in _SESSION dataset
2378
+ # else the property will be ignored by the backend.
2379
+ # @param [string] session_id Session ID in which the load job must run.
2375
2380
  #
2376
2381
  # @yield [load_job] a block for setting the load job
2377
2382
  # @yieldparam [LoadJob] load_job the load job object to be updated
@@ -2428,7 +2433,7 @@ module Google
2428
2433
  def load_job files, format: nil, create: nil, write: nil, projection_fields: nil, jagged_rows: nil,
2429
2434
  quoted_newlines: nil, encoding: nil, delimiter: nil, ignore_unknown: nil, max_bad_records: nil,
2430
2435
  quote: nil, skip_leading: nil, job_id: nil, prefix: nil, labels: nil, autodetect: nil,
2431
- null_marker: nil, dryrun: nil
2436
+ null_marker: nil, dryrun: nil, create_session: nil, session_id: nil, schema: self.schema
2432
2437
  ensure_service!
2433
2438
 
2434
2439
  updater = load_job_updater format: format, create: create, write: write, projection_fields: projection_fields,
@@ -2436,7 +2441,9 @@ module Google
2436
2441
  delimiter: delimiter, ignore_unknown: ignore_unknown,
2437
2442
  max_bad_records: max_bad_records, quote: quote, skip_leading: skip_leading,
2438
2443
  dryrun: dryrun, job_id: job_id, prefix: prefix, schema: schema, labels: labels,
2439
- autodetect: autodetect, null_marker: null_marker
2444
+ autodetect: autodetect, null_marker: null_marker, create_session: create_session,
2445
+ session_id: session_id
2446
+
2440
2447
 
2441
2448
  yield updater if block_given?
2442
2449
 
@@ -2551,6 +2558,7 @@ module Google
2551
2558
  # file that BigQuery will skip when loading the data. The default
2552
2559
  # value is `0`. This property is useful if you have header rows in the
2553
2560
  # file that should be skipped.
2561
+ # @param [string] session_id Session ID in which the load job must run.
2554
2562
  #
2555
2563
  # @yield [updater] A block for setting the schema of the destination
2556
2564
  # table and other options for the load job. The schema can be omitted
@@ -2612,12 +2620,13 @@ module Google
2612
2620
  #
2613
2621
  def load files, format: nil, create: nil, write: nil, projection_fields: nil, jagged_rows: nil,
2614
2622
  quoted_newlines: nil, encoding: nil, delimiter: nil, ignore_unknown: nil, max_bad_records: nil,
2615
- quote: nil, skip_leading: nil, autodetect: nil, null_marker: nil, &block
2623
+ quote: nil, skip_leading: nil, autodetect: nil, null_marker: nil, session_id: nil,
2624
+ schema: self.schema, &block
2616
2625
  job = load_job files, format: format, create: create, write: write, projection_fields: projection_fields,
2617
2626
  jagged_rows: jagged_rows, quoted_newlines: quoted_newlines, encoding: encoding,
2618
2627
  delimiter: delimiter, ignore_unknown: ignore_unknown, max_bad_records: max_bad_records,
2619
2628
  quote: quote, skip_leading: skip_leading, autodetect: autodetect,
2620
- null_marker: null_marker, &block
2629
+ null_marker: null_marker, session_id: session_id, schema: schema, &block
2621
2630
 
2622
2631
  job.wait_until_done!
2623
2632
  ensure_job_succeeded! job
@@ -2639,6 +2648,7 @@ module Google
2639
2648
  # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
2640
2649
  # | `DATE` | `Date` | |
2641
2650
  # | `GEOGRAPHY` | `String` | Well-known text (WKT) or GeoJSON. |
2651
+ # | `JSON` | `String` (Stringified JSON) | String, as JSON does not have a schema to verify. |
2642
2652
  # | `TIMESTAMP` | `Time` | |
2643
2653
  # | `TIME` | `Google::Cloud::BigQuery::Time` | |
2644
2654
  # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
@@ -3114,7 +3124,8 @@ module Google
3114
3124
  def load_job_updater format: nil, create: nil, write: nil, projection_fields: nil, jagged_rows: nil,
3115
3125
  quoted_newlines: nil, encoding: nil, delimiter: nil, ignore_unknown: nil,
3116
3126
  max_bad_records: nil, quote: nil, skip_leading: nil, dryrun: nil, schema: nil, job_id: nil,
3117
- prefix: nil, labels: nil, autodetect: nil, null_marker: nil
3127
+ prefix: nil, labels: nil, autodetect: nil, null_marker: nil,
3128
+ create_session: nil, session_id: nil
3118
3129
  new_job = load_job_gapi table_id, dryrun, job_id: job_id, prefix: prefix
3119
3130
  LoadJob::Updater.new(new_job).tap do |job|
3120
3131
  job.location = location if location # may be table reference
@@ -3123,6 +3134,8 @@ module Google
3123
3134
  job.schema = schema unless schema.nil?
3124
3135
  job.autodetect = autodetect unless autodetect.nil?
3125
3136
  job.labels = labels unless labels.nil?
3137
+ job.create_session = create_session unless create_session.nil?
3138
+ job.session_id = session_id unless session_id.nil?
3126
3139
  load_job_file_options! job, format: format,
3127
3140
  projection_fields: projection_fields,
3128
3141
  jagged_rows: jagged_rows,
@@ -3528,6 +3541,22 @@ module Google
3528
3541
  # At most 1 policy tag is currently allowed.
3529
3542
  # @param [Integer] max_length The maximum UTF-8 length of strings
3530
3543
  # allowed in the field.
3544
+ # @param default_value_expression [String] The default value of a field
3545
+ # using a SQL expression. It can only be set for top level fields (columns).
3546
+ # Use a struct or array expression to specify default value for the entire struct or
3547
+ # array. The valid SQL expressions are:
3548
+ # - Literals for all data types, including STRUCT and ARRAY.
3549
+ # - The following functions:
3550
+ # `CURRENT_TIMESTAMP`
3551
+ # `CURRENT_TIME`
3552
+ # `CURRENT_DATE`
3553
+ # `CURRENT_DATETIME`
3554
+ # `GENERATE_UUID`
3555
+ # `RAND`
3556
+ # `SESSION_USER`
3557
+ # `ST_GEOPOINT`
3558
+ # - Struct or array composed with the above allowed functions, for example:
3559
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
3531
3560
  #
3532
3561
  # @example
3533
3562
  # require "google/cloud/bigquery"
@@ -3538,9 +3567,20 @@ module Google
3538
3567
  # schema.string "first_name", mode: :required
3539
3568
  # end
3540
3569
  #
3570
+ # @example Add field with default value.
3571
+ # require "google/cloud/bigquery"
3572
+ #
3573
+ # bigquery = Google::Cloud::Bigquery.new
3574
+ # dataset = bigquery.dataset "my_dataset"
3575
+ # table = dataset.create_table "my_table" do |schema|
3576
+ # schema.string "first_name", default_value_expression: "'name'"
3577
+ # end
3578
+ #
3541
3579
  # @!group Schema
3542
- def string name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
3543
- schema.string name, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length
3580
+ def string name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil,
3581
+ default_value_expression: nil
3582
+ schema.string name, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length,
3583
+ default_value_expression: default_value_expression
3544
3584
  end
3545
3585
 
3546
3586
  ##
@@ -3560,6 +3600,22 @@ module Google
3560
3600
  # single policy tag for the field. Policy tag identifiers are of
3561
3601
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
3562
3602
  # At most 1 policy tag is currently allowed.
3603
+ # @param default_value_expression [String] The default value of a field
3604
+ # using a SQL expression. It can only be set for top level fields (columns).
3605
+ # Use a struct or array expression to specify default value for the entire struct or
3606
+ # array. The valid SQL expressions are:
3607
+ # - Literals for all data types, including STRUCT and ARRAY.
3608
+ # - The following functions:
3609
+ # `CURRENT_TIMESTAMP`
3610
+ # `CURRENT_TIME`
3611
+ # `CURRENT_DATE`
3612
+ # `CURRENT_DATETIME`
3613
+ # `GENERATE_UUID`
3614
+ # `RAND`
3615
+ # `SESSION_USER`
3616
+ # `ST_GEOPOINT`
3617
+ # - Struct or array composed with the above allowed functions, for example:
3618
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
3563
3619
  #
3564
3620
  # @example
3565
3621
  # require "google/cloud/bigquery"
@@ -3570,9 +3626,20 @@ module Google
3570
3626
  # schema.integer "age", mode: :required
3571
3627
  # end
3572
3628
  #
3629
+ # @example Add field with default value.
3630
+ # require "google/cloud/bigquery"
3631
+ #
3632
+ # bigquery = Google::Cloud::Bigquery.new
3633
+ # dataset = bigquery.dataset "my_dataset"
3634
+ # table = dataset.create_table "my_table" do |schema|
3635
+ # schema.integer "age", default_value_expression: "1"
3636
+ # end
3637
+ #
3573
3638
  # @!group Schema
3574
- def integer name, description: nil, mode: :nullable, policy_tags: nil
3575
- schema.integer name, description: description, mode: mode, policy_tags: policy_tags
3639
+ def integer name, description: nil, mode: :nullable, policy_tags: nil,
3640
+ default_value_expression: nil
3641
+ schema.integer name, description: description, mode: mode, policy_tags: policy_tags,
3642
+ default_value_expression: default_value_expression
3576
3643
  end
3577
3644
 
3578
3645
  ##
@@ -3592,6 +3659,22 @@ module Google
3592
3659
  # single policy tag for the field. Policy tag identifiers are of
3593
3660
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
3594
3661
  # At most 1 policy tag is currently allowed.
3662
+ # @param default_value_expression [String] The default value of a field
3663
+ # using a SQL expression. It can only be set for top level fields (columns).
3664
+ # Use a struct or array expression to specify default value for the entire struct or
3665
+ # array. The valid SQL expressions are:
3666
+ # - Literals for all data types, including STRUCT and ARRAY.
3667
+ # - The following functions:
3668
+ # `CURRENT_TIMESTAMP`
3669
+ # `CURRENT_TIME`
3670
+ # `CURRENT_DATE`
3671
+ # `CURRENT_DATETIME`
3672
+ # `GENERATE_UUID`
3673
+ # `RAND`
3674
+ # `SESSION_USER`
3675
+ # `ST_GEOPOINT`
3676
+ # - Struct or array composed with the above allowed functions, for example:
3677
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
3595
3678
  #
3596
3679
  # @example
3597
3680
  # require "google/cloud/bigquery"
@@ -3602,9 +3685,20 @@ module Google
3602
3685
  # schema.float "price", mode: :required
3603
3686
  # end
3604
3687
  #
3688
+ # @example Add field with default value.
3689
+ # require "google/cloud/bigquery"
3690
+ #
3691
+ # bigquery = Google::Cloud::Bigquery.new
3692
+ # dataset = bigquery.dataset "my_dataset"
3693
+ # table = dataset.create_table "my_table" do |schema|
3694
+ # schema.float "price", default_value_expression: "1.0"
3695
+ # end
3696
+ #
3605
3697
  # @!group Schema
3606
- def float name, description: nil, mode: :nullable, policy_tags: nil
3607
- schema.float name, description: description, mode: mode, policy_tags: policy_tags
3698
+ def float name, description: nil, mode: :nullable, policy_tags: nil,
3699
+ default_value_expression: nil
3700
+ schema.float name, description: description, mode: mode, policy_tags: policy_tags,
3701
+ default_value_expression: default_value_expression
3608
3702
  end
3609
3703
 
3610
3704
  ##
@@ -3645,6 +3739,22 @@ module Google
3645
3739
  # must be: `1 ≤ (precision - scale) ≤ 29`. Values for scale must
3646
3740
  # be: `0 ≤ scale ≤ 9`. If the scale value is set, the precision
3647
3741
  # value must be set as well.
3742
+ # @param default_value_expression [String] The default value of a field
3743
+ # using a SQL expression. It can only be set for top level fields (columns).
3744
+ # Use a struct or array expression to specify default value for the entire struct or
3745
+ # array. The valid SQL expressions are:
3746
+ # - Literals for all data types, including STRUCT and ARRAY.
3747
+ # - The following functions:
3748
+ # `CURRENT_TIMESTAMP`
3749
+ # `CURRENT_TIME`
3750
+ # `CURRENT_DATE`
3751
+ # `CURRENT_DATETIME`
3752
+ # `GENERATE_UUID`
3753
+ # `RAND`
3754
+ # `SESSION_USER`
3755
+ # `ST_GEOPOINT`
3756
+ # - Struct or array composed with the above allowed functions, for example:
3757
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
3648
3758
  #
3649
3759
  # @example
3650
3760
  # require "google/cloud/bigquery"
@@ -3655,14 +3765,25 @@ module Google
3655
3765
  # schema.numeric "total_cost", mode: :required
3656
3766
  # end
3657
3767
  #
3768
+ # @example Add field with default value.
3769
+ # require "google/cloud/bigquery"
3770
+ #
3771
+ # bigquery = Google::Cloud::Bigquery.new
3772
+ # dataset = bigquery.dataset "my_dataset"
3773
+ # table = dataset.create_table "my_table" do |schema|
3774
+ # schema.numeric "total_cost", default_value_expression: "1.0e4"
3775
+ # end
3776
+ #
3658
3777
  # @!group Schema
3659
- def numeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil
3778
+ def numeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil,
3779
+ default_value_expression: nil
3660
3780
  schema.numeric name,
3661
3781
  description: description,
3662
3782
  mode: mode,
3663
3783
  policy_tags: policy_tags,
3664
3784
  precision: precision,
3665
- scale: scale
3785
+ scale: scale,
3786
+ default_value_expression: default_value_expression
3666
3787
  end
3667
3788
 
3668
3789
  ##
@@ -3703,6 +3824,22 @@ module Google
3703
3824
  # must be: `1 ≤ (precision - scale) ≤ 38`. Values for scale must
3704
3825
  # be: `0 ≤ scale ≤ 38`. If the scale value is set, the precision
3705
3826
  # value must be set as well.
3827
+ # @param default_value_expression [String] The default value of a field
3828
+ # using a SQL expression. It can only be set for top level fields (columns).
3829
+ # Use a struct or array expression to specify default value for the entire struct or
3830
+ # array. The valid SQL expressions are:
3831
+ # - Literals for all data types, including STRUCT and ARRAY.
3832
+ # - The following functions:
3833
+ # `CURRENT_TIMESTAMP`
3834
+ # `CURRENT_TIME`
3835
+ # `CURRENT_DATE`
3836
+ # `CURRENT_DATETIME`
3837
+ # `GENERATE_UUID`
3838
+ # `RAND`
3839
+ # `SESSION_USER`
3840
+ # `ST_GEOPOINT`
3841
+ # - Struct or array composed with the above allowed functions, for example:
3842
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
3706
3843
  #
3707
3844
  # @example
3708
3845
  # require "google/cloud/bigquery"
@@ -3713,14 +3850,25 @@ module Google
3713
3850
  # schema.bignumeric "total_cost", mode: :required
3714
3851
  # end
3715
3852
  #
3853
+ # @example Add field with default value.
3854
+ # require "google/cloud/bigquery"
3855
+ #
3856
+ # bigquery = Google::Cloud::Bigquery.new
3857
+ # dataset = bigquery.dataset "my_dataset"
3858
+ # table = dataset.create_table "my_table" do |schema|
3859
+ # schema.bignumeric "total_cost", default_value_expression: "1.0e4"
3860
+ # end
3861
+ #
3716
3862
  # @!group Schema
3717
- def bignumeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil
3863
+ def bignumeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil,
3864
+ default_value_expression: nil
3718
3865
  schema.bignumeric name,
3719
3866
  description: description,
3720
3867
  mode: mode,
3721
3868
  policy_tags: policy_tags,
3722
3869
  precision: precision,
3723
- scale: scale
3870
+ scale: scale,
3871
+ default_value_expression: default_value_expression
3724
3872
  end
3725
3873
 
3726
3874
  ##
@@ -3740,6 +3888,22 @@ module Google
3740
3888
  # single policy tag for the field. Policy tag identifiers are of
3741
3889
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
3742
3890
  # At most 1 policy tag is currently allowed.
3891
+ # @param default_value_expression [String] The default value of a field
3892
+ # using a SQL expression. It can only be set for top level fields (columns).
3893
+ # Use a struct or array expression to specify default value for the entire struct or
3894
+ # array. The valid SQL expressions are:
3895
+ # - Literals for all data types, including STRUCT and ARRAY.
3896
+ # - The following functions:
3897
+ # `CURRENT_TIMESTAMP`
3898
+ # `CURRENT_TIME`
3899
+ # `CURRENT_DATE`
3900
+ # `CURRENT_DATETIME`
3901
+ # `GENERATE_UUID`
3902
+ # `RAND`
3903
+ # `SESSION_USER`
3904
+ # `ST_GEOPOINT`
3905
+ # - Struct or array composed with the above allowed functions, for example:
3906
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
3743
3907
  #
3744
3908
  # @example
3745
3909
  # require "google/cloud/bigquery"
@@ -3750,9 +3914,20 @@ module Google
3750
3914
  # schema.boolean "active", mode: :required
3751
3915
  # end
3752
3916
  #
3917
+ # @example Add field with default value.
3918
+ # require "google/cloud/bigquery"
3919
+ #
3920
+ # bigquery = Google::Cloud::Bigquery.new
3921
+ # dataset = bigquery.dataset "my_dataset"
3922
+ # table = dataset.create_table "my_table" do |schema|
3923
+ # schema.boolean "active", default_value_expression: "true"
3924
+ # end
3925
+ #
3753
3926
  # @!group Schema
3754
- def boolean name, description: nil, mode: :nullable, policy_tags: nil
3755
- schema.boolean name, description: description, mode: mode, policy_tags: policy_tags
3927
+ def boolean name, description: nil, mode: :nullable, policy_tags: nil,
3928
+ default_value_expression: nil
3929
+ schema.boolean name, description: description, mode: mode, policy_tags: policy_tags,
3930
+ default_value_expression: default_value_expression
3756
3931
  end
3757
3932
 
3758
3933
  ##
@@ -3774,6 +3949,22 @@ module Google
3774
3949
  # At most 1 policy tag is currently allowed.
3775
3950
  # @param [Integer] max_length The maximum the maximum number of
3776
3951
  # bytes in the field.
3952
+ # @param default_value_expression [String] The default value of a field
3953
+ # using a SQL expression. It can only be set for top level fields (columns).
3954
+ # Use a struct or array expression to specify default value for the entire struct or
3955
+ # array. The valid SQL expressions are:
3956
+ # - Literals for all data types, including STRUCT and ARRAY.
3957
+ # - The following functions:
3958
+ # `CURRENT_TIMESTAMP`
3959
+ # `CURRENT_TIME`
3960
+ # `CURRENT_DATE`
3961
+ # `CURRENT_DATETIME`
3962
+ # `GENERATE_UUID`
3963
+ # `RAND`
3964
+ # `SESSION_USER`
3965
+ # `ST_GEOPOINT`
3966
+ # - Struct or array composed with the above allowed functions, for example:
3967
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
3777
3968
  #
3778
3969
  # @example
3779
3970
  # require "google/cloud/bigquery"
@@ -3784,9 +3975,20 @@ module Google
3784
3975
  # schema.bytes "avatar", mode: :required
3785
3976
  # end
3786
3977
  #
3978
+ # @example Add field with default value.
3979
+ # require "google/cloud/bigquery"
3980
+ #
3981
+ # bigquery = Google::Cloud::Bigquery.new
3982
+ # dataset = bigquery.dataset "my_dataset"
3983
+ # table = dataset.create_table "my_table" do |schema|
3984
+ # schema.bytes "avatar", default_value_expression: "b'101'"
3985
+ # end
3986
+ #
3787
3987
  # @!group Schema
3788
- def bytes name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
3789
- schema.bytes name, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length
3988
+ def bytes name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil,
3989
+ default_value_expression: nil
3990
+ schema.bytes name, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length,
3991
+ default_value_expression: default_value_expression
3790
3992
  end
3791
3993
 
3792
3994
  ##
@@ -3806,6 +4008,22 @@ module Google
3806
4008
  # single policy tag for the field. Policy tag identifiers are of
3807
4009
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
3808
4010
  # At most 1 policy tag is currently allowed.
4011
+ # @param default_value_expression [String] The default value of a field
4012
+ # using a SQL expression. It can only be set for top level fields (columns).
4013
+ # Use a struct or array expression to specify default value for the entire struct or
4014
+ # array. The valid SQL expressions are:
4015
+ # - Literals for all data types, including STRUCT and ARRAY.
4016
+ # - The following functions:
4017
+ # `CURRENT_TIMESTAMP`
4018
+ # `CURRENT_TIME`
4019
+ # `CURRENT_DATE`
4020
+ # `CURRENT_DATETIME`
4021
+ # `GENERATE_UUID`
4022
+ # `RAND`
4023
+ # `SESSION_USER`
4024
+ # `ST_GEOPOINT`
4025
+ # - Struct or array composed with the above allowed functions, for example:
4026
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
3809
4027
  #
3810
4028
  # @example
3811
4029
  # require "google/cloud/bigquery"
@@ -3816,9 +4034,20 @@ module Google
3816
4034
  # schema.timestamp "creation_date", mode: :required
3817
4035
  # end
3818
4036
  #
4037
+ # @example Add field with default value.
4038
+ # require "google/cloud/bigquery"
4039
+ #
4040
+ # bigquery = Google::Cloud::Bigquery.new
4041
+ # dataset = bigquery.dataset "my_dataset"
4042
+ # table = dataset.create_table "my_table" do |schema|
4043
+ # schema.timestamp "creation_date", default_value_expression: "CURRENT_TIMESTAMP"
4044
+ # end
4045
+ #
3819
4046
  # @!group Schema
3820
- def timestamp name, description: nil, mode: :nullable, policy_tags: nil
3821
- schema.timestamp name, description: description, mode: mode, policy_tags: policy_tags
4047
+ def timestamp name, description: nil, mode: :nullable, policy_tags: nil,
4048
+ default_value_expression: nil
4049
+ schema.timestamp name, description: description, mode: mode, policy_tags: policy_tags,
4050
+ default_value_expression: default_value_expression
3822
4051
  end
3823
4052
 
3824
4053
  ##
@@ -3838,6 +4067,22 @@ module Google
3838
4067
  # single policy tag for the field. Policy tag identifiers are of
3839
4068
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
3840
4069
  # At most 1 policy tag is currently allowed.
4070
+ # @param default_value_expression [String] The default value of a field
4071
+ # using a SQL expression. It can only be set for top level fields (columns).
4072
+ # Use a struct or array expression to specify default value for the entire struct or
4073
+ # array. The valid SQL expressions are:
4074
+ # - Literals for all data types, including STRUCT and ARRAY.
4075
+ # - The following functions:
4076
+ # `CURRENT_TIMESTAMP`
4077
+ # `CURRENT_TIME`
4078
+ # `CURRENT_DATE`
4079
+ # `CURRENT_DATETIME`
4080
+ # `GENERATE_UUID`
4081
+ # `RAND`
4082
+ # `SESSION_USER`
4083
+ # `ST_GEOPOINT`
4084
+ # - Struct or array composed with the above allowed functions, for example:
4085
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
3841
4086
  #
3842
4087
  # @example
3843
4088
  # require "google/cloud/bigquery"
@@ -3848,9 +4093,20 @@ module Google
3848
4093
  # schema.time "duration", mode: :required
3849
4094
  # end
3850
4095
  #
4096
+ # @example Add field with default value.
4097
+ # require "google/cloud/bigquery"
4098
+ #
4099
+ # bigquery = Google::Cloud::Bigquery.new
4100
+ # dataset = bigquery.dataset "my_dataset"
4101
+ # table = dataset.create_table "my_table" do |schema|
4102
+ # schema.time "duration", default_value_expression: "CURRENT_TIME"
4103
+ # end
4104
+ #
3851
4105
  # @!group Schema
3852
- def time name, description: nil, mode: :nullable, policy_tags: nil
3853
- schema.time name, description: description, mode: mode, policy_tags: policy_tags
4106
+ def time name, description: nil, mode: :nullable, policy_tags: nil,
4107
+ default_value_expression: nil
4108
+ schema.time name, description: description, mode: mode, policy_tags: policy_tags,
4109
+ default_value_expression: default_value_expression
3854
4110
  end
3855
4111
 
3856
4112
  ##
@@ -3870,6 +4126,22 @@ module Google
3870
4126
  # single policy tag for the field. Policy tag identifiers are of
3871
4127
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
3872
4128
  # At most 1 policy tag is currently allowed.
4129
+ # @param default_value_expression [String] The default value of a field
4130
+ # using a SQL expression. It can only be set for top level fields (columns).
4131
+ # Use a struct or array expression to specify default value for the entire struct or
4132
+ # array. The valid SQL expressions are:
4133
+ # - Literals for all data types, including STRUCT and ARRAY.
4134
+ # - The following functions:
4135
+ # `CURRENT_TIMESTAMP`
4136
+ # `CURRENT_TIME`
4137
+ # `CURRENT_DATE`
4138
+ # `CURRENT_DATETIME`
4139
+ # `GENERATE_UUID`
4140
+ # `RAND`
4141
+ # `SESSION_USER`
4142
+ # `ST_GEOPOINT`
4143
+ # - Struct or array composed with the above allowed functions, for example:
4144
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
3873
4145
  #
3874
4146
  # @example
3875
4147
  # require "google/cloud/bigquery"
@@ -3880,9 +4152,20 @@ module Google
3880
4152
  # schema.datetime "target_end", mode: :required
3881
4153
  # end
3882
4154
  #
4155
+ # @example Add field with default value.
4156
+ # require "google/cloud/bigquery"
4157
+ #
4158
+ # bigquery = Google::Cloud::Bigquery.new
4159
+ # dataset = bigquery.dataset "my_dataset"
4160
+ # table = dataset.create_table "my_table" do |schema|
4161
+ # schema.datetime "target_end", default_value_expression: "CURRENT_DATETIME"
4162
+ # end
4163
+ #
3883
4164
  # @!group Schema
3884
- def datetime name, description: nil, mode: :nullable, policy_tags: nil
3885
- schema.datetime name, description: description, mode: mode, policy_tags: policy_tags
4165
+ def datetime name, description: nil, mode: :nullable, policy_tags: nil,
4166
+ default_value_expression: nil
4167
+ schema.datetime name, description: description, mode: mode, policy_tags: policy_tags,
4168
+ default_value_expression: default_value_expression
3886
4169
  end
3887
4170
 
3888
4171
  ##
@@ -3902,6 +4185,22 @@ module Google
3902
4185
  # single policy tag for the field. Policy tag identifiers are of
3903
4186
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
3904
4187
  # At most 1 policy tag is currently allowed.
4188
+ # @param default_value_expression [String] The default value of a field
4189
+ # using a SQL expression. It can only be set for top level fields (columns).
4190
+ # Use a struct or array expression to specify default value for the entire struct or
4191
+ # array. The valid SQL expressions are:
4192
+ # - Literals for all data types, including STRUCT and ARRAY.
4193
+ # - The following functions:
4194
+ # `CURRENT_TIMESTAMP`
4195
+ # `CURRENT_TIME`
4196
+ # `CURRENT_DATE`
4197
+ # `CURRENT_DATETIME`
4198
+ # `GENERATE_UUID`
4199
+ # `RAND`
4200
+ # `SESSION_USER`
4201
+ # `ST_GEOPOINT`
4202
+ # - Struct or array composed with the above allowed functions, for example:
4203
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
3905
4204
  #
3906
4205
  # @example
3907
4206
  # require "google/cloud/bigquery"
@@ -3912,9 +4211,20 @@ module Google
3912
4211
  # schema.date "birthday", mode: :required
3913
4212
  # end
3914
4213
  #
4214
+ # @example Add field with default value.
4215
+ # require "google/cloud/bigquery"
4216
+ #
4217
+ # bigquery = Google::Cloud::Bigquery.new
4218
+ # dataset = bigquery.dataset "my_dataset"
4219
+ # table = dataset.create_table "my_table" do |schema|
4220
+ # schema.date "birthday", default_value_expression: "CURRENT_DATE"
4221
+ # end
4222
+ #
3915
4223
  # @!group Schema
3916
- def date name, description: nil, mode: :nullable, policy_tags: nil
3917
- schema.date name, description: description, mode: mode, policy_tags: policy_tags
4224
+ def date name, description: nil, mode: :nullable, policy_tags: nil,
4225
+ default_value_expression: nil
4226
+ schema.date name, description: description, mode: mode, policy_tags: policy_tags,
4227
+ default_value_expression: default_value_expression
3918
4228
  end
3919
4229
 
3920
4230
  ##
@@ -3934,6 +4244,22 @@ module Google
3934
4244
  # single policy tag for the field. Policy tag identifiers are of
3935
4245
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
3936
4246
  # At most 1 policy tag is currently allowed.
4247
+ # @param default_value_expression [String] The default value of a field
4248
+ # using a SQL expression. It can only be set for top level fields (columns).
4249
+ # Use a struct or array expression to specify default value for the entire struct or
4250
+ # array. The valid SQL expressions are:
4251
+ # - Literals for all data types, including STRUCT and ARRAY.
4252
+ # - The following functions:
4253
+ # `CURRENT_TIMESTAMP`
4254
+ # `CURRENT_TIME`
4255
+ # `CURRENT_DATE`
4256
+ # `CURRENT_DATETIME`
4257
+ # `GENERATE_UUID`
4258
+ # `RAND`
4259
+ # `SESSION_USER`
4260
+ # `ST_GEOPOINT`
4261
+ # - Struct or array composed with the above allowed functions, for example:
4262
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
3937
4263
  #
3938
4264
  # @example
3939
4265
  # require "google/cloud/bigquery"
@@ -3944,8 +4270,79 @@ module Google
3944
4270
  # schema.geography "home", mode: :required
3945
4271
  # end
3946
4272
  #
3947
- def geography name, description: nil, mode: :nullable, policy_tags: nil
3948
- schema.geography name, description: description, mode: mode, policy_tags: policy_tags
4273
+ # @example Add field with default value.
4274
+ # require "google/cloud/bigquery"
4275
+ #
4276
+ # bigquery = Google::Cloud::Bigquery.new
4277
+ # dataset = bigquery.dataset "my_dataset"
4278
+ # table = dataset.create_table "my_table" do |schema|
4279
+ # schema.geography "home", default_value_expression: "ST_GEOGPOINT(-122.084801, 37.422131)"
4280
+ # end
4281
+ #
4282
+ def geography name, description: nil, mode: :nullable, policy_tags: nil,
4283
+ default_value_expression: nil
4284
+ schema.geography name, description: description, mode: mode, policy_tags: policy_tags,
4285
+ default_value_expression: default_value_expression
4286
+ end
4287
+
4288
+ ##
4289
+ # Adds an json field to the schema.
4290
+ #
4291
+ # See {Schema#json}.
4292
+ # https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#json_type
4293
+ #
4294
+ # @param [String] name The field name. The name must contain only
4295
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
4296
+ # start with a letter or underscore. The maximum length is 128
4297
+ # characters.
4298
+ # @param [String] description A description of the field.
4299
+ # @param [Symbol] mode The field's mode. The possible values are
4300
+ # `:nullable`, `:required`, and `:repeated`. The default value is
4301
+ # `:nullable`.
4302
+ # @param [Array<String>, String] policy_tags The policy tag list or
4303
+ # single policy tag for the field. Policy tag identifiers are of
4304
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
4305
+ # At most 1 policy tag is currently allowed.
4306
+ # @param default_value_expression [String] The default value of a field
4307
+ # using a SQL expression. It can only be set for top level fields (columns).
4308
+ # Use a struct or array expression to specify default value for the entire struct or
4309
+ # array. The valid SQL expressions are:
4310
+ # - Literals for all data types, including STRUCT and ARRAY.
4311
+ # - The following functions:
4312
+ # `CURRENT_TIMESTAMP`
4313
+ # `CURRENT_TIME`
4314
+ # `CURRENT_DATE`
4315
+ # `CURRENT_DATETIME`
4316
+ # `GENERATE_UUID`
4317
+ # `RAND`
4318
+ # `SESSION_USER`
4319
+ # `ST_GEOPOINT`
4320
+ # - Struct or array composed with the above allowed functions, for example:
4321
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
4322
+ #
4323
+ # @example
4324
+ # require "google/cloud/bigquery"
4325
+ #
4326
+ # bigquery = Google::Cloud::Bigquery.new
4327
+ # dataset = bigquery.dataset "my_dataset"
4328
+ # table = dataset.create_table "my_table" do |schema|
4329
+ # schema.json "person", mode: :required
4330
+ # end
4331
+ #
4332
+ # @example Add field with default value.
4333
+ # require "google/cloud/bigquery"
4334
+ #
4335
+ # bigquery = Google::Cloud::Bigquery.new
4336
+ # dataset = bigquery.dataset "my_dataset"
4337
+ # table = dataset.create_table "my_table" do |schema|
4338
+ # schema.json "person", default_value_expression: "JSON '{"name": "Alice", "age": 30}'"
4339
+ # end
4340
+ #
4341
+ # @!group Schema
4342
+ def json name, description: nil, mode: :nullable, policy_tags: nil,
4343
+ default_value_expression: nil
4344
+ schema.json name, description: description, mode: mode, policy_tags: policy_tags,
4345
+ default_value_expression: default_value_expression
3949
4346
  end
3950
4347
 
3951
4348
  ##
@@ -3965,6 +4362,23 @@ module Google
3965
4362
  # @param [Symbol] mode The field's mode. The possible values are
3966
4363
  # `:nullable`, `:required`, and `:repeated`. The default value is
3967
4364
  # `:nullable`.
4365
+ # @param default_value_expression [String] The default value of a field
4366
+ # using a SQL expression. It can only be set for top level fields (columns).
4367
+ # Use a struct or array expression to specify default value for the entire struct or
4368
+ # array. The valid SQL expressions are:
4369
+ # - Literals for all data types, including STRUCT and ARRAY.
4370
+ # - The following functions:
4371
+ # `CURRENT_TIMESTAMP`
4372
+ # `CURRENT_TIME`
4373
+ # `CURRENT_DATE`
4374
+ # `CURRENT_DATETIME`
4375
+ # `GENERATE_UUID`
4376
+ # `RAND`
4377
+ # `SESSION_USER`
4378
+ # `ST_GEOPOINT`
4379
+ # - Struct or array composed with the above allowed functions, for example:
4380
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
4381
+ #
3968
4382
  # @yield [nested_schema] a block for setting the nested schema
3969
4383
  # @yieldparam [Schema] nested_schema the object accepting the
3970
4384
  # nested schema
@@ -3981,10 +4395,22 @@ module Google
3981
4395
  # end
3982
4396
  # end
3983
4397
  #
3984
- # @!group Schema
4398
+ # @example Add field with default value.
4399
+ # require "google/cloud/bigquery"
4400
+ #
4401
+ # bigquery = Google::Cloud::Bigquery.new
4402
+ # dataset = bigquery.dataset "my_dataset"
4403
+ # table = dataset.create_table "my_table" do |schema|
4404
+ # schema.record "cities_lived", mode: :repeated, "[STRUCT('place',10)]" do |cities_lived|
4405
+ # cities_lived.string "place", mode: :required
4406
+ # cities_lived.integer "number_of_years", mode: :required
4407
+ # end
4408
+ # end
3985
4409
  #
3986
- def record name, description: nil, mode: nil, &block
3987
- schema.record name, description: description, mode: mode, &block
4410
+ # @!group Schema
4411
+ def record name, description: nil, mode: nil, default_value_expression: nil, &block
4412
+ schema.record name, description: description, mode: mode,
4413
+ default_value_expression: default_value_expression, &block
3988
4414
  end
3989
4415
 
3990
4416
  ##