Class: Fluent::Plugin::BigQueryBaseOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::Plugin::BigQueryBaseOutput
- Defined in:
- lib/fluent/plugin/out_bigquery_base.rb
Overview
This class is abstract class
Direct Known Subclasses
Instance Method Summary collapse
-
#clustering_fields ⇒ Object
Clustering.
- #configure(conf) ⇒ Object
- #fetch_schema(metadata) ⇒ Object
- #fetch_schema_target_table(metadata) ⇒ Object
-
#format(tag, time, record) ⇒ Object
Formatter.
- #get_schema(project, dataset, metadata) ⇒ Object
- #multi_workers_ready? ⇒ Boolean
-
#request_timeout_sec ⇒ Object
Timeout request_timeout_sec Bigquery API response timeout request_open_timeout_sec Bigquery API connection, and request timeout.
- #start ⇒ Object
-
#time_partitioning_type ⇒ Object
Partitioning.
- #write(chunk) ⇒ Object
- #writer ⇒ Object
Instance Method Details
#clustering_fields ⇒ Object
Clustering
77 |
# File 'lib/fluent/plugin/out_bigquery_base.rb', line 77 config_param :clustering_fields, :array, default: nil |
#configure(conf) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/fluent/plugin/out_bigquery_base.rb', line 84 def configure(conf) super case @auth_method when :private_key unless @email && @private_key_path raise Fluent::ConfigError, "'email' and 'private_key_path' must be specified if auth_method == 'private_key'" end when :compute_engine # Do nothing when :json_key unless @json_key raise Fluent::ConfigError, "'json_key' must be specified if auth_method == 'json_key'" end when :application_default # Do nothing else raise Fluent::ConfigError, "unrecognized 'auth_method': #{@auth_method}" end unless @table.nil? ^ @tables.nil? raise Fluent::ConfigError, "'table' or 'tables' must be specified, and both are invalid" end @tablelist = @tables ? @tables : [@table] @table_schema = Fluent::BigQuery::RecordSchema.new('record') if @schema @table_schema.load_schema(@schema) end if @schema_path @table_schema.load_schema(MultiJson.load(File.read(@schema_path))) end formatter_config = conf.elements("format")[0] @formatter = formatter_create(usage: 'out_bigquery_for_insert', default_type: 'json', conf: formatter_config) end |
#fetch_schema(metadata) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/fluent/plugin/out_bigquery_base.rb', line 181 def fetch_schema() table_id = nil project = extract_placeholders(@project, ) dataset = extract_placeholders(@dataset, ) table_id = fetch_schema_target_table() if Fluent::Engine.now - @last_fetch_schema_time["#{project}.#{dataset}.#{table_id}"] > @schema_cache_expire schema = writer.fetch_schema(project, dataset, table_id) if schema table_schema = Fluent::BigQuery::RecordSchema.new("record") table_schema.load_schema(schema) @fetched_schemas["#{project}.#{dataset}.#{table_id}"] = table_schema else if @fetched_schemas["#{project}.#{dataset}.#{table_id}"].nil? raise "failed to fetch schema from bigquery" else log.warn "#{table_id} uses previous schema" end end @last_fetch_schema_time["#{project}.#{dataset}.#{table_id}"] = Fluent::Engine.now end @fetched_schemas["#{project}.#{dataset}.#{table_id}"] end |
#fetch_schema_target_table(metadata) ⇒ Object
208 209 210 |
# File 'lib/fluent/plugin/out_bigquery_base.rb', line 208 def fetch_schema_target_table() extract_placeholders(@fetch_schema_table || @tablelist[0], ) end |
#format(tag, time, record) ⇒ Object
Formatter
80 81 82 |
# File 'lib/fluent/plugin/out_bigquery_base.rb', line 80 config_section :format do config_set_default :@type, 'json' end |
#get_schema(project, dataset, metadata) ⇒ Object
212 213 214 215 216 217 218 |
# File 'lib/fluent/plugin/out_bigquery_base.rb', line 212 def get_schema(project, dataset, ) if @fetch_schema @fetched_schemas["#{project}.#{dataset}.#{fetch_schema_target_table()}"] || fetch_schema() else @table_schema end end |
#multi_workers_ready? ⇒ Boolean
131 132 133 |
# File 'lib/fluent/plugin/out_bigquery_base.rb', line 131 def multi_workers_ready? true end |
#request_timeout_sec ⇒ Object
Timeout request_timeout_sec
Bigquery API response timeout
request_open_timeout_sec
Bigquery API connection, and request timeout
68 |
# File 'lib/fluent/plugin/out_bigquery_base.rb', line 68 config_param :request_timeout_sec, :time, default: nil |
#start ⇒ Object
122 123 124 125 126 127 128 129 |
# File 'lib/fluent/plugin/out_bigquery_base.rb', line 122 def start super @tables_queue = @tablelist.shuffle @tables_mutex = Mutex.new @fetched_schemas = {} @last_fetch_schema_time = Hash.new(0) end |
#time_partitioning_type ⇒ Object
Partitioning
72 |
# File 'lib/fluent/plugin/out_bigquery_base.rb', line 72 config_param :time_partitioning_type, :enum, list: [:day], default: nil |
#write(chunk) ⇒ Object
178 179 |
# File 'lib/fluent/plugin/out_bigquery_base.rb', line 178 def write(chunk) end |
#writer ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/fluent/plugin/out_bigquery_base.rb', line 135 def writer @writer ||= Fluent::BigQuery::Writer.new(@log, @auth_method, { private_key_path: @private_key_path, private_key_passphrase: @private_key_passphrase, email: @email, json_key: @json_key, location: @location, source_format: @source_format, skip_invalid_rows: @skip_invalid_rows, ignore_unknown_values: @ignore_unknown_values, max_bad_records: @max_bad_records, allow_retry_insert_errors: @allow_retry_insert_errors, prevent_duplicate_load: @prevent_duplicate_load, auto_create_table: @auto_create_table, time_partitioning_type: @time_partitioning_type, time_partitioning_field: @time_partitioning_field, time_partitioning_expiration: @time_partitioning_expiration, clustering_fields: @clustering_fields, timeout_sec: @request_timeout_sec, open_timeout_sec: @request_open_timeout_sec, }) end |