[ https://issues.apache.org/jira/browse/BEAM-5191?focusedWorklogId=270841&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-270841 ]
ASF GitHub Bot logged work on BEAM-5191: ---------------------------------------- Author: ASF GitHub Bot Created on: 02/Jul/19 12:26 Start Date: 02/Jul/19 12:26 Worklog Time Spent: 10m Work Description: jklukas commented on pull request #8945: [BEAM-5191] Support for BigQuery clustering URL: https://github.com/apache/beam/pull/8945#discussion_r299455880 ########## File path: sdks/java/io/google-cloud-platform/src/test/java/org/apache/beam/sdk/io/gcp/bigquery/BigQueryTimePartitioningClusteringIT.java ########## @@ -0,0 +1,150 @@ +/* + * 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.io.gcp.bigquery; + +import com.google.api.services.bigquery.Bigquery; +import com.google.api.services.bigquery.model.Clustering; +import com.google.api.services.bigquery.model.Table; +import com.google.api.services.bigquery.model.TableFieldSchema; +import com.google.api.services.bigquery.model.TableRow; +import com.google.api.services.bigquery.model.TableSchema; +import com.google.api.services.bigquery.model.TimePartitioning; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import org.apache.beam.sdk.Pipeline; +import org.apache.beam.sdk.io.gcp.testing.BigqueryClient; +import org.apache.beam.sdk.options.Default; +import org.apache.beam.sdk.options.Description; +import org.apache.beam.sdk.options.ExperimentalOptions; +import org.apache.beam.sdk.options.PipelineOptionsFactory; +import org.apache.beam.sdk.testing.TestPipeline; +import org.apache.beam.sdk.testing.TestPipelineOptions; +import org.apache.beam.sdk.transforms.DoFn; +import org.apache.beam.sdk.transforms.ParDo; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +/** Integration test that partitions and clusters sample data in BigQuery. */ +@RunWith(JUnit4.class) +public class BigQueryTimePartitioningClusteringIT { + private static final String WEATHER_SAMPLES_TABLE = + "clouddataflow-readonly:samples.weather_stations"; + + private Bigquery bqClient; + private String datasetName = "BigQueryTimePartitioningIT"; + private BigQueryClusteringITOptions options; + + @Before + public void setUp() { + PipelineOptionsFactory.register(BigQueryClusteringITOptions.class); + options = TestPipeline.testingPipelineOptions().as(BigQueryClusteringITOptions.class); + options.setTempLocation(options.getTempRoot() + "/temp-it/"); + bqClient = BigqueryClient.getNewBigquerryClient(options.getAppName()); + } + + /** Customized PipelineOptions for BigQueryClustering Integration Test. */ + public interface BigQueryClusteringITOptions + extends TestPipelineOptions, ExperimentalOptions, BigQueryOptions { + @Description("Table to read from, specified as " + "<project_id>:<dataset_id>.<table_id>") + @Default.String(WEATHER_SAMPLES_TABLE) + String getInput(); + + void setInput(String value); + } + + static class KeepStationNumberAndConvertDate extends DoFn<TableRow, TableRow> { + @ProcessElement + public void processElement(ProcessContext c) { + String day = (String) c.element().get("day"); + String month = (String) c.element().get("month"); + String year = (String) c.element().get("year"); + + TableRow row = new TableRow(); + row.set("station_number", c.element().get("station_number")); + row.set("date", String.format("%s-%s-%s", year, month, day)); + c.output(row); + } + } + + @Test + public void testE2EBigQueryTimePartitioning() throws Exception { + String tableName = "weather_stations_time_partitioned_" + System.currentTimeMillis(); + + Pipeline p = Pipeline.create(options); + + p.apply(BigQueryIO.readTableRows().from(options.getInput())) + .apply(ParDo.of(new KeepStationNumberAndConvertDate())) + .apply( + BigQueryIO.writeTableRows() + .to(String.format("%s.%s", datasetName, tableName)) + .withTimePartitioning(getTimepartitioning()) + .withSchema(getSchema()) + .withCreateDisposition(BigQueryIO.Write.CreateDisposition.CREATE_IF_NEEDED) + .withWriteDisposition(BigQueryIO.Write.WriteDisposition.WRITE_TRUNCATE)); + + p.run().waitUntilFinish(); + + bqClient = BigqueryClient.getNewBigquerryClient(options.getAppName()); + Table table = bqClient.tables().get(options.getProject(), datasetName, tableName).execute(); + + Assert.assertEquals(table.getTimePartitioning(), getTimepartitioning()); + } + + @Test + public void testE2EBigQueryClustering() throws Exception { + String tableName = "weather_stations_clustered_" + System.currentTimeMillis(); + + Pipeline p = Pipeline.create(options); + + p.apply(BigQueryIO.readTableRows().from(options.getInput())) + .apply(ParDo.of(new KeepStationNumberAndConvertDate())) + .apply( + BigQueryIO.writeTableRows() Review comment: Added. It doesn't look like the ITs are run by Jenkins by default and I also can't find that there's a command to kick off BigQueryIO integration tests. Do you have any advice about how we can get results for these? ---------------------------------------------------------------- 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: 270841) Time Spent: 9h 50m (was: 9h 40m) > Add support for writing to BigQuery clustered tables > ---------------------------------------------------- > > Key: BEAM-5191 > URL: https://issues.apache.org/jira/browse/BEAM-5191 > Project: Beam > Issue Type: Improvement > Components: io-java-gcp > Affects Versions: 2.6.0 > Reporter: Robert Sahlin > Assignee: Wout Scheepers > Priority: Minor > Labels: features, newbie > Time Spent: 9h 50m > Remaining Estimate: 0h > > Google recently added support for clustered tables in BigQuery. It would be > useful to set clustering columns the same way as for partitioning. It should > support multiple fields (4) for clustering. > For example: > [BigQueryIO.Write|https://beam.apache.org/documentation/sdks/javadoc/2.6.0/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.Write.html]<[T|https://beam.apache.org/documentation/sdks/javadoc/2.6.0/org/apache/beam/sdk/io/gcp/bigquery/BigQueryIO.Write.html]> > .withClustering(new Clustering().setField("productId").setType("STRING")) -- This message was sent by Atlassian JIRA (v7.6.3#76005)