Skip to content

Commit

Permalink
Merge pull request #829 from Polber:jkinard/BigQueryToTFRecordIT
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 544553298
  • Loading branch information
cloud-teleport committed Jun 30, 2023
2 parents 80c3bd3 + 8fc4f4c commit 1276f71
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2023 Google LLC
*
* 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.
*/
package com.google.cloud.teleport.templates;

import static com.google.cloud.teleport.it.truthmatchers.PipelineAsserts.assertThatPipeline;
import static com.google.cloud.teleport.it.truthmatchers.PipelineAsserts.assertThatResult;
import static com.google.common.truth.Truth.assertThat;

import com.google.cloud.teleport.it.common.PipelineLauncher;
import com.google.cloud.teleport.it.common.PipelineOperator;
import com.google.cloud.teleport.it.gcp.TemplateTestBase;
import com.google.cloud.teleport.it.gcp.artifacts.Artifact;
import com.google.cloud.teleport.metadata.TemplateIntegrationTest;
import com.google.common.io.Resources;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.regex.Pattern;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@Category(TemplateIntegrationTest.class)
@TemplateIntegrationTest(value = BigQueryToTFRecord.class)
@RunWith(JUnit4.class)
public class BigQueryToTFRecordIT extends TemplateTestBase {

private static final String GCS_RESULTS_SUFFIX = "/results/";

private static final String SQL_QUERY =
"Select station_number, year, mean_temp, fog, rain, \"Some Comments\" as comments,\n"
+ " [1,2,3] as test_int_array, [\"hello\", \"world\"] as test_string_array,\n"
+ " [2.40, 2.60] as test_float_array, [true, false] as test_boolean_array\n"
+ " from `bigquery-public-data.samples.gsod`\n"
+ " where station_number=31590 and year=1933 and month=5 and day=11;";

@Test
public void testBigQueryToTfRecord() throws IOException, URISyntaxException {
// Act
PipelineLauncher.LaunchInfo info =
launchTemplate(
PipelineLauncher.LaunchConfig.builder(testName, specPath)
.addParameter("readQuery", SQL_QUERY)
.addParameter("outputDirectory", getGcsPath(testName) + GCS_RESULTS_SUFFIX));
assertThatPipeline(info).isRunning();

PipelineOperator.Result result = pipelineOperator().waitUntilDoneAndFinish(createConfig(info));

List<Artifact> artifacts =
gcsClient.listArtifacts(testName + GCS_RESULTS_SUFFIX, Pattern.compile(".*tfrecord"));

// Assert
assertThatResult(result).isLaunchFinished();
assertThat(artifacts.get(0).contents())
.isEqualTo(
Files.readAllBytes(
Path.of(Resources.getResource("BigQueryToTFRecordIT/output.tfrecord").toURI())));
}
}
Binary file not shown.

0 comments on commit 1276f71

Please sign in to comment.