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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 779c0f4690b370db6eb7811fa6fb8dbca101dff34ff478dcdc51ed1e9c83c083
4
- data.tar.gz: d1456024ae30a18c93c05d6d8be7eef88dd3f0610cdbf816cf0c46322c9574be
3
+ metadata.gz: d5aa7d55d1ed17508170fec706bfaf59a4434dc5ff9fa4a7ba6d3b655d441881
4
+ data.tar.gz: 865f6dc6a4a0abfed2c2c89da2a6c1021ca8e1174b6e89418da0807dca854954
5
5
  SHA512:
6
- metadata.gz: 6a5da0e2565b0c224f46a6330d138c8fb35831e874ebc2364fd3b91578d400354011d1e9df7d2986dbe2398f610776b130b7eb9305af8282bf3a6265dd84aa05
7
- data.tar.gz: 0d14faa0d89ba6a114e247c362f8a5d4775ae4dc19de1aad0a64083da7e41fc93ac810e876b434056340b27412bb08063af05edf33355800ca1c528ff02f437b
6
+ metadata.gz: 3641715b30ab0897a12fab3b216944d50ae5d9468614bac41a60116470b3f8e948db6d394ff02f9dabebd5dc0a16e3cb3a7d8e0ee03b433740953ec0f5e803ac
7
+ data.tar.gz: 76a9ad13b267ea9313213a1ee3e1ad094bfd0ea81831fa0aae0e46e7dcae01443a4b76a04b20703145c7b6eaf76e6b74792358ae31984e0d73b9e1cb41bd9db9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Release History
2
2
 
3
+ ### 1.43.0 (2023-05-10)
4
+
5
+ #### Features
6
+
7
+ * Added support for default value expression ([#21540](https://github.com/googleapis/google-cloud-ruby/issues/21540))
8
+
3
9
  ### 1.42.0 (2023-01-15)
4
10
 
5
11
  #### Features
@@ -763,6 +763,22 @@ module Google
763
763
  # At most 1 policy tag is currently allowed.
764
764
  # @param [Integer] max_length The maximum UTF-8 length of strings
765
765
  # allowed in the field.
766
+ # @param default_value_expression [String] The default value of a field
767
+ # using a SQL expression. It can only be set for top level fields (columns).
768
+ # Use a struct or array expression to specify default value for the entire struct or
769
+ # array. The valid SQL expressions are:
770
+ # - Literals for all data types, including STRUCT and ARRAY.
771
+ # - The following functions:
772
+ # `CURRENT_TIMESTAMP`
773
+ # `CURRENT_TIME`
774
+ # `CURRENT_DATE`
775
+ # `CURRENT_DATETIME`
776
+ # `GENERATE_UUID`
777
+ # `RAND`
778
+ # `SESSION_USER`
779
+ # `ST_GEOPOINT`
780
+ # - Struct or array composed with the above allowed functions, for example:
781
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
766
782
  #
767
783
  # @example
768
784
  # require "google/cloud/bigquery"
@@ -773,9 +789,20 @@ module Google
773
789
  # schema.string "first_name", mode: :required
774
790
  # end
775
791
  #
792
+ # @example Add field with default value.
793
+ # require "google/cloud/bigquery"
794
+ #
795
+ # bigquery = Google::Cloud::Bigquery.new
796
+ # dataset = bigquery.dataset "my_dataset"
797
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
798
+ # schema.string "first_name", default_value_expression: "'name'"
799
+ # end
800
+ #
776
801
  # @!group Schema
777
- def string name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
778
- schema.string name, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length
802
+ def string name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil,
803
+ default_value_expression: nil
804
+ schema.string name, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length,
805
+ default_value_expression: default_value_expression
779
806
  end
780
807
 
781
808
  ##
@@ -795,6 +822,22 @@ module Google
795
822
  # single policy tag for the field. Policy tag identifiers are of
796
823
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
797
824
  # At most 1 policy tag is currently allowed.
825
+ # @param default_value_expression [String] The default value of a field
826
+ # using a SQL expression. It can only be set for top level fields (columns).
827
+ # Use a struct or array expression to specify default value for the entire struct or
828
+ # array. The valid SQL expressions are:
829
+ # - Literals for all data types, including STRUCT and ARRAY.
830
+ # - The following functions:
831
+ # `CURRENT_TIMESTAMP`
832
+ # `CURRENT_TIME`
833
+ # `CURRENT_DATE`
834
+ # `CURRENT_DATETIME`
835
+ # `GENERATE_UUID`
836
+ # `RAND`
837
+ # `SESSION_USER`
838
+ # `ST_GEOPOINT`
839
+ # - Struct or array composed with the above allowed functions, for example:
840
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
798
841
  #
799
842
  # @example
800
843
  # require "google/cloud/bigquery"
@@ -805,9 +848,20 @@ module Google
805
848
  # schema.integer "age", mode: :required
806
849
  # end
807
850
  #
851
+ # @example Add field with default value.
852
+ # require "google/cloud/bigquery"
853
+ #
854
+ # bigquery = Google::Cloud::Bigquery.new
855
+ # dataset = bigquery.dataset "my_dataset"
856
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
857
+ # schema.integer "age", default_value_expression: "1"
858
+ # end
859
+ #
808
860
  # @!group Schema
809
- def integer name, description: nil, mode: :nullable, policy_tags: nil
810
- schema.integer name, description: description, mode: mode, policy_tags: policy_tags
861
+ def integer name, description: nil, mode: :nullable, policy_tags: nil,
862
+ default_value_expression: nil
863
+ schema.integer name, description: description, mode: mode, policy_tags: policy_tags,
864
+ default_value_expression: default_value_expression
811
865
  end
812
866
 
813
867
  ##
@@ -827,6 +881,22 @@ module Google
827
881
  # single policy tag for the field. Policy tag identifiers are of
828
882
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
829
883
  # At most 1 policy tag is currently allowed.
884
+ # @param default_value_expression [String] The default value of a field
885
+ # using a SQL expression. It can only be set for top level fields (columns).
886
+ # Use a struct or array expression to specify default value for the entire struct or
887
+ # array. The valid SQL expressions are:
888
+ # - Literals for all data types, including STRUCT and ARRAY.
889
+ # - The following functions:
890
+ # `CURRENT_TIMESTAMP`
891
+ # `CURRENT_TIME`
892
+ # `CURRENT_DATE`
893
+ # `CURRENT_DATETIME`
894
+ # `GENERATE_UUID`
895
+ # `RAND`
896
+ # `SESSION_USER`
897
+ # `ST_GEOPOINT`
898
+ # - Struct or array composed with the above allowed functions, for example:
899
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
830
900
  #
831
901
  # @example
832
902
  # require "google/cloud/bigquery"
@@ -837,9 +907,20 @@ module Google
837
907
  # schema.float "price", mode: :required
838
908
  # end
839
909
  #
910
+ # @example Add field with default value.
911
+ # require "google/cloud/bigquery"
912
+ #
913
+ # bigquery = Google::Cloud::Bigquery.new
914
+ # dataset = bigquery.dataset "my_dataset"
915
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
916
+ # schema.float "price", default_value_expression: "1.0"
917
+ # end
918
+ #
840
919
  # @!group Schema
841
- def float name, description: nil, mode: :nullable, policy_tags: nil
842
- schema.float name, description: description, mode: mode, policy_tags: policy_tags
920
+ def float name, description: nil, mode: :nullable, policy_tags: nil,
921
+ default_value_expression: nil
922
+ schema.float name, description: description, mode: mode, policy_tags: policy_tags,
923
+ default_value_expression: default_value_expression
843
924
  end
844
925
 
845
926
  ##
@@ -880,6 +961,22 @@ module Google
880
961
  # must be: `1 ≤ (precision - scale) ≤ 29`. Values for scale must
881
962
  # be: `0 ≤ scale ≤ 9`. If the scale value is set, the precision
882
963
  # value must be set as well.
964
+ # @param default_value_expression [String] The default value of a field
965
+ # using a SQL expression. It can only be set for top level fields (columns).
966
+ # Use a struct or array expression to specify default value for the entire struct or
967
+ # array. The valid SQL expressions are:
968
+ # - Literals for all data types, including STRUCT and ARRAY.
969
+ # - The following functions:
970
+ # `CURRENT_TIMESTAMP`
971
+ # `CURRENT_TIME`
972
+ # `CURRENT_DATE`
973
+ # `CURRENT_DATETIME`
974
+ # `GENERATE_UUID`
975
+ # `RAND`
976
+ # `SESSION_USER`
977
+ # `ST_GEOPOINT`
978
+ # - Struct or array composed with the above allowed functions, for example:
979
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
883
980
  #
884
981
  # @example
885
982
  # require "google/cloud/bigquery"
@@ -890,14 +987,25 @@ module Google
890
987
  # schema.numeric "total_cost", mode: :required
891
988
  # end
892
989
  #
990
+ # @example Add field with default value.
991
+ # require "google/cloud/bigquery"
992
+ #
993
+ # bigquery = Google::Cloud::Bigquery.new
994
+ # dataset = bigquery.dataset "my_dataset"
995
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
996
+ # schema.numeric "total_cost", default_value_expression: "1.0e10"
997
+ # end
998
+ #
893
999
  # @!group Schema
894
- def numeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil
1000
+ def numeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil,
1001
+ default_value_expression: nil
895
1002
  schema.numeric name,
896
1003
  description: description,
897
1004
  mode: mode,
898
1005
  policy_tags: policy_tags,
899
1006
  precision: precision,
900
- scale: scale
1007
+ scale: scale,
1008
+ default_value_expression: default_value_expression
901
1009
  end
902
1010
 
903
1011
  ##
@@ -938,6 +1046,22 @@ module Google
938
1046
  # must be: `1 ≤ (precision - scale) ≤ 38`. Values for scale must
939
1047
  # be: `0 ≤ scale ≤ 38`. If the scale value is set, the precision
940
1048
  # value must be set as well.
1049
+ # @param default_value_expression [String] The default value of a field
1050
+ # using a SQL expression. It can only be set for top level fields (columns).
1051
+ # Use a struct or array expression to specify default value for the entire struct or
1052
+ # array. The valid SQL expressions are:
1053
+ # - Literals for all data types, including STRUCT and ARRAY.
1054
+ # - The following functions:
1055
+ # `CURRENT_TIMESTAMP`
1056
+ # `CURRENT_TIME`
1057
+ # `CURRENT_DATE`
1058
+ # `CURRENT_DATETIME`
1059
+ # `GENERATE_UUID`
1060
+ # `RAND`
1061
+ # `SESSION_USER`
1062
+ # `ST_GEOPOINT`
1063
+ # - Struct or array composed with the above allowed functions, for example:
1064
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
941
1065
  #
942
1066
  # @example
943
1067
  # require "google/cloud/bigquery"
@@ -948,14 +1072,25 @@ module Google
948
1072
  # schema.bignumeric "total_cost", mode: :required
949
1073
  # end
950
1074
  #
1075
+ # @example Add field with default value.
1076
+ # require "google/cloud/bigquery"
1077
+ #
1078
+ # bigquery = Google::Cloud::Bigquery.new
1079
+ # dataset = bigquery.dataset "my_dataset"
1080
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1081
+ # schema.bignumeric "total_cost", default_value_expression: "1.0e10"
1082
+ # end
1083
+ #
951
1084
  # @!group Schema
952
- def bignumeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil
1085
+ def bignumeric name, description: nil, mode: :nullable, policy_tags: nil, precision: nil, scale: nil,
1086
+ default_value_expression: nil
953
1087
  schema.bignumeric name,
954
1088
  description: description,
955
1089
  mode: mode,
956
1090
  policy_tags: policy_tags,
957
1091
  precision: precision,
958
- scale: scale
1092
+ scale: scale,
1093
+ default_value_expression: default_value_expression
959
1094
  end
960
1095
 
961
1096
  ##
@@ -975,6 +1110,22 @@ module Google
975
1110
  # single policy tag for the field. Policy tag identifiers are of
976
1111
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
977
1112
  # At most 1 policy tag is currently allowed.
1113
+ # @param default_value_expression [String] The default value of a field
1114
+ # using a SQL expression. It can only be set for top level fields (columns).
1115
+ # Use a struct or array expression to specify default value for the entire struct or
1116
+ # array. The valid SQL expressions are:
1117
+ # - Literals for all data types, including STRUCT and ARRAY.
1118
+ # - The following functions:
1119
+ # `CURRENT_TIMESTAMP`
1120
+ # `CURRENT_TIME`
1121
+ # `CURRENT_DATE`
1122
+ # `CURRENT_DATETIME`
1123
+ # `GENERATE_UUID`
1124
+ # `RAND`
1125
+ # `SESSION_USER`
1126
+ # `ST_GEOPOINT`
1127
+ # - Struct or array composed with the above allowed functions, for example:
1128
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
978
1129
  #
979
1130
  # @example
980
1131
  # require "google/cloud/bigquery"
@@ -985,9 +1136,23 @@ module Google
985
1136
  # schema.boolean "active", mode: :required
986
1137
  # end
987
1138
  #
1139
+ # @example Add field with default value.
1140
+ # require "google/cloud/bigquery"
1141
+ #
1142
+ # bigquery = Google::Cloud::Bigquery.new
1143
+ # dataset = bigquery.dataset "my_dataset"
1144
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1145
+ # schema.boolean "active", default_value_expression: "true"
1146
+ # end
1147
+ #
988
1148
  # @!group Schema
989
- def boolean name, description: nil, mode: :nullable, policy_tags: nil
990
- schema.boolean name, description: description, mode: mode, policy_tags: policy_tags
1149
+ def boolean name, description: nil, mode: :nullable, policy_tags: nil,
1150
+ default_value_expression: nil
1151
+ schema.boolean name,
1152
+ description: description,
1153
+ mode: mode,
1154
+ policy_tags: policy_tags,
1155
+ default_value_expression: default_value_expression
991
1156
  end
992
1157
 
993
1158
  ##
@@ -1009,6 +1174,22 @@ module Google
1009
1174
  # At most 1 policy tag is currently allowed.
1010
1175
  # @param [Integer] max_length The maximum the maximum number of
1011
1176
  # bytes in the field.
1177
+ # @param default_value_expression [String] The default value of a field
1178
+ # using a SQL expression. It can only be set for top level fields (columns).
1179
+ # Use a struct or array expression to specify default value for the entire struct or
1180
+ # array. The valid SQL expressions are:
1181
+ # - Literals for all data types, including STRUCT and ARRAY.
1182
+ # - The following functions:
1183
+ # `CURRENT_TIMESTAMP`
1184
+ # `CURRENT_TIME`
1185
+ # `CURRENT_DATE`
1186
+ # `CURRENT_DATETIME`
1187
+ # `GENERATE_UUID`
1188
+ # `RAND`
1189
+ # `SESSION_USER`
1190
+ # `ST_GEOPOINT`
1191
+ # - Struct or array composed with the above allowed functions, for example:
1192
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
1012
1193
  #
1013
1194
  # @example
1014
1195
  # require "google/cloud/bigquery"
@@ -1019,9 +1200,24 @@ module Google
1019
1200
  # schema.bytes "avatar", mode: :required
1020
1201
  # end
1021
1202
  #
1203
+ # @example Add field with default value.
1204
+ # require "google/cloud/bigquery"
1205
+ #
1206
+ # bigquery = Google::Cloud::Bigquery.new
1207
+ # dataset = bigquery.dataset "my_dataset"
1208
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1209
+ # schema.bytes "avatar", default_value_expression: "b'101'"
1210
+ # end
1211
+ #
1022
1212
  # @!group Schema
1023
- def bytes name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil
1024
- schema.bytes name, description: description, mode: mode, policy_tags: policy_tags, max_length: max_length
1213
+ def bytes name, description: nil, mode: :nullable, policy_tags: nil, max_length: nil,
1214
+ default_value_expression: nil
1215
+ schema.bytes name,
1216
+ description: description,
1217
+ mode: mode,
1218
+ policy_tags: policy_tags,
1219
+ max_length: max_length,
1220
+ default_value_expression: default_value_expression
1025
1221
  end
1026
1222
 
1027
1223
  ##
@@ -1041,6 +1237,22 @@ module Google
1041
1237
  # single policy tag for the field. Policy tag identifiers are of
1042
1238
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
1043
1239
  # At most 1 policy tag is currently allowed.
1240
+ # @param default_value_expression [String] The default value of a field
1241
+ # using a SQL expression. It can only be set for top level fields (columns).
1242
+ # Use a struct or array expression to specify default value for the entire struct or
1243
+ # array. The valid SQL expressions are:
1244
+ # - Literals for all data types, including STRUCT and ARRAY.
1245
+ # - The following functions:
1246
+ # `CURRENT_TIMESTAMP`
1247
+ # `CURRENT_TIME`
1248
+ # `CURRENT_DATE`
1249
+ # `CURRENT_DATETIME`
1250
+ # `GENERATE_UUID`
1251
+ # `RAND`
1252
+ # `SESSION_USER`
1253
+ # `ST_GEOPOINT`
1254
+ # - Struct or array composed with the above allowed functions, for example:
1255
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
1044
1256
  #
1045
1257
  # @example
1046
1258
  # require "google/cloud/bigquery"
@@ -1051,9 +1263,20 @@ module Google
1051
1263
  # schema.timestamp "creation_date", mode: :required
1052
1264
  # end
1053
1265
  #
1266
+ # @example Add field with default value.
1267
+ # require "google/cloud/bigquery"
1268
+ #
1269
+ # bigquery = Google::Cloud::Bigquery.new
1270
+ # dataset = bigquery.dataset "my_dataset"
1271
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1272
+ # schema.timestamp "creation_date", default_value_expression: "CURRENT_TIMESTAMP"
1273
+ # end
1274
+ #
1054
1275
  # @!group Schema
1055
- def timestamp name, description: nil, mode: :nullable, policy_tags: nil
1056
- schema.timestamp name, description: description, mode: mode, policy_tags: policy_tags
1276
+ def timestamp name, description: nil, mode: :nullable, policy_tags: nil,
1277
+ default_value_expression: nil
1278
+ schema.timestamp name, description: description, mode: mode, policy_tags: policy_tags,
1279
+ default_value_expression: default_value_expression
1057
1280
  end
1058
1281
 
1059
1282
  ##
@@ -1073,6 +1296,22 @@ module Google
1073
1296
  # single policy tag for the field. Policy tag identifiers are of
1074
1297
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
1075
1298
  # At most 1 policy tag is currently allowed.
1299
+ # @param default_value_expression [String] The default value of a field
1300
+ # using a SQL expression. It can only be set for top level fields (columns).
1301
+ # Use a struct or array expression to specify default value for the entire struct or
1302
+ # array. The valid SQL expressions are:
1303
+ # - Literals for all data types, including STRUCT and ARRAY.
1304
+ # - The following functions:
1305
+ # `CURRENT_TIMESTAMP`
1306
+ # `CURRENT_TIME`
1307
+ # `CURRENT_DATE`
1308
+ # `CURRENT_DATETIME`
1309
+ # `GENERATE_UUID`
1310
+ # `RAND`
1311
+ # `SESSION_USER`
1312
+ # `ST_GEOPOINT`
1313
+ # - Struct or array composed with the above allowed functions, for example:
1314
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
1076
1315
  #
1077
1316
  # @example
1078
1317
  # require "google/cloud/bigquery"
@@ -1083,9 +1322,23 @@ module Google
1083
1322
  # schema.time "duration", mode: :required
1084
1323
  # end
1085
1324
  #
1325
+ # @example Add field with default value.
1326
+ # require "google/cloud/bigquery"
1327
+ #
1328
+ # bigquery = Google::Cloud::Bigquery.new
1329
+ # dataset = bigquery.dataset "my_dataset"
1330
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1331
+ # schema.time "duration", default_value_expression: "CURRENT_TIME"
1332
+ # end
1333
+ #
1086
1334
  # @!group Schema
1087
- def time name, description: nil, mode: :nullable, policy_tags: nil
1088
- schema.time name, description: description, mode: mode, policy_tags: policy_tags
1335
+ def time name, description: nil, mode: :nullable, policy_tags: nil,
1336
+ default_value_expression: nil
1337
+ schema.time name,
1338
+ description: description,
1339
+ mode: mode,
1340
+ policy_tags: policy_tags,
1341
+ default_value_expression: default_value_expression
1089
1342
  end
1090
1343
 
1091
1344
  ##
@@ -1105,6 +1358,22 @@ module Google
1105
1358
  # single policy tag for the field. Policy tag identifiers are of
1106
1359
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
1107
1360
  # At most 1 policy tag is currently allowed.
1361
+ # @param default_value_expression [String] The default value of a field
1362
+ # using a SQL expression. It can only be set for top level fields (columns).
1363
+ # Use a struct or array expression to specify default value for the entire struct or
1364
+ # array. The valid SQL expressions are:
1365
+ # - Literals for all data types, including STRUCT and ARRAY.
1366
+ # - The following functions:
1367
+ # `CURRENT_TIMESTAMP`
1368
+ # `CURRENT_TIME`
1369
+ # `CURRENT_DATE`
1370
+ # `CURRENT_DATETIME`
1371
+ # `GENERATE_UUID`
1372
+ # `RAND`
1373
+ # `SESSION_USER`
1374
+ # `ST_GEOPOINT`
1375
+ # - Struct or array composed with the above allowed functions, for example:
1376
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
1108
1377
  #
1109
1378
  # @example
1110
1379
  # require "google/cloud/bigquery"
@@ -1115,9 +1384,23 @@ module Google
1115
1384
  # schema.datetime "target_end", mode: :required
1116
1385
  # end
1117
1386
  #
1387
+ # @example Add field with default value.
1388
+ # require "google/cloud/bigquery"
1389
+ #
1390
+ # bigquery = Google::Cloud::Bigquery.new
1391
+ # dataset = bigquery.dataset "my_dataset"
1392
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1393
+ # schema.datetime "target_end", default_value_expression: "CURRENT_DATETIME"
1394
+ # end
1395
+ #
1118
1396
  # @!group Schema
1119
- def datetime name, description: nil, mode: :nullable, policy_tags: nil
1120
- schema.datetime name, description: description, mode: mode, policy_tags: policy_tags
1397
+ def datetime name, description: nil, mode: :nullable, policy_tags: nil,
1398
+ default_value_expression: nil
1399
+ schema.datetime name,
1400
+ description: description,
1401
+ mode: mode,
1402
+ policy_tags: policy_tags,
1403
+ default_value_expression: default_value_expression
1121
1404
  end
1122
1405
 
1123
1406
  ##
@@ -1137,6 +1420,22 @@ module Google
1137
1420
  # single policy tag for the field. Policy tag identifiers are of
1138
1421
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
1139
1422
  # At most 1 policy tag is currently allowed.
1423
+ # @param default_value_expression [String] The default value of a field
1424
+ # using a SQL expression. It can only be set for top level fields (columns).
1425
+ # Use a struct or array expression to specify default value for the entire struct or
1426
+ # array. The valid SQL expressions are:
1427
+ # - Literals for all data types, including STRUCT and ARRAY.
1428
+ # - The following functions:
1429
+ # `CURRENT_TIMESTAMP`
1430
+ # `CURRENT_TIME`
1431
+ # `CURRENT_DATE`
1432
+ # `CURRENT_DATETIME`
1433
+ # `GENERATE_UUID`
1434
+ # `RAND`
1435
+ # `SESSION_USER`
1436
+ # `ST_GEOPOINT`
1437
+ # - Struct or array composed with the above allowed functions, for example:
1438
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
1140
1439
  #
1141
1440
  # @example
1142
1441
  # require "google/cloud/bigquery"
@@ -1147,9 +1446,23 @@ module Google
1147
1446
  # schema.date "birthday", mode: :required
1148
1447
  # end
1149
1448
  #
1449
+ # @example Add field with default value.
1450
+ # require "google/cloud/bigquery"
1451
+ #
1452
+ # bigquery = Google::Cloud::Bigquery.new
1453
+ # dataset = bigquery.dataset "my_dataset"
1454
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1455
+ # schema.date "birthday", default_value_expression: "CURRENT_DATE"
1456
+ # end
1457
+ #
1150
1458
  # @!group Schema
1151
- def date name, description: nil, mode: :nullable, policy_tags: nil
1152
- schema.date name, description: description, mode: mode, policy_tags: policy_tags
1459
+ def date name, description: nil, mode: :nullable, policy_tags: nil,
1460
+ default_value_expression: nil
1461
+ schema.date name,
1462
+ description: description,
1463
+ mode: mode,
1464
+ policy_tags: policy_tags,
1465
+ default_value_expression: default_value_expression
1153
1466
  end
1154
1467
 
1155
1468
  ##
@@ -1171,6 +1484,22 @@ module Google
1171
1484
  # single policy tag for the field. Policy tag identifiers are of
1172
1485
  # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
1173
1486
  # At most 1 policy tag is currently allowed.
1487
+ # @param default_value_expression [String] The default value of a field
1488
+ # using a SQL expression. It can only be set for top level fields (columns).
1489
+ # Use a struct or array expression to specify default value for the entire struct or
1490
+ # array. The valid SQL expressions are:
1491
+ # - Literals for all data types, including STRUCT and ARRAY.
1492
+ # - The following functions:
1493
+ # `CURRENT_TIMESTAMP`
1494
+ # `CURRENT_TIME`
1495
+ # `CURRENT_DATE`
1496
+ # `CURRENT_DATETIME`
1497
+ # `GENERATE_UUID`
1498
+ # `RAND`
1499
+ # `SESSION_USER`
1500
+ # `ST_GEOPOINT`
1501
+ # - Struct or array composed with the above allowed functions, for example:
1502
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
1174
1503
  #
1175
1504
  # @example
1176
1505
  # require "google/cloud/bigquery"
@@ -1184,8 +1513,22 @@ module Google
1184
1513
  # end
1185
1514
  # end
1186
1515
  #
1187
- def geography name, description: nil, mode: :nullable, policy_tags: nil
1188
- schema.geography name, description: description, mode: mode, policy_tags: policy_tags
1516
+ # @example Add field with default value.
1517
+ # require "google/cloud/bigquery"
1518
+ #
1519
+ # bigquery = Google::Cloud::Bigquery.new
1520
+ # dataset = bigquery.dataset "my_dataset"
1521
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1522
+ # schema.geography "location", default_value_expression: "ST_GEOGPOINT(-122.084801, 37.422131)"
1523
+ # end
1524
+ #
1525
+ def geography name, description: nil, mode: :nullable, policy_tags: nil,
1526
+ default_value_expression: nil
1527
+ schema.geography name,
1528
+ description: description,
1529
+ mode: mode,
1530
+ policy_tags: policy_tags,
1531
+ default_value_expression: default_value_expression
1189
1532
  end
1190
1533
 
1191
1534
  ##
@@ -1205,6 +1548,23 @@ module Google
1205
1548
  # @param [Symbol] mode The field's mode. The possible values are
1206
1549
  # `:nullable`, `:required`, and `:repeated`. The default value is
1207
1550
  # `:nullable`.
1551
+ # @param default_value_expression [String] The default value of a field
1552
+ # using a SQL expression. It can only be set for top level fields (columns).
1553
+ # Use a struct or array expression to specify default value for the entire struct or
1554
+ # array. The valid SQL expressions are:
1555
+ # - Literals for all data types, including STRUCT and ARRAY.
1556
+ # - The following functions:
1557
+ # `CURRENT_TIMESTAMP`
1558
+ # `CURRENT_TIME`
1559
+ # `CURRENT_DATE`
1560
+ # `CURRENT_DATETIME`
1561
+ # `GENERATE_UUID`
1562
+ # `RAND`
1563
+ # `SESSION_USER`
1564
+ # `ST_GEOPOINT`
1565
+ # - Struct or array composed with the above allowed functions, for example:
1566
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
1567
+ #
1208
1568
  # @yield [nested_schema] a block for setting the nested schema
1209
1569
  # @yieldparam [Schema] nested_schema the object accepting the
1210
1570
  # nested schema
@@ -1221,10 +1581,23 @@ module Google
1221
1581
  # end
1222
1582
  # end
1223
1583
  #
1584
+ # @example
1585
+ # require "google/cloud/bigquery"
1586
+ #
1587
+ # bigquery = Google::Cloud::Bigquery.new
1588
+ # dataset = bigquery.dataset "my_dataset"
1589
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1590
+ # schema.record "cities_lived", default_value_expression: "STRUCT('place',10)" do |cities_lived|
1591
+ # cities_lived.string "place", mode: :required
1592
+ # cities_lived.integer "number_of_years", mode: :required
1593
+ # end
1594
+ # end
1595
+ #
1224
1596
  # @!group Schema
1225
1597
  #
1226
- def record name, description: nil, mode: nil, &block
1227
- schema.record name, description: description, mode: mode, &block
1598
+ def record name, description: nil, mode: nil, default_value_expression: nil, &block
1599
+ schema.record name, description: description, mode: mode,
1600
+ default_value_expression: default_value_expression, &block
1228
1601
  end
1229
1602
 
1230
1603
  ##