talatuyarer commented on code in PR #34799: URL: https://github.com/apache/beam/pull/34799#discussion_r2078569069
########## sdks/java/extensions/sql/src/test/java/org/apache/beam/sdk/extensions/sql/PubsubToIcebergIT.java: ########## @@ -0,0 +1,249 @@ +/* + * 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.sdk.extensions.sql; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.beam.sdk.schemas.Schema.FieldType.INT64; +import static org.apache.beam.sdk.schemas.Schema.FieldType.STRING; + +import com.google.api.services.bigquery.model.TableRow; +import java.io.IOException; +import java.io.Serializable; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.stream.Collectors; +import org.apache.beam.sdk.extensions.gcp.options.GcpOptions; +import org.apache.beam.sdk.extensions.sql.meta.provider.iceberg.IcebergReadWriteIT; +import org.apache.beam.sdk.extensions.sql.meta.provider.iceberg.IcebergTableProvider; +import org.apache.beam.sdk.io.gcp.bigquery.BigQueryUtils; +import org.apache.beam.sdk.io.gcp.pubsub.PubsubMessage; +import org.apache.beam.sdk.io.gcp.pubsub.TestPubsub; +import org.apache.beam.sdk.io.gcp.testing.BigqueryClient; +import org.apache.beam.sdk.schemas.Schema; +import org.apache.beam.sdk.testing.TestPipeline; +import org.apache.beam.sdk.util.BackOff; +import org.apache.beam.sdk.util.BackOffUtils; +import org.apache.beam.sdk.util.FluentBackoff; +import org.apache.beam.sdk.util.Sleeper; +import org.apache.beam.sdk.values.Row; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableList; +import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.ImmutableMap; +import org.joda.time.Duration; +import org.joda.time.Instant; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestName; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Tests stream writing to Iceberg with Beam SQL. */ +@RunWith(JUnit4.class) +public class PubsubToIcebergIT implements Serializable { + private static final Schema SOURCE_SCHEMA = + Schema.builder().addNullableField("id", INT64).addNullableField("name", STRING).build(); + + @Rule public transient TestPipeline pipeline = TestPipeline.create(); + @Rule public transient TestPubsub pubsub = TestPubsub.create(); + + private static final BigqueryClient BQ_CLIENT = new BigqueryClient("PubsubToIcebergIT"); + static final String DATASET = "sql_pubsub_to_iceberg_it_" + System.nanoTime(); + static String warehouse; + protected static final GcpOptions OPTIONS = + TestPipeline.testingPipelineOptions().as(GcpOptions.class); + @Rule public TestName testName = new TestName(); + + @BeforeClass + public static void createDataset() throws IOException, InterruptedException { + warehouse = + String.format( + "%s%s/%s", + TestPipeline.testingPipelineOptions().getTempLocation(), + IcebergReadWriteIT.class.getSimpleName(), + UUID.randomUUID()); + BQ_CLIENT.createNewDataset(OPTIONS.getProject(), DATASET); + } + + private String tableIdentifier; + private Map<String, String> icebergConfig; + + @Before + public void setup() { + tableIdentifier = DATASET + "." + testName.getMethodName(); + icebergConfig = + ImmutableMap.of( + "catalog-impl", "org.apache.iceberg.gcp.bigquery.BigQueryMetastoreCatalog", + "io-impl", "org.apache.iceberg.gcp.gcs.GCSFileIO", + "warehouse", warehouse, + "gcp_project", OPTIONS.getProject(), + "gcp_region", "us-central1"); + } + + @AfterClass + public static void deleteDataset() { + BQ_CLIENT.deleteDataset(OPTIONS.getProject(), DATASET); + } + + @Test + public void testSimpleInsert() throws Exception { + String pubsubTableString = + "CREATE EXTERNAL TABLE pubsub_topic (\n" + + "event_timestamp TIMESTAMP, \n" + + "attributes MAP<VARCHAR, VARCHAR>, \n" + + "payload ROW< \n" + + " id BIGINT, \n" + + " name VARCHAR \n" + + " > \n" + + ") \n" + + "TYPE 'pubsub' \n" + + "LOCATION '" + + pubsub.topicPath() + + "' \n" + + "TBLPROPERTIES '{ \"timestampAttributeKey\" : \"ts\" }'"; + String icebergTableString = + "CREATE EXTERNAL TABLE iceberg_table( \n" + + " id BIGINT, \n" + + " name VARCHAR \n " + + ") \n" + + "TYPE 'iceberg' \n" + + "LOCATION '" + + tableIdentifier + + "' \n" + + "TBLPROPERTIES '{ \"triggering_frequency_seconds\" : 10 }'"; Review Comment: Can I define partition column with transform function for my Iceberg Table ? -- 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-unsubscr...@beam.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org