google-cloud-bigquery 1.53.0 → 1.54.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0844316676c10ea437a2901f4693a347786a147f4fb11af5de161083fba04edd'
4
- data.tar.gz: 3a4a37fa591e5ff75d40680872fda8188dc136d011d9742e35a5d87611ebd81c
3
+ metadata.gz: cbfaf1f9de532a42e02ae04ce9a3373b337b401491a746a10e103c708b01d069
4
+ data.tar.gz: 3d7dd0f1213c69fcb79fee23f342f3e435c66842af1cc7569bf7c861f5f54773
5
5
  SHA512:
6
- metadata.gz: 8a2aed50235c51c87c03a36ab5f2564d46fe5ffc1f98dee981b691c0f818ca3275511ce44ccb7f23786f324092eaf929bfcc2b79c100565984d6fa54e674c001
7
- data.tar.gz: 56c77db151cf32224701742e1fa707a246ac8dd6df4802aead2eb7e017c8b5e3ce96960d4b1999194c054c20b1bcfdc8ee274d5a1a3954f50d6d6745a5451874
6
+ metadata.gz: 4144ce5964844c6f8aebc2e12049639a6e42c65d74458617b88836b7bccded75c061315548c49d0030f1667a8890496911e9d8334d518adc40c0b416dc968ffe
7
+ data.tar.gz: 46d49fb84f11c0b97211ba5099a11be5001a21b20df26a21a4a31843633abba9869dad0cb4f80a9674156c5a4d78d84af2cfef9b77ee52395987e8e7637ce7b9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Release History
2
2
 
3
+ ### 1.54.0 (2025-08-15)
4
+
5
+ #### Features
6
+
7
+ * Add support for format_options_use_int64_timestamp ([#30755](https://github.com/googleapis/google-cloud-ruby/issues/30755))
8
+ * load job external table options ([#30743](https://github.com/googleapis/google-cloud-ruby/issues/30743))
9
+
3
10
  ### 1.53.0 (2025-08-12)
4
11
 
5
12
  #### Features
@@ -60,6 +60,10 @@ module Google
60
60
  end
61
61
  end
62
62
 
63
+ def self.is_int? value
64
+ /\A\s*[-+]?\d+\s*\z/.match? value.to_s
65
+ end
66
+
63
67
  # rubocop:disable all
64
68
 
65
69
  def self.format_value value, field
@@ -96,7 +100,12 @@ module Google
96
100
  elsif field.type == "BYTES"
97
101
  StringIO.new Base64.decode64 value[:v]
98
102
  elsif field.type == "TIMESTAMP"
99
- ::Time.at Float(value[:v])
103
+ if is_int?(value[:v])
104
+ # Convert microseconds to seconds
105
+ ::Time.at Rational(Integer(value[:v]), 1_000_000)
106
+ else
107
+ ::Time.at Rational(value[:v])
108
+ end
100
109
  elsif field.type == "TIME"
101
110
  Bigquery::Time.new value[:v]
102
111
  elsif field.type == "DATETIME"
@@ -66,6 +66,10 @@ module Google
66
66
  # @private The query Job gapi object, or nil if from Table#data.
67
67
  attr_accessor :job_gapi
68
68
 
69
+ ##
70
+ # @private Whether to output timestamp as usec int64.
71
+ attr_accessor :format_options_use_int64_timestamp
72
+
69
73
  # @private
70
74
  def initialize arr = []
71
75
  @service = nil
@@ -473,8 +477,9 @@ module Google
473
477
  data_json = service.list_tabledata \
474
478
  @table_gapi.table_reference.dataset_id,
475
479
  @table_gapi.table_reference.table_id,
476
- token: token
477
- self.class.from_gapi_json data_json, @table_gapi, job_gapi, @service
480
+ token: token,
481
+ format_options_use_int64_timestamp: @format_options_use_int64_timestamp
482
+ self.class.from_gapi_json data_json, @table_gapi, job_gapi, @service, @format_options_use_int64_timestamp
478
483
  end
479
484
 
480
485
  ##
@@ -549,7 +554,7 @@ module Google
549
554
 
550
555
  ##
551
556
  # @private New Data from a response object.
552
- def self.from_gapi_json gapi_json, table_gapi, job_gapi, service
557
+ def self.from_gapi_json gapi_json, table_gapi, job_gapi, service, format_options_use_int64_timestamp
553
558
  rows = gapi_json[:rows] || []
554
559
  rows = Convert.format_rows rows, table_gapi.schema.fields unless rows.empty?
555
560
 
@@ -558,6 +563,7 @@ module Google
558
563
  data.gapi_json = gapi_json
559
564
  data.job_gapi = job_gapi
560
565
  data.service = service
566
+ data.format_options_use_int64_timestamp = format_options_use_int64_timestamp
561
567
  data
562
568
  end
563
569
 
@@ -1710,6 +1710,8 @@ module Google
1710
1710
  # `flatten` is false. Optional. The default value is false.
1711
1711
  # @param [String] session_id The ID of an existing session. See the
1712
1712
  # `create_session` param in {#query_job} and {Job#session_id}.
1713
+ # @param [Boolean] format_options_use_int64_timestamp Output timestamp
1714
+ # as usec int64. Default is true.
1713
1715
  # @yield [job] a job configuration object
1714
1716
  # @yieldparam [Google::Cloud::Bigquery::QueryJob::Updater] job a job
1715
1717
  # configuration object for setting additional options for the query.
@@ -1864,6 +1866,7 @@ module Google
1864
1866
  standard_sql: nil,
1865
1867
  legacy_sql: nil,
1866
1868
  session_id: nil,
1869
+ format_options_use_int64_timestamp: true,
1867
1870
  &block
1868
1871
  job = query_job query,
1869
1872
  params: params,
@@ -1877,7 +1880,7 @@ module Google
1877
1880
  job.wait_until_done!
1878
1881
  ensure_job_succeeded! job
1879
1882
 
1880
- job.data max: max
1883
+ job.data max: max, format_options_use_int64_timestamp: format_options_use_int64_timestamp
1881
1884
  end
1882
1885
 
1883
1886
  ##
@@ -367,6 +367,177 @@ module Google
367
367
  @gapi.csv_options.skip_leading_rows = row_count
368
368
  end
369
369
 
370
+ ##
371
+ # Specifies a string that represents a null value in a CSV file. For
372
+ # example, if you specify `\N`, BigQuery interprets `\N` as a null value when
373
+ # querying a CSV file. The default value is the empty string. If you set this
374
+ # property to a custom value, BigQuery throws an error if an empty string is
375
+ # present for all data types except for STRING and BYTE. For STRING and BYTE
376
+ # columns, BigQuery interprets the empty string as an empty value.
377
+ #
378
+ # @return [String, nil] The null marker string. `nil` if not set.
379
+ #
380
+ # @example
381
+ # require "google/cloud/bigquery"
382
+ #
383
+ # bigquery = Google::Cloud::Bigquery.new
384
+ #
385
+ # csv_url = "gs://bucket/path/to/data.csv"
386
+ # csv_table = bigquery.external csv_url do |csv|
387
+ # csv.null_marker = "\N"
388
+ # end
389
+ #
390
+ # csv_table.null_marker #=> "\N"
391
+ #
392
+ def null_marker
393
+ @gapi.csv_options.null_marker
394
+ end
395
+
396
+ ##
397
+ # Sets a string that represents a null value in a CSV file. For
398
+ # example, if you specify `\N`, BigQuery interprets `\N` as a null value when
399
+ # querying a CSV file. The default value is the empty string. If you set this
400
+ # property to a custom value, BigQuery throws an error if an empty string is
401
+ # present for all data types except for STRING and BYTE. For STRING and BYTE
402
+ # columns, BigQuery interprets the empty string as an empty value.
403
+ #
404
+ # @param [String, nil] null_marker The null marker string. `nil` to unset.
405
+ #
406
+ # @example
407
+ # require "google/cloud/bigquery"
408
+ #
409
+ # bigquery = Google::Cloud::Bigquery.new
410
+ #
411
+ # csv_url = "gs://bucket/path/to/data.csv"
412
+ # csv_table = bigquery.external csv_url do |csv|
413
+ # csv.null_marker = "\N"
414
+ # end
415
+ #
416
+ # csv_table.null_marker #=> "\N"
417
+ #
418
+ def null_marker= null_marker
419
+ frozen_check!
420
+ @gapi.csv_options.null_marker = null_marker
421
+ end
422
+
423
+ ##
424
+ # The list of strings represented as SQL NULL value in a CSV file.
425
+ # null_marker and null_markers can't be set at the same time. If null_marker is
426
+ # set, null_markers has to be not set. If null_markers is set, null_marker has
427
+ # to be not set. If both null_marker and null_markers are set at the same time,
428
+ # a user error would be thrown. Any strings listed in null_markers, including
429
+ # empty string would be interpreted as SQL NULL. This applies to all column
430
+ # types.
431
+ #
432
+ # @return [Array<String>] The array of null marker strings.
433
+ #
434
+ # @example
435
+ # require "google/cloud/bigquery"
436
+ #
437
+ # bigquery = Google::Cloud::Bigquery.new
438
+ #
439
+ # csv_url = "gs://bucket/path/to/data.csv"
440
+ # csv_table = bigquery.external csv_url do |csv|
441
+ # csv.null_markers = ["\N", "NULL"]
442
+ # end
443
+ #
444
+ # csv_table.null_markers #=> ["\N", "NULL"]
445
+ #
446
+ def null_markers
447
+ @gapi.csv_options.null_markers || []
448
+ end
449
+
450
+ ##
451
+ # Sets the list of strings represented as SQL NULL value in a CSV file.
452
+ # null_marker and null_markers can't be set at the same time. If null_marker is
453
+ # set, null_markers has to be not set. If null_markers is set, null_marker has
454
+ # to be not set. If both null_marker and null_markers are set at the same time,
455
+ # a user error would be thrown. Any strings listed in null_markers, including
456
+ # empty string would be interpreted as SQL NULL. This applies to all column
457
+ # types.
458
+ #
459
+ # @param [Array<String>] null_markers The array of null marker strings.
460
+ #
461
+ #
462
+ # @example
463
+ # require "google/cloud/bigquery"
464
+ #
465
+ # bigquery = Google::Cloud::Bigquery.new
466
+ #
467
+ # csv_url = "gs://bucket/path/to/data.csv"
468
+ # csv_table = bigquery.external csv_url do |csv|
469
+ # csv.null_markers = ["\N", "NULL"]
470
+ # end
471
+ #
472
+ # csv_table.null_markers #=> ["\N", "NULL"]
473
+ #
474
+ def null_markers= null_markers
475
+ frozen_check!
476
+ @gapi.csv_options.null_markers = null_markers
477
+ end
478
+
479
+ # Controls the strategy used to match loaded columns to the schema.
480
+ # If not set, a sensible default is chosen based on how the schema is
481
+ # provided. If autodetect is used, then columns are matched by name.
482
+ # Otherwise, columns are matched by position. This is done to keep the
483
+ # behavior backward-compatible.
484
+ #
485
+ # Acceptable values are:
486
+ # - `POSITION`: matches by position. Assumes columns are ordered the
487
+ # same way as the schema.
488
+ # - `NAME`: matches by name. Reads the header row as column names and
489
+ # reorders columns to match the schema.
490
+ #
491
+ # @return [String, nil] The source column match value. `nil` if not set.
492
+ #
493
+ # @example
494
+ # require "google/cloud/bigquery"
495
+ #
496
+ # bigquery = Google::Cloud::Bigquery.new
497
+ #
498
+ # csv_url = "gs://bucket/path/to/data.csv"
499
+ # csv_table = bigquery.external csv_url do |csv|
500
+ # csv.source_column_match = "NAME"
501
+ # end
502
+ #
503
+ # csv_table.source_column_match #=> "NAME"
504
+ #
505
+ def source_column_match
506
+ @gapi.csv_options.source_column_match
507
+ end
508
+
509
+ # Sets the strategy used to match loaded columns to the schema.
510
+ # If not set, a sensible default is chosen based on how the schema is
511
+ # provided. If autodetect is used, then columns are matched by name.
512
+ # Otherwise, columns are matched by position. This is done to keep the
513
+ # behavior backward-compatible. Optional.
514
+ #
515
+ # Acceptable values are:
516
+ # - `POSITION`: matches by position. Assumes columns are ordered the
517
+ # same way as the schema.
518
+ # - `NAME`: matches by name. Reads the header row as column names and
519
+ # reorders columns to match the schema.
520
+ #
521
+ # @param [String, nil] source_column_match The new source column match value. `nil` to unset.
522
+ #
523
+ #
524
+ # @example
525
+ # require "google/cloud/bigquery"
526
+ #
527
+ # bigquery = Google::Cloud::Bigquery.new
528
+ #
529
+ # csv_url = "gs://bucket/path/to/data.csv"
530
+ # csv_table = bigquery.external csv_url do |csv|
531
+ # csv.source_column_match = "NAME"
532
+ # end
533
+ #
534
+ # csv_table.source_column_match #=> "NAME"
535
+ #
536
+ def source_column_match= source_column_match
537
+ frozen_check!
538
+ @gapi.csv_options.source_column_match = source_column_match
539
+ end
540
+
370
541
  ##
371
542
  # The schema for the data.
372
543
  #
@@ -744,6 +744,222 @@ module Google
744
744
  @gapi.hive_partitioning_options.source_uri_prefix = source_uri_prefix
745
745
  end
746
746
 
747
+ ##
748
+ # Time zone used when parsing timestamp values that do not have specific
749
+ # time zone information (e.g. `2024-04-20 12:34:56`). The expected format
750
+ # is an IANA timezone string (e.g. `America/Los_Angeles`).
751
+ #
752
+ # @return [String, nil] The IANA time zone name. `nil` if not set.
753
+ #
754
+ # @example
755
+ # require "google/cloud/bigquery"
756
+ #
757
+ # bigquery = Google::Cloud::Bigquery.new
758
+ #
759
+ # external_data = bigquery.external "gs://bucket/path/to/data.csv" do |ext|
760
+ # ext.time_zone = "America/Los_Angeles"
761
+ # end
762
+ #
763
+ # external_data.time_zone #=> "America/Los_Angeles"
764
+ #
765
+ def time_zone
766
+ @gapi.time_zone
767
+ end
768
+
769
+ ##
770
+ # Sets the time zone used when parsing timestamp values that do not have
771
+ # specific time zone information (e.g. `2024-04-20 12:34:56`). The expected
772
+ # format is an IANA timezone string (e.g. `America/Los_Angeles`).
773
+ #
774
+ # @param [String, nil] time_zone The IANA time zone name. `nil` to unset.
775
+ #
776
+ # @example
777
+ # require "google/cloud/bigquery"
778
+ #
779
+ # bigquery = Google::Cloud::Bigquery.new
780
+ #
781
+ # external_data = bigquery.external "gs://bucket/path/to/data.csv" do |ext|
782
+ # ext.time_zone = "America/Los_Angeles"
783
+ # end
784
+ #
785
+ # external_data.time_zone #=> "America/Los_Angeles"
786
+ #
787
+ def time_zone= time_zone
788
+ frozen_check!
789
+ @gapi.time_zone = time_zone
790
+ end
791
+
792
+ ##
793
+ # Format used to parse TIME values. Supports C-style and SQL-style values.
794
+ #
795
+ # @return [String, nil] The time format pattern. `nil` if not set.
796
+ #
797
+ # @example
798
+ # require "google/cloud/bigquery"
799
+ #
800
+ # bigquery = Google::Cloud::Bigquery.new
801
+ #
802
+ # external_data = bigquery.external "gs://bucket/path/to/data.csv" do |ext|
803
+ # ext.time_format = "%H:%M:%S"
804
+ # end
805
+ #
806
+ # external_data.time_format #=> "%H:%M:%S"
807
+ #
808
+ def time_format
809
+ @gapi.time_format
810
+ end
811
+
812
+ ##
813
+ # Sets the format used to parse TIME values. Supports C-style and SQL-style
814
+ # values.
815
+ #
816
+ # @param [String, nil] time_format The time format pattern. `nil` if not set.
817
+ #
818
+ # @example
819
+ # require "google/cloud/bigquery"
820
+ #
821
+ # bigquery = Google::Cloud::Bigquery.new
822
+ #
823
+ # external_data = bigquery.external "gs://bucket/path/to/data.csv" do |ext|
824
+ # ext.time_format = "%H:%M:%S"
825
+ # end
826
+ #
827
+ # external_data.time_format #=> "%H:%M:%S"
828
+ #
829
+ def time_format= time_format
830
+ frozen_check!
831
+ @gapi.time_format = time_format
832
+ end
833
+
834
+ ##
835
+ # Format used to parse TIMESTAMP values. Supports C-style and SQL-style
836
+ # values.
837
+ #
838
+ # @return [String, nil] The timestamp format pattern. `nil` if not set.
839
+ #
840
+ # @example
841
+ # require "google/cloud/bigquery"
842
+ #
843
+ # bigquery = Google::Cloud::Bigquery.new
844
+ #
845
+ # external_data = bigquery.external "gs://bucket/path/to/data.csv" do |ext|
846
+ # ext.timestamp_format = "%Y-%m-%d %H:%M:%S.%f %z"
847
+ # end
848
+ #
849
+ # external_data.timestamp_format #=> "%Y-%m-%d %H:%M:%S.%f %z"
850
+ #
851
+ def timestamp_format
852
+ @gapi.timestamp_format
853
+ end
854
+
855
+ ##
856
+ # Sets the format used to parse TIMESTAMP values. Supports C-style and SQL-style
857
+ # values.
858
+ #
859
+ # @param [String, nil] timestamp_format The timestamp format pattern. `nil` to unset.
860
+ #
861
+ # @example
862
+ # require "google/cloud/bigquery"
863
+ #
864
+ # bigquery = Google::Cloud::Bigquery.new
865
+ #
866
+ # external_data = bigquery.external "gs://bucket/path/to/data.csv" do |ext|
867
+ # ext.timestamp_format = "%Y-%m-%d %H:%M:%S.%f %z"
868
+ # end
869
+ #
870
+ # external_data.timestamp_format #=> "%Y-%m-%d %H:%M:%S.%f %z"
871
+ #
872
+ def timestamp_format= timestamp_format
873
+ frozen_check!
874
+ @gapi.timestamp_format = timestamp_format
875
+ end
876
+
877
+ ##
878
+ # Format used to parse DATETIME values. Supports C-style and SQL-style
879
+ # values.
880
+ #
881
+ # @return [String, nil] The datetime format pattern. `nil` if not set.
882
+ #
883
+ # @example
884
+ # require "google/cloud/bigquery"
885
+ #
886
+ # bigquery = Google::Cloud::Bigquery.new
887
+ #
888
+ # external_data = bigquery.external "gs://bucket/path/to/data.csv" do |ext|
889
+ # ext.datetime_format = "%Y-%m-%d %H:%M:%S"
890
+ # end
891
+ #
892
+ # external_data.datetime_format #=> "%Y-%m-%d %H:%M:%S"
893
+ #
894
+ def datetime_format
895
+ @gapi.datetime_format
896
+ end
897
+
898
+ ##
899
+ # Sets the format used to parse DATETIME values. Supports C-style and SQL-style
900
+ # values.
901
+ #
902
+ # @param [String, nil] datetime_format The datetime format pattern. `nil` to unset.
903
+ #
904
+ # @example
905
+ # require "google/cloud/bigquery"
906
+ #
907
+ # bigquery = Google::Cloud::Bigquery.new
908
+ #
909
+ # external_data = bigquery.external "gs://bucket/path/to/data.csv" do |ext|
910
+ # ext.datetime_format = "%Y-%m-%d %H:%M:%S"
911
+ # end
912
+ #
913
+ # external_data.datetime_format #=> "%Y-%m-%d %H:%M:%S"
914
+ #
915
+ def datetime_format= datetime_format
916
+ frozen_check!
917
+ @gapi.datetime_format = datetime_format
918
+ end
919
+
920
+ ##
921
+ # Format used to parse DATE values. Supports C-style and SQL-style
922
+ # values.
923
+ #
924
+ # @return [String, nil] The date format pattern. `nil` if not set.
925
+ #
926
+ # @example
927
+ # require "google/cloud/bigquery"
928
+ #
929
+ # bigquery = Google::Cloud::Bigquery.new
930
+ #
931
+ # external_data = bigquery.external "gs://bucket/path/to/data.csv" do |ext|
932
+ # ext.date_format = "%Y-%m-%d"
933
+ # end
934
+ #
935
+ # external_data.date_format #=> "%Y-%m-%d"
936
+ #
937
+ def date_format
938
+ @gapi.date_format
939
+ end
940
+
941
+ ##
942
+ # Sets the format used to parse DATE values. Supports C-style and SQL-style
943
+ # values.
944
+ #
945
+ # @param [String, nil] date_format The date format pattern. `nil` to unset.
946
+ #
947
+ # @example
948
+ # require "google/cloud/bigquery"
949
+ #
950
+ # bigquery = Google::Cloud::Bigquery.new
951
+ #
952
+ # external_data = bigquery.external "gs://bucket/path/to/data.csv" do |ext|
953
+ # ext.date_format = "%Y-%m-%d"
954
+ # end
955
+ #
956
+ # external_data.date_format #=> "%Y-%m-%d"
957
+ #
958
+ def date_format= date_format
959
+ frozen_check!
960
+ @gapi.date_format = date_format
961
+ end
962
+
747
963
  ##
748
964
  # @private Google API Client object.
749
965
  def to_gapi
@@ -652,6 +652,90 @@ module Google
652
652
  @gapi.configuration.load.clustering.fields if clustering?
653
653
  end
654
654
 
655
+ ##
656
+ # Format used to parse DATE values. Supports C-style and SQL-style
657
+ # values.
658
+ #
659
+ # @return [String, nil] The date format pattern, such as
660
+ # `%Y-%m-%d`. `nil` if not set.
661
+ def date_format
662
+ @gapi.configuration.load.date_format
663
+ end
664
+
665
+ ##
666
+ # Format used to parse DATETIME values. Supports C-style and SQL-style
667
+ # values.
668
+ #
669
+ # @return [String, nil] The datetime format pattern, such as
670
+ # `%Y-%m-%d %H:%M:%S`. `nil` if not set.
671
+ def datetime_format
672
+ @gapi.configuration.load.datetime_format
673
+ end
674
+
675
+ ##
676
+ # Format used to parse TIME values. Supports C-style and SQL-style
677
+ # values.
678
+ #
679
+ # @return [String, nil] The time format pattern, such as
680
+ # `%H:%M:%S`. `nil` if not set.
681
+ def time_format
682
+ @gapi.configuration.load.time_format
683
+ end
684
+
685
+ ##
686
+ # Format used to parse TIMESTAMP values. Supports C-style and SQL-style
687
+ # values.
688
+ #
689
+ # @return [String, nil] The timestamp format pattern, such as
690
+ # `%Y-%m-%d %H:%M:%S.%f %z`. `nil` if not set.
691
+ def timestamp_format
692
+ @gapi.configuration.load.timestamp_format
693
+ end
694
+
695
+ ##
696
+ # A list of strings represented as SQL NULL value in a CSV file.
697
+ # null_marker and null_markers can't be set at the same time. If null_marker
698
+ # is set, null_markers has to be not set. If null_markers is set, null_marker
699
+ # has to be not set. If both null_marker and null_markers are set at the same
700
+ # time, a user error would be thrown. Any strings listed in null_markers,
701
+ # including empty string would be interpreted as SQL NULL. This applies to all
702
+ # column types.
703
+ #
704
+ # @return [Array<String>] The array of null marker strings.
705
+ def null_markers
706
+ @gapi.configuration.load.null_markers || []
707
+ end
708
+
709
+ ##
710
+ # Controls the strategy used to match loaded columns to the schema. If
711
+ # not set, a sensible default is chosen based on how the schema is provided.
712
+ # If autodetect is used, then columns are matched by name. Otherwise,
713
+ # columns are matched by position. This is done to keep the behavior
714
+ # backward-compatible.
715
+ #
716
+ # Acceptable values are:
717
+ # * `POSITION` - matches by position. This assumes that the columns are
718
+ # ordered the same way as the schema.
719
+ # * `NAME` - matches by name. This reads the header row as column names
720
+ # and reorders columns to match the field names in the schema.
721
+ #
722
+ # @return [String, nil] The source column match strategy, such as
723
+ # `POSITION`. `nil` if not set.
724
+ def source_column_match
725
+ @gapi.configuration.load.source_column_match
726
+ end
727
+
728
+ ##
729
+ # Time zone used when parsing timestamp values that do not have specific
730
+ # time zone information (e.g. `2024-04-20 12:34:56`). The expected format
731
+ # is an IANA timezone string (e.g. `America/Los_Angeles`).
732
+ #
733
+ # @return [String, nil] The IANA time zone name, such as
734
+ # `America/Los_Angeles`. `nil` if not set.
735
+ def time_zone
736
+ @gapi.configuration.load.time_zone
737
+ end
738
+
655
739
  ##
656
740
  # Yielded to a block to accumulate changes for a patch request.
657
741
  class Updater < LoadJob
@@ -2585,6 +2669,89 @@ module Google
2585
2669
  @gapi.configuration.load.clustering.fields = fields
2586
2670
  end
2587
2671
 
2672
+ ##
2673
+ # Sets the format used to parse DATE values. Supports C-style and SQL-style
2674
+ # values.
2675
+ #
2676
+ # @param [String, nil] date_format The date format pattern, such as
2677
+ # `%Y-%m-%d`. `nil` to unset.
2678
+ def date_format= date_format
2679
+ @gapi.configuration.load.update! date_format: date_format
2680
+ end
2681
+
2682
+ ##
2683
+ # Sets the format used to parse DATETIME values. Supports C-style and SQL-style
2684
+ # values.
2685
+ #
2686
+ # @param [String, nil] datetime_format The datetime format pattern, such as
2687
+ # `%Y-%m-%d %H:%M:%S`. `nil` to unset.
2688
+ def datetime_format= datetime_format
2689
+ @gapi.configuration.load.update! datetime_format: datetime_format
2690
+ end
2691
+
2692
+ ##
2693
+ # Sets the format used to parse TIME values. Supports C-style and SQL-style
2694
+ # values.
2695
+ #
2696
+ # @param [String, nil] time_format The time format pattern, such as
2697
+ # `%H:%M:%S`. `nil` to unset.
2698
+ def time_format= time_format
2699
+ @gapi.configuration.load.update! time_format: time_format
2700
+ end
2701
+
2702
+ ##
2703
+ # Sets the format used to parse TIMESTAMP values. Supports C-style and SQL-style
2704
+ # values.
2705
+ #
2706
+ # @param [String, nil] timestamp_format The timestamp format pattern, such as
2707
+ # `%Y-%m-%d %H:%M:%S.%f %z`. `nil` to unset.
2708
+ def timestamp_format= timestamp_format
2709
+ @gapi.configuration.load.update! timestamp_format: timestamp_format
2710
+ end
2711
+
2712
+ ##
2713
+ # Sets the list of strings represented as SQL NULL value in a CSV file.
2714
+ # null_marker and null_markers can't be set at the same time. If null_marker is
2715
+ # set, null_markers has to be not set. If null_markers is set, null_marker has
2716
+ # to be not set. If both null_marker and null_markers are set at the same time,
2717
+ # a user error would be thrown. Any strings listed in null_markers, including
2718
+ # empty string would be interpreted as SQL NULL. This applies to all column
2719
+ # types.
2720
+ #
2721
+ # @param [Array<String>] null_markers The array of null marker strings.
2722
+ def null_markers= null_markers
2723
+ @gapi.configuration.load.update! null_markers: null_markers
2724
+ end
2725
+
2726
+ # Sets the strategy used to match loaded columns to the schema.
2727
+ # If not set, a sensible default is chosen based on how the schema is
2728
+ # provided. If autodetect is used, then columns are matched by name.
2729
+ # Otherwise, columns are matched by position. This is done to keep the
2730
+ # behavior backward-compatible.
2731
+ #
2732
+ # Acceptable values are:
2733
+ # - `POSITION`: matches by position. Assumes columns are ordered the
2734
+ # same way as the schema.
2735
+ # - `NAME`: matches by name. Reads the header row as column names and
2736
+ # reorders columns to match the schema.
2737
+ #
2738
+ # @param [String, nil] source_column_match The new source column match value.
2739
+ # `nil` to unset.
2740
+ def source_column_match= source_column_match
2741
+ @gapi.configuration.load.update! source_column_match: source_column_match
2742
+ end
2743
+
2744
+ ##
2745
+ # Sets the time zone used when parsing timestamp values that do not have
2746
+ # specific time zone information (e.g. `2024-04-20 12:34:56`). The expected
2747
+ # format is an IANA timezone string (e.g. `America/Los_Angeles`).
2748
+ #
2749
+ # @param [String, nil] time_zone The IANA time zone name, such as
2750
+ # `America/Los_Angeles`. `nil` to unset.
2751
+ def time_zone= time_zone
2752
+ @gapi.configuration.load.update! time_zone: time_zone
2753
+ end
2754
+
2588
2755
  def cancel
2589
2756
  raise "not implemented in #{self.class}"
2590
2757
  end
@@ -783,6 +783,9 @@ module Google
783
783
  # `flatten` is false. Optional. The default value is false.
784
784
  # @param [String] session_id The ID of an existing session. See the
785
785
  # `create_session` param in {#query_job} and {Job#session_id}.
786
+ # @param [Boolean] format_options_use_int64_timestamp Output timestamp
787
+ # as usec int64. Default is true.
788
+ #
786
789
  # @yield [job] a job configuration object
787
790
  # @yieldparam [Google::Cloud::Bigquery::QueryJob::Updater] job a job
788
791
  # configuration object for setting additional options for the query.
@@ -929,6 +932,7 @@ module Google
929
932
  standard_sql: nil,
930
933
  legacy_sql: nil,
931
934
  session_id: nil,
935
+ format_options_use_int64_timestamp: true,
932
936
  &block
933
937
  job = query_job query,
934
938
  params: params,
@@ -953,7 +957,7 @@ module Google
953
957
  end
954
958
  end
955
959
 
956
- job.data max: max
960
+ job.data max: max, format_options_use_int64_timestamp: format_options_use_int64_timestamp
957
961
  end
958
962
 
959
963
  ##
@@ -723,6 +723,8 @@ module Google
723
723
  # identifying the result set.
724
724
  # @param [Integer] max Maximum number of results to return.
725
725
  # @param [Integer] start Zero-based index of the starting row to read.
726
+ # @param [Boolean] format_options_use_int64_timestamp Output timestamp
727
+ # as usec int64. Default is true.
726
728
  #
727
729
  # @return [Google::Cloud::Bigquery::Data] An object providing access to
728
730
  # data read from the destination table for the job.
@@ -745,20 +747,21 @@ module Google
745
747
  # # Retrieve the next page of results
746
748
  # data = data.next if data.next?
747
749
  #
748
- def data token: nil, max: nil, start: nil
750
+ def data token: nil, max: nil, start: nil, format_options_use_int64_timestamp: true
749
751
  return nil unless done?
750
- return Data.from_gapi_json({ rows: [] }, nil, @gapi, service) if dryrun?
752
+ return Data.from_gapi_json({ rows: [] }, nil, @gapi, service, format_options_use_int64_timestamp) if dryrun?
751
753
  if ddl? || dml? || !ensure_schema!
752
754
  data_hash = { totalRows: nil, rows: [] }
753
- return Data.from_gapi_json data_hash, nil, @gapi, service
755
+ return Data.from_gapi_json data_hash, nil, @gapi, service, format_options_use_int64_timestamp
754
756
  end
755
757
 
756
758
  data_hash = service.list_tabledata destination_table_dataset_id,
757
759
  destination_table_table_id,
758
760
  token: token,
759
761
  max: max,
760
- start: start
761
- Data.from_gapi_json data_hash, destination_table_gapi, @gapi, service
762
+ start: start,
763
+ format_options_use_int64_timestamp: format_options_use_int64_timestamp
764
+ Data.from_gapi_json data_hash, destination_table_gapi, @gapi, service, format_options_use_int64_timestamp
762
765
  end
763
766
  alias query_results data
764
767
 
@@ -244,7 +244,8 @@ module Google
244
244
 
245
245
  ##
246
246
  # Retrieves data from the table.
247
- def list_tabledata dataset_id, table_id, max: nil, token: nil, start: nil
247
+ def list_tabledata dataset_id, table_id, max: nil, token: nil, start: nil,
248
+ format_options_use_int64_timestamp: nil
248
249
  # The list operation is considered idempotent
249
250
  execute backoff: true do
250
251
  json_txt = service.list_table_data \
@@ -252,7 +253,8 @@ module Google
252
253
  max_results: max,
253
254
  page_token: token,
254
255
  start_index: start,
255
- options: { skip_deserialization: true }
256
+ options: { skip_deserialization: true },
257
+ format_options_use_int64_timestamp: format_options_use_int64_timestamp
256
258
  JSON.parse json_txt, symbolize_names: true
257
259
  end
258
260
  end
@@ -456,7 +458,8 @@ module Google
456
458
 
457
459
  ##
458
460
  # Returns the query data for the job
459
- def job_query_results job_id, location: nil, max: nil, token: nil, start: nil, timeout: nil
461
+ def job_query_results job_id, location: nil, max: nil, token: nil,
462
+ start: nil, timeout: nil, format_options_use_int64_timestamp: nil
460
463
  # The get operation is considered idempotent
461
464
  execute backoff: true do
462
465
  service.get_job_query_results @project, job_id,
@@ -464,7 +467,8 @@ module Google
464
467
  max_results: max,
465
468
  page_token: token,
466
469
  start_index: start,
467
- timeout_ms: timeout
470
+ timeout_ms: timeout,
471
+ format_options_use_int64_timestamp: format_options_use_int64_timestamp
468
472
  end
469
473
  end
470
474
 
@@ -1701,6 +1701,8 @@ module Google
1701
1701
  #
1702
1702
  # @param [Integer] max Maximum number of results to return.
1703
1703
  # @param [Integer] start Zero-based index of the starting row to read.
1704
+ # @param [Boolean] format_options_use_int64_timestamp Output timestamp
1705
+ # as usec int64. Default is true.
1704
1706
  #
1705
1707
  # @return [Google::Cloud::Bigquery::Data]
1706
1708
  #
@@ -1735,11 +1737,12 @@ module Google
1735
1737
  #
1736
1738
  # @!group Data
1737
1739
  #
1738
- def data token: nil, max: nil, start: nil
1740
+ def data token: nil, max: nil, start: nil, format_options_use_int64_timestamp: true
1739
1741
  ensure_service!
1740
1742
  reload! unless resource_full?
1741
- data_json = service.list_tabledata dataset_id, table_id, token: token, max: max, start: start
1742
- Data.from_gapi_json data_json, gapi, nil, service
1743
+ data_json = service.list_tabledata dataset_id, table_id, token: token, max: max, start: start,
1744
+ format_options_use_int64_timestamp: format_options_use_int64_timestamp
1745
+ Data.from_gapi_json data_json, gapi, nil, service, format_options_use_int64_timestamp
1743
1746
  end
1744
1747
 
1745
1748
  ##
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Bigquery
19
- VERSION = "1.53.0".freeze
19
+ VERSION = "1.54.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.53.0
4
+ version: 1.54.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Moore