You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "tarun-google (via GitHub)" <gi...@apache.org> on 2025/07/15 18:08:49 UTC
[PR] Add Iceberg Rest Catalog Example [beam]
tarun-google opened a new pull request, #35599:
URL: https://github.com/apache/beam/pull/35599
**Please** add a meaningful description for your change here
------------------------
Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:
- [ ] Mention the appropriate issue in your description (for example: `addresses #123`), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment `fixes #<ISSUE NUMBER>` instead.
- [ ] Update `CHANGES.md` with noteworthy changes.
- [ ] If this contribution is large, please file an Apache [Individual Contributor License Agreement](https://www.apache.org/licenses/icla.pdf).
See the [Contributor Guide](https://beam.apache.org/contribute) for more tips on [how to make review process smoother](https://github.com/apache/beam/blob/master/CONTRIBUTING.md#make-the-reviewers-job-easier).
To check the build health, please visit [https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md](https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md)
GitHub Actions Tests Status (on master branch)
------------------------------------------------------------------------------------------------
[](https://github.com/apache/beam/actions?query=workflow%3A%22Build+python+source+distribution+and+wheels%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Python+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Java+Tests%22+branch%3Amaster+event%3Aschedule)
[](https://github.com/apache/beam/actions?query=workflow%3A%22Go+tests%22+branch%3Amaster+event%3Aschedule)
See [CI.md](https://github.com/apache/beam/blob/master/CI.md) for more information about GitHub Actions CI or the [workflows README](https://github.com/apache/beam/blob/master/.github/workflows/README.md) to see a list of phrases to trigger workflows.
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Iceberg Rest Catalog Example [beam]
Posted by "tarun-google (via GitHub)" <gi...@apache.org>.
tarun-google commented on code in PR #35599:
URL: https://github.com/apache/beam/pull/35599#discussion_r2214087415
##########
examples/java/src/main/java/org/apache/beam/examples/cookbook/IcebergRestCatalogStreamingWriteExample.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.beam.examples.cookbook;
+
+import com.google.auth.oauth2.GoogleCredentials;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.coders.RowCoder;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubIO;
+import org.apache.beam.sdk.managed.Managed;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.Filter;
+import org.apache.beam.sdk.transforms.JsonToRow;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.Sum;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+import org.joda.time.DateTime;
+import org.joda.time.Duration;
+
+/**
+ * Reads real-time NYC taxi ride information from {@code
+ * projects/pubsub-public-data/topics/taxirides-realtime} and writes aggregated passenger count data
+ * to an Iceberg table using Beam's {@link Managed} IcebergIO sink.
+ *
+ * <p>This is a streaming pipeline that processes taxi ride events, filters for 'dropoff' status,
+ * aggregates passenger counts within fixed 10-second windows by minute of the ride, and writes the
+ * results to a single Iceberg table. The Iceberg sink triggers writes every 30 seconds, creating
+ * new snapshots.
+ */
+public class IcebergRestCatalogStreamingWriteExample {
+
+ public static final Schema TAXIRIDES_SCHEMA =
+ Schema.builder()
+ .addInt64Field("passenger_count")
+ .addStringField("ride_status")
+ .addDateTimeField("timestamp")
+ .build();
+
+ public static final Schema AGGREGATED_SCHEMA =
+ Schema.builder().addStringField("ride_minute").addInt64Field("passenger_count").build();
+
+ /**
+ * Main entry point for the pipeline.
+ *
+ * @param args Command line arguments
+ * @throws IOException if there's an issue with GoogleCredentials
+ */
+ public static void main(String[] args) throws IOException {
+ IcebergPipelineOptions options =
+ PipelineOptionsFactory.fromArgs(args).withValidation().as(IcebergPipelineOptions.class);
+ options.setProject("apache-beam-testing");
+
+ final String tableIdentifier = "taxi_dataset.passenger_count_by_minute";
+ final String pubsubTopic = options.getTopic();
+ final String catalogUri = options.getCatalogUri();
+ final String warehouseLocation = options.getWarehouse();
+ final String projectName = options.getProject();
+ final String catalogName = options.getCatalogName();
+ final int triggeringFrequencySeconds = 30;
+
+ Map<String, String> catalogProps =
+ ImmutableMap.<String, String>builder()
+ .put("type", "rest")
Review Comment:
Added documentation on the top
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Iceberg Rest Catalog Example [beam]
Posted by "ahmedabu98 (via GitHub)" <gi...@apache.org>.
ahmedabu98 commented on code in PR #35599:
URL: https://github.com/apache/beam/pull/35599#discussion_r2216555396
##########
examples/java/src/main/java/org/apache/beam/examples/cookbook/IcebergRestCatalogStreamingWriteExample.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.beam.examples.cookbook;
+
+import com.google.auth.oauth2.GoogleCredentials;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.coders.RowCoder;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubIO;
+import org.apache.beam.sdk.managed.Managed;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.Filter;
+import org.apache.beam.sdk.transforms.JsonToRow;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.Sum;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+import org.joda.time.DateTime;
+import org.joda.time.Duration;
+
+/**
+ * Reads real-time NYC taxi ride information from {@code
+ * projects/pubsub-public-data/topics/taxirides-realtime} and writes aggregated passenger count data
+ * to an Iceberg table using Beam's {@link Managed} IcebergIO sink.
+ *
+ * <p>This is a streaming pipeline that processes taxi ride events, filters for 'dropoff' status,
+ * aggregates passenger counts within fixed 10-second windows by minute of the ride, and writes the
+ * results to a single Iceberg table. The Iceberg sink triggers writes every 30 seconds, creating
+ * new snapshots.
+ *
+ * <p>This example is a demonstration of the Iceberg REST Catalog. For more information, see the
+ * documentation at {@link https://cloud.google.com/bigquery/docs/blms-rest-catalog}.
+ */
+public class IcebergRestCatalogStreamingWriteExample {
+
+ public static final Schema TAXIRIDES_SCHEMA =
+ Schema.builder()
+ .addInt64Field("passenger_count")
+ .addStringField("ride_status")
+ .addDateTimeField("timestamp")
+ .build();
+
+ public static final Schema AGGREGATED_SCHEMA =
+ Schema.builder().addStringField("ride_minute").addInt64Field("passenger_count").build();
+
+ /**
+ * Main entry point for the pipeline.
+ *
+ * @param args Command line arguments
+ * @throws IOException if there's an issue with GoogleCredentials
+ */
+ public static void main(String[] args) throws IOException {
+ IcebergPipelineOptions options =
+ PipelineOptionsFactory.fromArgs(args).withValidation().as(IcebergPipelineOptions.class);
+ options.setProject("apache-beam-testing");
+
+ final String tableIdentifier = "taxi_dataset.passenger_count_by_minute";
+ final String pubsubTopic = options.getTopic();
+ final String catalogUri = options.getCatalogUri();
+ final String warehouseLocation = options.getWarehouse();
+ final String projectName = options.getProject();
+ final String catalogName = options.getCatalogName();
+ final int triggeringFrequencySeconds = 30;
+
+ // Note: The token expires in 1 hour, and users may need to re-run the pipeline.
+ // Upcoming changes in Iceberg and the BigLake Metastore with the Iceberg REST Catalog
+ // will support token refreshing and credential vending.
+ Map<String, String> catalogProps =
+ ImmutableMap.<String, String>builder()
+ .put("type", "rest")
+ .put("uri", catalogUri)
+ .put("warehouse", warehouseLocation)
+ .put("header.x-goog-user-project", projectName)
+ .put("oauth2-server-uri", "https://oauth2.googleapis.com/token")
+ .put(
+ "token",
+ GoogleCredentials.getApplicationDefault().refreshAccessToken().getTokenValue())
+ .put("rest-metrics-reporting-enabled", "false")
+ .build();
+
+ Map<String, Object> icebergWriteConfig =
+ ImmutableMap.<String, Object>builder()
+ .put("table", tableIdentifier)
+ .put("catalog_properties", catalogProps)
+ .put("catalog_name", catalogName)
+ .put("triggering_frequency_seconds", triggeringFrequencySeconds)
+ .build();
+
+ Pipeline p = Pipeline.create(options);
+
+ PCollection<Row> aggregatedRows =
+ p.apply("ReadFromPubSub", PubsubIO.readStrings().fromTopic(pubsubTopic))
+ .apply("ConvertJsonToRow", JsonToRow.withSchema(TAXIRIDES_SCHEMA))
+ .apply(
+ "FilterNullFields",
+ Filter.by(
+ (Row row) ->
+ row.getInt64("passenger_count") != null
+ && row.getDateTime("timestamp") != null))
+ .apply(
+ "FilterDropoffRides",
+ Filter.by((Row row) -> "dropoff".equals(row.getString("ride_status"))))
+ .apply(
+ "ApplyFixedWindow", Window.<Row>into(FixedWindows.of(Duration.standardSeconds(10))))
+ .apply(
+ "ExtractMinuteAndPassengerCount",
+ MapElements.into(
+ TypeDescriptors.kvs(TypeDescriptors.strings(), TypeDescriptors.longs()))
+ .via(
+ (Row row) -> {
+ Long passengerCount = row.getInt64("passenger_count");
+ DateTime timestamp = (DateTime) row.getDateTime("timestamp");
+ if (timestamp == null) {
+ throw new IllegalStateException(
+ "Timestamp should not be null at this stage.");
+ }
Review Comment:
I think we don't need this null check.
If it's giving you a null warning, just wrap `row.getDateTime()` in a `Preconditions.checkStateNotNull()`
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Iceberg Rest Catalog Example [beam]
Posted by "tarun-google (via GitHub)" <gi...@apache.org>.
tarun-google commented on code in PR #35599:
URL: https://github.com/apache/beam/pull/35599#discussion_r2214032661
##########
examples/java/src/main/java/org/apache/beam/examples/cookbook/IcebergRestCatalogStreamingWriteExample.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.beam.examples.cookbook;
+
+import com.google.auth.oauth2.GoogleCredentials;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.coders.RowCoder;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubIO;
+import org.apache.beam.sdk.managed.Managed;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.Filter;
+import org.apache.beam.sdk.transforms.JsonToRow;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.Sum;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+import org.joda.time.DateTime;
+import org.joda.time.Duration;
+
+/**
+ * Reads real-time NYC taxi ride information from {@code
+ * projects/pubsub-public-data/topics/taxirides-realtime} and writes aggregated passenger count data
+ * to an Iceberg table using Beam's {@link Managed} IcebergIO sink.
+ *
+ * <p>This is a streaming pipeline that processes taxi ride events, filters for 'dropoff' status,
+ * aggregates passenger counts within fixed 10-second windows by minute of the ride, and writes the
+ * results to a single Iceberg table. The Iceberg sink triggers writes every 30 seconds, creating
+ * new snapshots.
+ */
+public class IcebergRestCatalogStreamingWriteExample {
+
+ public static final Schema TAXIRIDES_SCHEMA =
+ Schema.builder()
+ .addInt64Field("passenger_count")
+ .addStringField("ride_status")
+ .addDateTimeField("timestamp")
+ .build();
+
+ public static final Schema AGGREGATED_SCHEMA =
+ Schema.builder().addStringField("ride_minute").addInt64Field("passenger_count").build();
+
+ /**
+ * Main entry point for the pipeline.
+ *
+ * @param args Command line arguments
+ * @throws IOException if there's an issue with GoogleCredentials
+ */
+ public static void main(String[] args) throws IOException {
+ IcebergPipelineOptions options =
+ PipelineOptionsFactory.fromArgs(args).withValidation().as(IcebergPipelineOptions.class);
+ options.setProject("apache-beam-testing");
+
+ final String tableIdentifier = "taxi_dataset.passenger_count_by_minute";
+ final String pubsubTopic = options.getTopic();
+ final String catalogUri = options.getCatalogUri();
+ final String warehouseLocation = options.getWarehouse();
+ final String projectName = options.getProject();
+ final String catalogName = options.getCatalogName();
+ final int triggeringFrequencySeconds = 30;
+
+ Map<String, String> catalogProps =
+ ImmutableMap.<String, String>builder()
+ .put("type", "rest")
+ .put("uri", catalogUri)
+ .put("warehouse", warehouseLocation)
+ .put("header.x-goog-user-project", projectName)
+ .put("oauth2-server-uri", "https://oauth2.googleapis.com/token")
Review Comment:
@nika-qubit "oauth2-server-uri" property is needed as per the warning.
"WARNING: Iceberg REST client is missing the OAuth2 server URI configuration and defaults to https://biglake.googleapis.com/iceberg/v1beta/restcatalogv1/oauth/tokens. This automatic fallback will be removed in a future Iceberg release.It is recommended to configure the OAuth2 endpoint using the 'oauth2-server-uri' property to be prepared. This warning will disappear if the OAuth2 endpoint is explicitly configured. See https://github.com/apache/iceberg/issues/10537"
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Iceberg Rest Catalog Example [beam]
Posted by "liferoad (via GitHub)" <gi...@apache.org>.
liferoad commented on code in PR #35599:
URL: https://github.com/apache/beam/pull/35599#discussion_r2213874345
##########
examples/java/src/main/java/org/apache/beam/examples/cookbook/IcebergRestCatalogStreamingWriteExample.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.beam.examples.cookbook;
+
+import com.google.auth.oauth2.GoogleCredentials;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.coders.RowCoder;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubIO;
+import org.apache.beam.sdk.managed.Managed;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.Filter;
+import org.apache.beam.sdk.transforms.JsonToRow;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.Sum;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+import org.joda.time.DateTime;
+import org.joda.time.Duration;
+
+/**
+ * Reads real-time NYC taxi ride information from {@code
+ * projects/pubsub-public-data/topics/taxirides-realtime} and writes aggregated passenger count data
+ * to an Iceberg table using Beam's {@link Managed} IcebergIO sink.
+ *
+ * <p>This is a streaming pipeline that processes taxi ride events, filters for 'dropoff' status,
+ * aggregates passenger counts within fixed 10-second windows by minute of the ride, and writes the
+ * results to a single Iceberg table. The Iceberg sink triggers writes every 30 seconds, creating
+ * new snapshots.
+ */
+public class IcebergRestCatalogStreamingWriteExample {
Review Comment:
we should add this here later: https://cloud.google.com/dataflow/docs/guides/write-to-iceberg
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Iceberg Rest Catalog Example [beam]
Posted by "nika-qubit (via GitHub)" <gi...@apache.org>.
nika-qubit commented on code in PR #35599:
URL: https://github.com/apache/beam/pull/35599#discussion_r2214013355
##########
examples/java/src/main/java/org/apache/beam/examples/cookbook/IcebergRestCatalogStreamingWriteExample.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.beam.examples.cookbook;
+
+import com.google.auth.oauth2.GoogleCredentials;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.coders.RowCoder;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubIO;
+import org.apache.beam.sdk.managed.Managed;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.Filter;
+import org.apache.beam.sdk.transforms.JsonToRow;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.Sum;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+import org.joda.time.DateTime;
+import org.joda.time.Duration;
+
+/**
+ * Reads real-time NYC taxi ride information from {@code
+ * projects/pubsub-public-data/topics/taxirides-realtime} and writes aggregated passenger count data
+ * to an Iceberg table using Beam's {@link Managed} IcebergIO sink.
+ *
+ * <p>This is a streaming pipeline that processes taxi ride events, filters for 'dropoff' status,
+ * aggregates passenger counts within fixed 10-second windows by minute of the ride, and writes the
+ * results to a single Iceberg table. The Iceberg sink triggers writes every 30 seconds, creating
+ * new snapshots.
+ */
+public class IcebergRestCatalogStreamingWriteExample {
+
+ public static final Schema TAXIRIDES_SCHEMA =
+ Schema.builder()
+ .addInt64Field("passenger_count")
+ .addStringField("ride_status")
+ .addDateTimeField("timestamp")
+ .build();
+
+ public static final Schema AGGREGATED_SCHEMA =
+ Schema.builder().addStringField("ride_minute").addInt64Field("passenger_count").build();
+
+ /**
+ * Main entry point for the pipeline.
+ *
+ * @param args Command line arguments
+ * @throws IOException if there's an issue with GoogleCredentials
+ */
+ public static void main(String[] args) throws IOException {
+ IcebergPipelineOptions options =
+ PipelineOptionsFactory.fromArgs(args).withValidation().as(IcebergPipelineOptions.class);
+ options.setProject("apache-beam-testing");
+
+ final String tableIdentifier = "taxi_dataset.passenger_count_by_minute";
+ final String pubsubTopic = options.getTopic();
+ final String catalogUri = options.getCatalogUri();
+ final String warehouseLocation = options.getWarehouse();
+ final String projectName = options.getProject();
+ final String catalogName = options.getCatalogName();
+ final int triggeringFrequencySeconds = 30;
+
+ Map<String, String> catalogProps =
+ ImmutableMap.<String, String>builder()
+ .put("type", "rest")
+ .put("uri", catalogUri)
+ .put("warehouse", warehouseLocation)
+ .put("header.x-goog-user-project", projectName)
+ .put("oauth2-server-uri", "https://oauth2.googleapis.com/token")
Review Comment:
You can remove this property since it's never used.
##########
examples/java/src/main/java/org/apache/beam/examples/cookbook/IcebergRestCatalogStreamingWriteExample.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.beam.examples.cookbook;
+
+import com.google.auth.oauth2.GoogleCredentials;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.coders.RowCoder;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubIO;
+import org.apache.beam.sdk.managed.Managed;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.Filter;
+import org.apache.beam.sdk.transforms.JsonToRow;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.Sum;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+import org.joda.time.DateTime;
+import org.joda.time.Duration;
+
+/**
+ * Reads real-time NYC taxi ride information from {@code
+ * projects/pubsub-public-data/topics/taxirides-realtime} and writes aggregated passenger count data
+ * to an Iceberg table using Beam's {@link Managed} IcebergIO sink.
+ *
+ * <p>This is a streaming pipeline that processes taxi ride events, filters for 'dropoff' status,
+ * aggregates passenger counts within fixed 10-second windows by minute of the ride, and writes the
+ * results to a single Iceberg table. The Iceberg sink triggers writes every 30 seconds, creating
+ * new snapshots.
+ */
+public class IcebergRestCatalogStreamingWriteExample {
+
+ public static final Schema TAXIRIDES_SCHEMA =
+ Schema.builder()
+ .addInt64Field("passenger_count")
+ .addStringField("ride_status")
+ .addDateTimeField("timestamp")
+ .build();
+
+ public static final Schema AGGREGATED_SCHEMA =
+ Schema.builder().addStringField("ride_minute").addInt64Field("passenger_count").build();
+
+ /**
+ * Main entry point for the pipeline.
+ *
+ * @param args Command line arguments
+ * @throws IOException if there's an issue with GoogleCredentials
+ */
+ public static void main(String[] args) throws IOException {
+ IcebergPipelineOptions options =
+ PipelineOptionsFactory.fromArgs(args).withValidation().as(IcebergPipelineOptions.class);
+ options.setProject("apache-beam-testing");
+
+ final String tableIdentifier = "taxi_dataset.passenger_count_by_minute";
+ final String pubsubTopic = options.getTopic();
+ final String catalogUri = options.getCatalogUri();
+ final String warehouseLocation = options.getWarehouse();
+ final String projectName = options.getProject();
+ final String catalogName = options.getCatalogName();
+ final int triggeringFrequencySeconds = 30;
+
+ Map<String, String> catalogProps =
+ ImmutableMap.<String, String>builder()
+ .put("type", "rest")
+ .put("uri", catalogUri)
+ .put("warehouse", warehouseLocation)
+ .put("header.x-goog-user-project", projectName)
+ .put("oauth2-server-uri", "https://oauth2.googleapis.com/token")
+ .put(
+ "token",
Review Comment:
Please notify the reader that this will expire in 1 hour. And there are upcoming changes in Iceberg and the BigLake Metastore with the Iceberg REST Catalog to support refreshed tokens and credential vending.
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Iceberg Rest Catalog Example [beam]
Posted by "ahmedabu98 (via GitHub)" <gi...@apache.org>.
ahmedabu98 commented on code in PR #35599:
URL: https://github.com/apache/beam/pull/35599#discussion_r2216927538
##########
examples/java/src/main/java/org/apache/beam/examples/cookbook/IcebergRestCatalogStreamingWriteExample.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.beam.examples.cookbook;
+
+import com.google.auth.oauth2.GoogleCredentials;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.coders.RowCoder;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubIO;
+import org.apache.beam.sdk.managed.Managed;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.Filter;
+import org.apache.beam.sdk.transforms.JsonToRow;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.Sum;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.util.Preconditions;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+import org.joda.time.DateTime;
+import org.joda.time.Duration;
+
+/**
+ * Reads real-time NYC taxi ride information from {@code
+ * projects/pubsub-public-data/topics/taxirides-realtime} and writes aggregated passenger count data
+ * to an Iceberg table using Beam's {@link Managed} IcebergIO sink.
+ *
+ * <p>This is a streaming pipeline that processes taxi ride events, filters for 'dropoff' status,
+ * aggregates passenger counts within fixed 10-second windows by minute of the ride, and writes the
+ * results to a single Iceberg table. The Iceberg sink triggers writes every 30 seconds, creating
+ * new snapshots.
+ *
+ * <p>This example is a demonstration of the Iceberg REST Catalog. For more information, see the
+ * documentation at {@link https://cloud.google.com/bigquery/docs/blms-rest-catalog}.
+ */
+public class IcebergRestCatalogStreamingWriteExample {
+
+ public static final Schema TAXIRIDES_SCHEMA =
+ Schema.builder()
+ .addInt64Field("passenger_count")
+ .addStringField("ride_status")
+ .addDateTimeField("timestamp")
+ .build();
+
+ public static final Schema AGGREGATED_SCHEMA =
+ Schema.builder().addStringField("ride_minute").addInt64Field("passenger_count").build();
+
+ /**
+ * Main entry point for the pipeline.
+ *
+ * @param args Command line arguments
+ * @throws IOException if there's an issue with GoogleCredentials
+ */
+ public static void main(String[] args) throws IOException {
+ IcebergPipelineOptions options =
+ PipelineOptionsFactory.fromArgs(args).withValidation().as(IcebergPipelineOptions.class);
+ options.setProject("apache-beam-testing");
+
+ final String tableIdentifier = "taxi_dataset.passenger_count_by_minute";
+ final String pubsubTopic = options.getTopic();
+ final String catalogUri = options.getCatalogUri();
+ final String warehouseLocation = options.getWarehouse();
+ final String projectName = options.getProject();
+ final String catalogName = options.getCatalogName();
+ final int triggeringFrequencySeconds = 30;
+
+ // Note: The token expires in 1 hour, and users may need to re-run the pipeline.
+ // Upcoming changes in Iceberg and the BigLake Metastore with the Iceberg REST Catalog
+ // will support token refreshing and credential vending.
+ Map<String, String> catalogProps =
+ ImmutableMap.<String, String>builder()
+ .put("type", "rest")
+ .put("uri", catalogUri)
+ .put("warehouse", warehouseLocation)
+ .put("header.x-goog-user-project", projectName)
+ .put("oauth2-server-uri", "https://oauth2.googleapis.com/token")
+ .put(
+ "token",
+ GoogleCredentials.getApplicationDefault().refreshAccessToken().getTokenValue())
+ .put("rest-metrics-reporting-enabled", "false")
+ .build();
+
+ Map<String, Object> icebergWriteConfig =
+ ImmutableMap.<String, Object>builder()
+ .put("table", tableIdentifier)
+ .put("catalog_properties", catalogProps)
+ .put("catalog_name", catalogName)
+ .put("triggering_frequency_seconds", triggeringFrequencySeconds)
+ .build();
+
+ Pipeline p = Pipeline.create(options);
+
+ PCollection<Row> aggregatedRows =
+ p.apply("ReadFromPubSub", PubsubIO.readStrings().fromTopic(pubsubTopic))
+ .apply("ConvertJsonToRow", JsonToRow.withSchema(TAXIRIDES_SCHEMA))
+ .apply(
+ "FilterNullFields",
+ Filter.by(
+ (Row row) ->
+ row.getInt64("passenger_count") != null
+ && row.getDateTime("timestamp") != null))
+ .apply(
+ "FilterDropoffRides",
+ Filter.by((Row row) -> "dropoff".equals(row.getString("ride_status"))))
+ .apply(
+ "ApplyFixedWindow", Window.<Row>into(FixedWindows.of(Duration.standardSeconds(10))))
+ .apply(
+ "ExtractMinuteAndPassengerCount",
+ MapElements.into(
+ TypeDescriptors.kvs(TypeDescriptors.strings(), TypeDescriptors.longs()))
+ .via(
+ (Row row) -> {
+ Long passengerCount = row.getInt64("passenger_count");
+ DateTime timestamp =
+ (DateTime)
+ Preconditions.checkStateNotNull(row.getDateTime("timestamp"));
+ String minute = timestamp.toString("yyyy-MM-dd HH:mm");
+ return KV.of(minute, passengerCount);
+ }))
Review Comment:
nit: can we shorten this logic?
i.e. `row -> KV.of(checkStateNotNull(row.getDateTime("timestamp")).toString("..."), row.getInt64())`
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Iceberg Rest Catalog Example [beam]
Posted by "ahmedabu98 (via GitHub)" <gi...@apache.org>.
ahmedabu98 commented on code in PR #35599:
URL: https://github.com/apache/beam/pull/35599#discussion_r2216927538
##########
examples/java/src/main/java/org/apache/beam/examples/cookbook/IcebergRestCatalogStreamingWriteExample.java:
##########
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.beam.examples.cookbook;
+
+import com.google.auth.oauth2.GoogleCredentials;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.coders.RowCoder;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubIO;
+import org.apache.beam.sdk.managed.Managed;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.Filter;
+import org.apache.beam.sdk.transforms.JsonToRow;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.Sum;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.util.Preconditions;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+import org.joda.time.DateTime;
+import org.joda.time.Duration;
+
+/**
+ * Reads real-time NYC taxi ride information from {@code
+ * projects/pubsub-public-data/topics/taxirides-realtime} and writes aggregated passenger count data
+ * to an Iceberg table using Beam's {@link Managed} IcebergIO sink.
+ *
+ * <p>This is a streaming pipeline that processes taxi ride events, filters for 'dropoff' status,
+ * aggregates passenger counts within fixed 10-second windows by minute of the ride, and writes the
+ * results to a single Iceberg table. The Iceberg sink triggers writes every 30 seconds, creating
+ * new snapshots.
+ *
+ * <p>This example is a demonstration of the Iceberg REST Catalog. For more information, see the
+ * documentation at {@link https://cloud.google.com/bigquery/docs/blms-rest-catalog}.
+ */
+public class IcebergRestCatalogStreamingWriteExample {
+
+ public static final Schema TAXIRIDES_SCHEMA =
+ Schema.builder()
+ .addInt64Field("passenger_count")
+ .addStringField("ride_status")
+ .addDateTimeField("timestamp")
+ .build();
+
+ public static final Schema AGGREGATED_SCHEMA =
+ Schema.builder().addStringField("ride_minute").addInt64Field("passenger_count").build();
+
+ /**
+ * Main entry point for the pipeline.
+ *
+ * @param args Command line arguments
+ * @throws IOException if there's an issue with GoogleCredentials
+ */
+ public static void main(String[] args) throws IOException {
+ IcebergPipelineOptions options =
+ PipelineOptionsFactory.fromArgs(args).withValidation().as(IcebergPipelineOptions.class);
+ options.setProject("apache-beam-testing");
+
+ final String tableIdentifier = "taxi_dataset.passenger_count_by_minute";
+ final String pubsubTopic = options.getTopic();
+ final String catalogUri = options.getCatalogUri();
+ final String warehouseLocation = options.getWarehouse();
+ final String projectName = options.getProject();
+ final String catalogName = options.getCatalogName();
+ final int triggeringFrequencySeconds = 30;
+
+ // Note: The token expires in 1 hour, and users may need to re-run the pipeline.
+ // Upcoming changes in Iceberg and the BigLake Metastore with the Iceberg REST Catalog
+ // will support token refreshing and credential vending.
+ Map<String, String> catalogProps =
+ ImmutableMap.<String, String>builder()
+ .put("type", "rest")
+ .put("uri", catalogUri)
+ .put("warehouse", warehouseLocation)
+ .put("header.x-goog-user-project", projectName)
+ .put("oauth2-server-uri", "https://oauth2.googleapis.com/token")
+ .put(
+ "token",
+ GoogleCredentials.getApplicationDefault().refreshAccessToken().getTokenValue())
+ .put("rest-metrics-reporting-enabled", "false")
+ .build();
+
+ Map<String, Object> icebergWriteConfig =
+ ImmutableMap.<String, Object>builder()
+ .put("table", tableIdentifier)
+ .put("catalog_properties", catalogProps)
+ .put("catalog_name", catalogName)
+ .put("triggering_frequency_seconds", triggeringFrequencySeconds)
+ .build();
+
+ Pipeline p = Pipeline.create(options);
+
+ PCollection<Row> aggregatedRows =
+ p.apply("ReadFromPubSub", PubsubIO.readStrings().fromTopic(pubsubTopic))
+ .apply("ConvertJsonToRow", JsonToRow.withSchema(TAXIRIDES_SCHEMA))
+ .apply(
+ "FilterNullFields",
+ Filter.by(
+ (Row row) ->
+ row.getInt64("passenger_count") != null
+ && row.getDateTime("timestamp") != null))
+ .apply(
+ "FilterDropoffRides",
+ Filter.by((Row row) -> "dropoff".equals(row.getString("ride_status"))))
+ .apply(
+ "ApplyFixedWindow", Window.<Row>into(FixedWindows.of(Duration.standardSeconds(10))))
+ .apply(
+ "ExtractMinuteAndPassengerCount",
+ MapElements.into(
+ TypeDescriptors.kvs(TypeDescriptors.strings(), TypeDescriptors.longs()))
+ .via(
+ (Row row) -> {
+ Long passengerCount = row.getInt64("passenger_count");
+ DateTime timestamp =
+ (DateTime)
+ Preconditions.checkStateNotNull(row.getDateTime("timestamp"));
+ String minute = timestamp.toString("yyyy-MM-dd HH:mm");
+ return KV.of(minute, passengerCount);
+ }))
Review Comment:
nit: can we shorten this logic?
i.e. `row -> KV.of(checkStateNotNull(row.getDateTime("timestamp")).toString("..."), row.getInt64())
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Iceberg Rest Catalog Example [beam]
Posted by "ahmedabu98 (via GitHub)" <gi...@apache.org>.
ahmedabu98 merged PR #35599:
URL: https://github.com/apache/beam/pull/35599
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Iceberg Rest Catalog Example [beam]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #35599:
URL: https://github.com/apache/beam/pull/35599#issuecomment-3080489905
Assigning reviewers:
R: @chamikaramj for label java.
Note: If you would like to opt out of this review, comment `assign to next reviewer`.
Available commands:
- `stop reviewer notifications` - opt out of the automated review tooling
- `remind me after tests pass` - tag the comment author after tests pass
- `waiting on author` - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)
The PR bot will only process comments in the main thread (not review comments).
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Add Iceberg Rest Catalog Example [beam]
Posted by "liferoad (via GitHub)" <gi...@apache.org>.
liferoad commented on code in PR #35599:
URL: https://github.com/apache/beam/pull/35599#discussion_r2213871959
##########
examples/java/src/main/java/org/apache/beam/examples/cookbook/IcebergRestCatalogStreamingWriteExample.java:
##########
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.beam.examples.cookbook;
+
+import com.google.auth.oauth2.GoogleCredentials;
+import java.io.IOException;
+import java.util.Map;
+import org.apache.beam.sdk.Pipeline;
+import org.apache.beam.sdk.coders.RowCoder;
+import org.apache.beam.sdk.extensions.gcp.options.GcpOptions;
+import org.apache.beam.sdk.io.gcp.pubsub.PubsubIO;
+import org.apache.beam.sdk.managed.Managed;
+import org.apache.beam.sdk.options.Default;
+import org.apache.beam.sdk.options.Description;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.apache.beam.sdk.options.Validation;
+import org.apache.beam.sdk.schemas.Schema;
+import org.apache.beam.sdk.transforms.DoFn;
+import org.apache.beam.sdk.transforms.Filter;
+import org.apache.beam.sdk.transforms.JsonToRow;
+import org.apache.beam.sdk.transforms.MapElements;
+import org.apache.beam.sdk.transforms.ParDo;
+import org.apache.beam.sdk.transforms.Sum;
+import org.apache.beam.sdk.transforms.windowing.FixedWindows;
+import org.apache.beam.sdk.transforms.windowing.Window;
+import org.apache.beam.sdk.values.KV;
+import org.apache.beam.sdk.values.PCollection;
+import org.apache.beam.sdk.values.Row;
+import org.apache.beam.sdk.values.TypeDescriptors;
+import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap;
+import org.joda.time.DateTime;
+import org.joda.time.Duration;
+
+/**
+ * Reads real-time NYC taxi ride information from {@code
+ * projects/pubsub-public-data/topics/taxirides-realtime} and writes aggregated passenger count data
+ * to an Iceberg table using Beam's {@link Managed} IcebergIO sink.
+ *
+ * <p>This is a streaming pipeline that processes taxi ride events, filters for 'dropoff' status,
+ * aggregates passenger counts within fixed 10-second windows by minute of the ride, and writes the
+ * results to a single Iceberg table. The Iceberg sink triggers writes every 30 seconds, creating
+ * new snapshots.
+ */
+public class IcebergRestCatalogStreamingWriteExample {
+
+ public static final Schema TAXIRIDES_SCHEMA =
+ Schema.builder()
+ .addInt64Field("passenger_count")
+ .addStringField("ride_status")
+ .addDateTimeField("timestamp")
+ .build();
+
+ public static final Schema AGGREGATED_SCHEMA =
+ Schema.builder().addStringField("ride_minute").addInt64Field("passenger_count").build();
+
+ /**
+ * Main entry point for the pipeline.
+ *
+ * @param args Command line arguments
+ * @throws IOException if there's an issue with GoogleCredentials
+ */
+ public static void main(String[] args) throws IOException {
+ IcebergPipelineOptions options =
+ PipelineOptionsFactory.fromArgs(args).withValidation().as(IcebergPipelineOptions.class);
+ options.setProject("apache-beam-testing");
+
+ final String tableIdentifier = "taxi_dataset.passenger_count_by_minute";
+ final String pubsubTopic = options.getTopic();
+ final String catalogUri = options.getCatalogUri();
+ final String warehouseLocation = options.getWarehouse();
+ final String projectName = options.getProject();
+ final String catalogName = options.getCatalogName();
+ final int triggeringFrequencySeconds = 30;
+
+ Map<String, String> catalogProps =
+ ImmutableMap.<String, String>builder()
+ .put("type", "rest")
Review Comment:
possible to link the BQ rest catalog doc url here as the comments?
--
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.
To unsubscribe, e-mail: github-unsubscribe@beam.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org