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.
@@ -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,87 @@ 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'"]
1503
+ #
1504
+ # @example
1505
+ # require "google/cloud/bigquery"
1506
+ #
1507
+ # bigquery = Google::Cloud::Bigquery.new
1508
+ # dataset = bigquery.dataset "my_dataset"
1509
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1510
+ # schema.record "cities_lived", mode: :repeated do |cities_lived|
1511
+ # cities_lived.geography "location", mode: :required
1512
+ # cities_lived.integer "number_of_years", mode: :required
1513
+ # end
1514
+ # end
1515
+ #
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
1532
+ end
1533
+
1534
+ ##
1535
+ # Adds an json field to the schema.
1536
+ #
1537
+ # See {Schema#json}.
1538
+ # https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#json_type
1539
+ #
1540
+ # @param [String] name The field name. The name must contain only
1541
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
1542
+ # start with a letter or underscore. The maximum length is 128
1543
+ # characters.
1544
+ # @param [String] description A description of the field.
1545
+ # @param [Symbol] mode The field's mode. The possible values are
1546
+ # `:nullable`, `:required`, and `:repeated`. The default value is
1547
+ # `:nullable`.
1548
+ # @param [Array<String>, String] policy_tags The policy tag list or
1549
+ # single policy tag for the field. Policy tag identifiers are of
1550
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
1551
+ # At most 1 policy tag is currently allowed.
1552
+ # @param default_value_expression [String] The default value of a field
1553
+ # using a SQL expression. It can only be set for top level fields (columns).
1554
+ # Use a struct or array expression to specify default value for the entire struct or
1555
+ # array. The valid SQL expressions are:
1556
+ # - Literals for all data types, including STRUCT and ARRAY.
1557
+ # - The following functions:
1558
+ # `CURRENT_TIMESTAMP`
1559
+ # `CURRENT_TIME`
1560
+ # `CURRENT_DATE`
1561
+ # `CURRENT_DATETIME`
1562
+ # `GENERATE_UUID`
1563
+ # `RAND`
1564
+ # `SESSION_USER`
1565
+ # `ST_GEOPOINT`
1566
+ # - Struct or array composed with the above allowed functions, for example:
1567
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
1174
1568
  #
1175
1569
  # @example
1176
1570
  # require "google/cloud/bigquery"
@@ -1181,11 +1575,25 @@ module Google
1181
1575
  # schema.record "cities_lived", mode: :repeated do |cities_lived|
1182
1576
  # cities_lived.geography "location", mode: :required
1183
1577
  # cities_lived.integer "number_of_years", mode: :required
1578
+ # cities_lived.json "address", mode: :required
1184
1579
  # end
1185
1580
  # end
1186
1581
  #
1187
- def geography name, description: nil, mode: :nullable, policy_tags: nil
1188
- schema.geography name, description: description, mode: mode, policy_tags: policy_tags
1582
+ # @example Add field with default value.
1583
+ # require "google/cloud/bigquery"
1584
+ #
1585
+ # bigquery = Google::Cloud::Bigquery.new
1586
+ # dataset = bigquery.dataset "my_dataset"
1587
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1588
+ # schema.json "person", default_value_expression: "JSON '{"name": "Alice", "age": 30}'"
1589
+ # end
1590
+ #
1591
+ # @!group Schema
1592
+ #
1593
+ def json name, description: nil, mode: :nullable, policy_tags: nil,
1594
+ default_value_expression: nil
1595
+ schema.json name, description: description, mode: mode, policy_tags: policy_tags,
1596
+ default_value_expression: default_value_expression
1189
1597
  end
1190
1598
 
1191
1599
  ##
@@ -1205,6 +1613,23 @@ module Google
1205
1613
  # @param [Symbol] mode The field's mode. The possible values are
1206
1614
  # `:nullable`, `:required`, and `:repeated`. The default value is
1207
1615
  # `:nullable`.
1616
+ # @param default_value_expression [String] The default value of a field
1617
+ # using a SQL expression. It can only be set for top level fields (columns).
1618
+ # Use a struct or array expression to specify default value for the entire struct or
1619
+ # array. The valid SQL expressions are:
1620
+ # - Literals for all data types, including STRUCT and ARRAY.
1621
+ # - The following functions:
1622
+ # `CURRENT_TIMESTAMP`
1623
+ # `CURRENT_TIME`
1624
+ # `CURRENT_DATE`
1625
+ # `CURRENT_DATETIME`
1626
+ # `GENERATE_UUID`
1627
+ # `RAND`
1628
+ # `SESSION_USER`
1629
+ # `ST_GEOPOINT`
1630
+ # - Struct or array composed with the above allowed functions, for example:
1631
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
1632
+ #
1208
1633
  # @yield [nested_schema] a block for setting the nested schema
1209
1634
  # @yieldparam [Schema] nested_schema the object accepting the
1210
1635
  # nested schema
@@ -1221,10 +1646,23 @@ module Google
1221
1646
  # end
1222
1647
  # end
1223
1648
  #
1649
+ # @example
1650
+ # require "google/cloud/bigquery"
1651
+ #
1652
+ # bigquery = Google::Cloud::Bigquery.new
1653
+ # dataset = bigquery.dataset "my_dataset"
1654
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1655
+ # schema.record "cities_lived", default_value_expression: "STRUCT('place',10)" do |cities_lived|
1656
+ # cities_lived.string "place", mode: :required
1657
+ # cities_lived.integer "number_of_years", mode: :required
1658
+ # end
1659
+ # end
1660
+ #
1224
1661
  # @!group Schema
1225
1662
  #
1226
- def record name, description: nil, mode: nil, &block
1227
- schema.record name, description: description, mode: mode, &block
1663
+ def record name, description: nil, mode: nil, default_value_expression: nil, &block
1664
+ schema.record name, description: description, mode: mode,
1665
+ default_value_expression: default_value_expression, &block
1228
1666
  end
1229
1667
 
1230
1668
  ##
@@ -1330,6 +1768,37 @@ module Google
1330
1768
  @gapi.configuration.load.update! write_disposition: Convert.write_disposition(new_write)
1331
1769
  end
1332
1770
 
1771
+ ##
1772
+ # Sets the create_session property. If true, creates a new session,
1773
+ # where session id will be a server generated random id. If false,
1774
+ # runs query with an existing {#session_id=}, otherwise runs query in
1775
+ # non-session mode. The default value is `false`.
1776
+ #
1777
+ # @param [Boolean] value The create_session property. The default
1778
+ # value is `false`.
1779
+ #
1780
+ # @!group Attributes
1781
+ def create_session= value
1782
+ @gapi.configuration.load.create_session = value
1783
+ end
1784
+
1785
+ ##
1786
+ # Sets the session ID for a query run in session mode. See {#create_session=}.
1787
+ #
1788
+ # @param [String] value The session ID. The default value is `nil`.
1789
+ #
1790
+ # @!group Attributes
1791
+ def session_id= value
1792
+ @gapi.configuration.load.connection_properties ||= []
1793
+ prop = @gapi.configuration.load.connection_properties.find { |cp| cp.key == "session_id" }
1794
+ if prop
1795
+ prop.value = value
1796
+ else
1797
+ prop = Google::Apis::BigqueryV2::ConnectionProperty.new key: "session_id", value: value
1798
+ @gapi.configuration.load.connection_properties << prop
1799
+ end
1800
+ end
1801
+
1333
1802
  ##
1334
1803
  # Sets the projection fields.
1335
1804
  #