[ https://issues.apache.org/jira/browse/BEAM-9770?focusedWorklogId=425171&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-425171 ]
ASF GitHub Bot logged work on BEAM-9770: ---------------------------------------- Author: ASF GitHub Bot Created on: 20/Apr/20 01:06 Start Date: 20/Apr/20 01:06 Worklog Time Spent: 10m Work Description: rezarokni commented on a change in pull request #11437: URL: https://github.com/apache/beam/pull/11437#discussion_r411034442 ########## File path: examples/java/src/main/java/org/apache/beam/examples/snippets/Snippets.java ########## @@ -753,35 +750,93 @@ public static void main(String[] args) { // [START CustomSessionWindow5] PCollection<TableRow> p = - Pipeline.create() - .apply( - "Create data", - Create.timestamped( - TimestampedValue.of( - new TableRow().set("user", "mobile").set("score", 12).set("gap", 5), - new Instant()), - TimestampedValue.of( - new TableRow().set("user", "desktop").set("score", 4), new Instant()), - TimestampedValue.of( - new TableRow().set("user", "mobile").set("score", -3).set("gap", 5), - new Instant().plus(2000)), - TimestampedValue.of( - new TableRow().set("user", "mobile").set("score", 2).set("gap", 5), - new Instant().plus(9000)), - TimestampedValue.of( - new TableRow().set("user", "mobile").set("score", 7).set("gap", 5), - new Instant().plus(12000)), - TimestampedValue.of( - new TableRow().set("user", "desktop").set("score", 10), - new Instant().plus(12000)))); + Pipeline.create() + .apply( + "Create data", + Create.timestamped( + TimestampedValue.of( + new TableRow().set("user", "mobile").set("score", 12).set("gap", 5), + new Instant()), + TimestampedValue.of( + new TableRow().set("user", "desktop").set("score", 4), new Instant()), + TimestampedValue.of( + new TableRow().set("user", "mobile").set("score", -3).set("gap", 5), + new Instant().plus(2000)), + TimestampedValue.of( + new TableRow().set("user", "mobile").set("score", 2).set("gap", 5), + new Instant().plus(9000)), + TimestampedValue.of( + new TableRow().set("user", "mobile").set("score", 7).set("gap", 5), + new Instant().plus(12000)), + TimestampedValue.of( + new TableRow().set("user", "desktop").set("score", 10), + new Instant().plus(12000)))); // [END CustomSessionWindow5] // [START CustomSessionWindow6] p.apply( - "Window into sessions", - Window.<TableRow>into( - DynamicSessions.withDefaultGapDuration(Duration.standardSeconds(10)))); + "Window into sessions", + Window.<TableRow>into( + DynamicSessions.withDefaultGapDuration(Duration.standardSeconds(10)))); // [END CustomSessionWindow6] + } + + public static class DeadLetterBigQuery { + public static void deadletter(String[] args) { + // [START BigQueryIODeadLetter] + // Create pipeline + PipelineOptions options = + PipelineOptionsFactory.fromArgs(args).withValidation().as(BigQueryOptions.class); + + Pipeline p = Pipeline.create(options); + + // Create a bug by writing the 2nd value as null. The API will correctly + // throw an error when trying to insert a null value into a REQUIRED field. + WriteResult result = + p.apply(Create.of(1, 2)) + .apply( + BigQueryIO.<Integer>write() + .withSchema( + new TableSchema() + .setFields( + com.google.common.collect.ImmutableList.of( + new TableFieldSchema() + .setName("num") + .setType("INTEGER") + .setMode("REQUIRED")))) + .to("Test.dummyTable") + .withFormatFunction(x -> new TableRow().set("num", (x == 2) ? null : x)) + .withFailedInsertRetryPolicy(InsertRetryPolicy.neverRetry()) Review comment: Fixed. ########## File path: website/src/documentation/patterns/bigqueryio.md ########## @@ -0,0 +1,37 @@ +--- +layout: section +title: "BigQuery patterns" +section_menu: section-menu/documentation.html +permalink: /documentation/patterns/bigqueryio/ +--- +<!-- +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +--> + +# Google BigQuery patterns + +The samples on this page show you common patterns for use with BigQueryIO. + +## BigQueryIO deadletter pattern +In production systems, it is useful to implement the deadletter pattern with BigQueryIO outputting any elements which had errors during processing by BigQueryIO into another PCollection for further processing. + +When using `STREAMING_INSERTS` you can use the `WriteResult` object to access a `PCollection` with the `TableRows` that failed to be inserted into BigQuery. Review comment: Fixed. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 425171) Time Spent: 0.5h (was: 20m) > Add BigQuery DeadLetter pattern to Patterns Page > ------------------------------------------------ > > Key: BEAM-9770 > URL: https://issues.apache.org/jira/browse/BEAM-9770 > Project: Beam > Issue Type: New Feature > Components: website > Reporter: Reza ardeshir rokni > Assignee: Reza ardeshir rokni > Priority: Trivial > Time Spent: 0.5h > Remaining Estimate: 0h > -- This message was sent by Atlassian Jira (v8.3.4#803005)