google-cloud-bigquery 1.46.1 → 1.47.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: 608b8602a5b5af958a8041da97abd1a676f5fabca08f2c7c602b4b5fcdf287fd
4
- data.tar.gz: c2fd47001c69ef30fc37007cef0d2fca3d0f3e8fc706198970ea4d8b5353ed5e
3
+ metadata.gz: 4ae89922b3fcbb32e3a271991fd06d3d67cc0691894c67093ba92aab2e075014
4
+ data.tar.gz: 8c8191361353fc7e0bf96dbaaedb23ee9bdfc994f5b82168cd7cbf576db8ed89
5
5
  SHA512:
6
- metadata.gz: 534de3f92ebda331c48ba33767983945ba6a803095e26efe7db43f037272136b582816e3c4650b82ea731c5b7749b5bfcf87075dbc5576d49083051a87fb0f7c
7
- data.tar.gz: 53cd0d50cfd12a6c79e4501ba0b5771362c5a1fd58af70c3c62748a3d4f20d1e72fa98ef74ff9f67751a1a3883b5a74302a080fa81ed3fb1a9d3d9faf30f591c
6
+ metadata.gz: c6d4a196086e10047f137593a2049af71a8de762581f8bcc43b6f71b50fb903a66ea10fa33851a3d9b6ae7c3c6c6952fd23b4c2881e3b86d2a9e966beb2b01b6
7
+ data.tar.gz: d375fad8b9cce3951cf2be7beccc4a064104ce9353f3ebce1799c652ab2bca22d00abf278cb0f2679ce1044af1835b060883a6adcfa8b7a65b9fb387c5330b1c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Release History
2
2
 
3
+ ### 1.47.0 (2024-02-05)
4
+
5
+ #### Features
6
+
7
+ * add json type support ([#24491](https://github.com/googleapis/google-cloud-ruby/issues/24491))
8
+
3
9
  ### 1.46.1 (2024-01-26)
4
10
 
5
11
  #### Bug Fixes
@@ -39,6 +39,7 @@ module Google
39
39
  # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
40
40
  # | `DATE` | `Date` | |
41
41
  # | `GEOGRAPHY` | `String` | |
42
+ # | `JSON` | `String` | String, as JSON does not have a schema to verify. |
42
43
  # | `TIMESTAMP` | `Time` | |
43
44
  # | `TIME` | `Google::Cloud::BigQuery::Time` | |
44
45
  # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
@@ -72,7 +73,7 @@ module Google
72
73
  value[:v].map { |v| format_value v, field }
73
74
  elsif Hash === value[:v]
74
75
  format_row value[:v], field.fields
75
- elsif field.type == "STRING"
76
+ elsif field.type == "STRING" || field.type == "JSON" || field.type == "GEOGRAPHY"
76
77
  String value[:v]
77
78
  elsif field.type == "INTEGER"
78
79
  Integer value[:v]
@@ -102,8 +103,6 @@ module Google
102
103
  ::Time.parse("#{value[:v]} UTC").to_datetime
103
104
  elsif field.type == "DATE"
104
105
  Date.parse value[:v]
105
- elsif field.type == "GEOGRAPHY"
106
- String value[:v]
107
106
  else
108
107
  value[:v]
109
108
  end
@@ -1180,6 +1180,7 @@ module Google
1180
1180
  # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
1181
1181
  # | `DATE` | `Date` | |
1182
1182
  # | `GEOGRAPHY` | `String` (WKT or GeoJSON) | NOT AUTOMATIC: Must be mapped using `types`, below.|
1183
+ # | `JSON` | `String` (Stringified JSON) | String, as JSON does not have a schema to verify. |
1183
1184
  # | `TIMESTAMP` | `Time` | |
1184
1185
  # | `TIME` | `Google::Cloud::BigQuery::Time` | |
1185
1186
  # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
@@ -1206,6 +1207,7 @@ module Google
1206
1207
  # * `:DATETIME`
1207
1208
  # * `:DATE`
1208
1209
  # * `:GEOGRAPHY`
1210
+ # * `:JSON`
1209
1211
  # * `:TIMESTAMP`
1210
1212
  # * `:TIME`
1211
1213
  # * `:BYTES`
@@ -1585,6 +1587,7 @@ module Google
1585
1587
  # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
1586
1588
  # | `DATE` | `Date` | |
1587
1589
  # | `GEOGRAPHY` | `String` (WKT or GeoJSON) | NOT AUTOMATIC: Must be mapped using `types`, below.|
1590
+ # | `JSON` | `String` (Stringified JSON) | String, as JSON does not have a schema to verify. |
1588
1591
  # | `TIMESTAMP` | `Time` | |
1589
1592
  # | `TIME` | `Google::Cloud::BigQuery::Time` | |
1590
1593
  # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
@@ -1611,6 +1614,7 @@ module Google
1611
1614
  # * `:DATETIME`
1612
1615
  # * `:DATE`
1613
1616
  # * `:GEOGRAPHY`
1617
+ # * `:JSON`
1614
1618
  # * `:TIMESTAMP`
1615
1619
  # * `:TIME`
1616
1620
  # * `:BYTES`
@@ -2553,6 +2557,7 @@ module Google
2553
2557
  # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
2554
2558
  # | `DATE` | `Date` | |
2555
2559
  # | `GEOGRAPHY` | `String` | |
2560
+ # | `JSON` | `String` (Stringified JSON) | String, as JSON does not have a schema to verify. |
2556
2561
  # | `TIMESTAMP` | `Time` | |
2557
2562
  # | `TIME` | `Google::Cloud::BigQuery::Time` | |
2558
2563
  # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
@@ -1531,6 +1531,71 @@ module Google
1531
1531
  default_value_expression: default_value_expression
1532
1532
  end
1533
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'"]
1568
+ #
1569
+ # @example
1570
+ # require "google/cloud/bigquery"
1571
+ #
1572
+ # bigquery = Google::Cloud::Bigquery.new
1573
+ # dataset = bigquery.dataset "my_dataset"
1574
+ # job = dataset.load_job "my_table", "gs://abc/file" do |schema|
1575
+ # schema.record "cities_lived", mode: :repeated do |cities_lived|
1576
+ # cities_lived.geography "location", mode: :required
1577
+ # cities_lived.integer "number_of_years", mode: :required
1578
+ # cities_lived.json "address", mode: :required
1579
+ # end
1580
+ # end
1581
+ #
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
1597
+ end
1598
+
1534
1599
  ##
1535
1600
  # Adds a record field to the schema. A block must be passed describing
1536
1601
  # the nested fields of the record. For more information about nested
@@ -313,6 +313,7 @@ module Google
313
313
  # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
314
314
  # | `DATE` | `Date` | |
315
315
  # | `GEOGRAPHY` | `String` (WKT or GeoJSON) | NOT AUTOMATIC: Must be mapped using `types`, below.|
316
+ # | `JSON` | `String` (Stringified JSON) | String, as JSON does not have a schema to verify. |
316
317
  # | `TIMESTAMP` | `Time` | |
317
318
  # | `TIME` | `Google::Cloud::BigQuery::Time` | |
318
319
  # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
@@ -339,6 +340,7 @@ module Google
339
340
  # * `:DATETIME`
340
341
  # * `:DATE`
341
342
  # * `:GEOGRAPHY`
343
+ # * `:JSON`
342
344
  # * `:TIMESTAMP`
343
345
  # * `:TIME`
344
346
  # * `:BYTES`
@@ -700,6 +702,7 @@ module Google
700
702
  # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
701
703
  # | `DATE` | `Date` | |
702
704
  # | `GEOGRAPHY` | `String` (WKT or GeoJSON) | NOT AUTOMATIC: Must be mapped using `types`, below.|
705
+ # | `JSON` | `String` (Stringified JSON) | String, as JSON does not have a schema to verify. |
703
706
  # | `TIMESTAMP` | `Time` | |
704
707
  # | `TIME` | `Google::Cloud::BigQuery::Time` | |
705
708
  # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
@@ -726,6 +729,7 @@ module Google
726
729
  # * `:DATETIME`
727
730
  # * `:DATE`
728
731
  # * `:GEOGRAPHY`
732
+ # * `:JSON`
729
733
  # * `:TIMESTAMP`
730
734
  # * `:TIME`
731
735
  # * `:BYTES`
@@ -927,6 +927,7 @@ module Google
927
927
  # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
928
928
  # | `DATE` | `Date` | |
929
929
  # | `GEOGRAPHY` | `String` (WKT or GeoJSON) | NOT AUTOMATIC: Must be mapped using `types`. |
930
+ # | `JSON` | `String` (Stringified JSON) | String, as JSON does not have a schema to verify.|
930
931
  # | `TIMESTAMP` | `Time` | |
931
932
  # | `TIME` | `Google::Cloud::BigQuery::Time` | |
932
933
  # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
@@ -964,6 +965,7 @@ module Google
964
965
  # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
965
966
  # | `DATE` | `Date` | |
966
967
  # | `GEOGRAPHY` | `String` (WKT or GeoJSON) | NOT AUTOMATIC: Must be mapped using `types`. |
968
+ # | `JSON` | `String` (Stringified JSON) | String, as JSON does not have a schema to verify.|
967
969
  # | `TIMESTAMP` | `Time` | |
968
970
  # | `TIME` | `Google::Cloud::BigQuery::Time` | |
969
971
  # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
@@ -990,6 +992,7 @@ module Google
990
992
  # * `:DATETIME`
991
993
  # * `:DATE`
992
994
  # * `:GEOGRAPHY`
995
+ # * `:JSON`
993
996
  # * `:TIMESTAMP`
994
997
  # * `:TIME`
995
998
  # * `:BYTES`
@@ -52,6 +52,7 @@ module Google
52
52
  "GEOGRAPHY",
53
53
  "INTEGER",
54
54
  "INT64",
55
+ "JSON",
55
56
  "NUMERIC",
56
57
  "RECORD",
57
58
  "STRING",
@@ -98,6 +99,7 @@ module Google
98
99
  # * `FLOAT`
99
100
  # * `FLOAT64` (same as `FLOAT`)
100
101
  # * `GEOGRAPHY`
102
+ # * `JSON`
101
103
  # * `INTEGER`
102
104
  # * `INT64` (same as `INTEGER`)
103
105
  # * `NUMERIC`
@@ -125,6 +127,7 @@ module Google
125
127
  # * `FLOAT`
126
128
  # * `FLOAT64` (same as `FLOAT`)
127
129
  # * `GEOGRAPHY`
130
+ # * `JSON`
128
131
  # * `INTEGER`
129
132
  # * `INT64` (same as `INTEGER`)
130
133
  # * `NUMERIC`
@@ -456,6 +459,15 @@ module Google
456
459
  type == "GEOGRAPHY"
457
460
  end
458
461
 
462
+ ##
463
+ # Checks if the type of the field is `JSON`.
464
+ #
465
+ # @return [Boolean] `true` when `JSON`, `false` otherwise.
466
+ #
467
+ def json?
468
+ type == "JSON"
469
+ end
470
+
459
471
  ##
460
472
  # Checks if the type of the field is `RECORD`.
461
473
  #
@@ -893,6 +905,30 @@ module Google
893
905
  add_field name, :geography, description: description, mode: mode, policy_tags: policy_tags
894
906
  end
895
907
 
908
+ ##
909
+ # Adds a json field to the nested schema of a record field.
910
+ #
911
+ # https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#json_type
912
+ #
913
+ # @param [String] name The field name. The name must contain only
914
+ # letters (a-z, A-Z), numbers (0-9), or underscores (_), and must
915
+ # start with a letter or underscore. The maximum length is 128
916
+ # characters.
917
+ # @param [String] description A description of the field.
918
+ # @param [Symbol] mode The field's mode. The possible values are
919
+ # `:nullable`, `:required`, and `:repeated`. The default value is
920
+ # `:nullable`.
921
+ # @param [Array<String>, String] policy_tags The policy tag list or
922
+ # single policy tag for the field. Policy tag identifiers are of
923
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
924
+ # At most 1 policy tag is currently allowed.
925
+ #
926
+ def json name, description: nil, mode: :nullable, policy_tags: nil
927
+ record_check!
928
+
929
+ add_field name, :json, description: description, mode: mode, policy_tags: policy_tags
930
+ end
931
+
896
932
  ##
897
933
  # Adds a record field to the nested schema of a record field. A block
898
934
  # must be passed describing the nested fields of the record. For more
@@ -829,6 +829,49 @@ module Google
829
829
  default_value_expression: default_value_expression
830
830
  end
831
831
 
832
+ ##
833
+ # Adds a JSON field to the schema.
834
+ #
835
+ # @see https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#json_type
836
+ #
837
+ # @param [String] name The field name. The name must contain only
838
+ # letters (`[A-Za-z]`), numbers (`[0-9]`), or underscores (`_`), and must
839
+ # start with a letter or underscore. The maximum length is 128
840
+ # characters.
841
+ # @param [String] description A description of the field.
842
+ # @param [Symbol] mode The field's mode. The possible values are
843
+ # `:nullable`, `:required`, and `:repeated`. The default value is
844
+ # `:nullable`.
845
+ # @param [Array<String>, String] policy_tags The policy tag list or
846
+ # single policy tag for the field. Policy tag identifiers are of
847
+ # the form `projects/*/locations/*/taxonomies/*/policyTags/*`.
848
+ # At most 1 policy tag is currently allowed.
849
+ # @param default_value_expression [String] The default value of a field
850
+ # using a SQL expression. It can only be set for top level fields (columns).
851
+ # Use a struct or array expression to specify default value for the entire struct or
852
+ # array. The valid SQL expressions are:
853
+ # - Literals for all data types, including STRUCT and ARRAY.
854
+ # - The following functions:
855
+ # `CURRENT_TIMESTAMP`
856
+ # `CURRENT_TIME`
857
+ # `CURRENT_DATE`
858
+ # `CURRENT_DATETIME`
859
+ # `GENERATE_UUID`
860
+ # `RAND`
861
+ # `SESSION_USER`
862
+ # `ST_GEOPOINT`
863
+ # - Struct or array composed with the above allowed functions, for example:
864
+ # "[CURRENT_DATE(), DATE '2020-01-01'"]
865
+ #
866
+ def json name, description: nil, mode: :nullable,
867
+ policy_tags: nil, default_value_expression: nil
868
+ add_field name, :json,
869
+ description: description,
870
+ mode: mode,
871
+ policy_tags: policy_tags,
872
+ default_value_expression: default_value_expression
873
+ end
874
+
832
875
  ##
833
876
  # Adds a record field to the schema. A block must be passed describing
834
877
  # the nested fields of the record. For more information about nested
@@ -111,6 +111,7 @@ module Google
111
111
  # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
112
112
  # | `DATE` | `Date` | |
113
113
  # | `GEOGRAPHY` | `String` | |
114
+ # | `JSON` | `String` (Stringified JSON) | String, as JSON does not have a schema to verify. |
114
115
  # | `TIMESTAMP` | `Time` | |
115
116
  # | `TIME` | `Google::Cloud::BigQuery::Time` | |
116
117
  # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
@@ -2648,6 +2648,7 @@ module Google
2648
2648
  # | `DATETIME` | `DateTime` | `DATETIME` does not support time zone. |
2649
2649
  # | `DATE` | `Date` | |
2650
2650
  # | `GEOGRAPHY` | `String` | Well-known text (WKT) or GeoJSON. |
2651
+ # | `JSON` | `String` (Stringified JSON) | String, as JSON does not have a schema to verify. |
2651
2652
  # | `TIMESTAMP` | `Time` | |
2652
2653
  # | `TIME` | `Google::Cloud::BigQuery::Time` | |
2653
2654
  # | `BYTES` | `File`, `IO`, `StringIO`, or similar | |
@@ -4284,6 +4285,66 @@ module Google
4284
4285
  default_value_expression: default_value_expression
4285
4286
  end
4286
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
4346
+ end
4347
+
4287
4348
  ##
4288
4349
  # Adds a record field to the schema. A block must be passed describing
4289
4350
  # the nested fields of the record. For more information about nested
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Bigquery
19
- VERSION = "1.46.1".freeze
19
+ VERSION = "1.47.0".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-bigquery
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.46.1
4
+ version: 1.47.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2024-01-26 00:00:00.000000000 Z
12
+ date: 2024-02-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby