/** * Similar to {@link #withSchema(TableSchema)} but takes in a JSON-serialized {@link * TableSchema}. */ public Write<T> withJsonSchema(String jsonSchema) { checkArgument(jsonSchema != null, "jsonSchema can not be null"); return withJsonSchema(StaticValueProvider.of(jsonSchema)); }
/** * Uses the specified schema for rows to be written. * * <p>The schema is <i>required</i> only if writing to a table that does not already exist, and * {@link CreateDisposition} is set to {@link CreateDisposition#CREATE_IF_NEEDED}. */ public Write<T> withSchema(TableSchema schema) { checkArgument(schema != null, "schema can not be null"); return withJsonSchema(StaticValueProvider.of(BigQueryHelpers.toJsonString(schema))); }
/** Same as {@link #withSchema(TableSchema)} but using a deferred {@link ValueProvider}. */ public Write<T> withSchema(ValueProvider<TableSchema> schema) { checkArgument(schema != null, "schema can not be null"); return withJsonSchema(NestedValueProvider.of(schema, new TableSchemaToJsonSchema())); }
BigQueryIO.<Quote>write() .to(tableSpec) .withJsonSchema(tableSchemaJson) .withFormatFunction( (Quote elem) ->
"InsertIntoBigQuery", BigQueryIO.writeTableRows() .withJsonSchema(getSchemaFromGCS(options.getJSONPath())) .to(options.getOutputTable()) .withExtendedErrorInfo()
@Override public WriteResult expand( PCollection<FailsafeElement<KV<String, String>, String>> failedRecords) { return failedRecords .apply("FailedRecordToTableRow", ParDo.of(new FailedMessageToTableRowFn())) .apply( "WriteFailedRecordsToBigQuery", BigQueryIO.writeTableRows() .to(getErrorRecordsTable()) .withJsonSchema(getErrorRecordsTableSchema()) .withCreateDisposition(CreateDisposition.CREATE_IF_NEEDED) .withWriteDisposition(WriteDisposition.WRITE_APPEND)); } }
@Override public WriteResult expand(PCollection<FailsafeElement<PubsubMessage, String>> failedRecords) { return failedRecords .apply("FailedRecordToTableRow", ParDo.of(new FailedPubsubMessageToTableRowFn())) .apply( "WriteFailedRecordsToBigQuery", BigQueryIO.writeTableRows() .to(getErrorRecordsTable()) .withJsonSchema(getErrorRecordsTableSchema()) .withCreateDisposition(CreateDisposition.CREATE_IF_NEEDED) .withWriteDisposition(WriteDisposition.WRITE_APPEND)); }
@Override public WriteResult expand(PCollection<FailsafeElement<String, String>> failedRecords) { return failedRecords .apply("FailedRecordToTableRow", ParDo.of(new FailedStringToTableRowFn())) .apply( "WriteFailedRecordsToBigQuery", BigQueryIO.writeTableRows() .to(getErrorRecordsTable()) .withJsonSchema(getErrorRecordsTableSchema()) .withCreateDisposition(CreateDisposition.CREATE_IF_NEEDED) .withWriteDisposition(WriteDisposition.WRITE_APPEND)); }