Search in sources :

Example 11 with State

use of org.apache.beam.sdk.PipelineResult.State in project beam by apache.

the class TpcdsRun method call.

@Override
public TpcdsRunResult call() {
    TpcdsRunResult tpcdsRunResult;
    try {
        PipelineResult pipelineResult = pipeline.run();
        long startTimeStamp = System.currentTimeMillis();
        State state = pipelineResult.waitUntilFinish();
        long endTimeStamp = System.currentTimeMillis();
        // Make sure to set the job status to be successful only when pipelineResult's final state is
        // DONE.
        boolean isSuccessful = state == State.DONE;
        tpcdsRunResult = new TpcdsRunResult(isSuccessful, startTimeStamp, endTimeStamp, pipeline.getOptions(), pipelineResult);
    } catch (Exception e) {
        // If the pipeline execution failed, return a result with failed status but don't interrupt
        // other threads.
        e.printStackTrace();
        tpcdsRunResult = new TpcdsRunResult(false, 0, 0, pipeline.getOptions(), null);
    }
    return tpcdsRunResult;
}
Also used : State(org.apache.beam.sdk.PipelineResult.State) PipelineResult(org.apache.beam.sdk.PipelineResult)

Example 12 with State

use of org.apache.beam.sdk.PipelineResult.State in project beam by apache.

the class DataStoreReadWriteIT method testReadAllSupportedTypes.

@Test
public void testReadAllSupportedTypes() {
    BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(new DataStoreV1TableProvider());
    String projectId = options.getProject();
    final Schema expectedSchema = Schema.builder().addNullableField("__key__", VARBINARY).addNullableField("boolean", BOOLEAN).addNullableField("datetime", DATETIME).addNullableField("floatingnumber", DOUBLE).addNullableField("integer", INT64).addNullableField("primitivearray", FieldType.array(STRING)).addNullableField("string", STRING).addNullableField("text", STRING).build();
    String createTableStatement = "CREATE EXTERNAL TABLE TEST( \n" + "   `__key__` VARBINARY, \n" + "   `boolean` BOOLEAN, \n" + "   `datetime` TIMESTAMP, \n" + // + "   `embeddedentity` ROW(`property1` VARCHAR, `property2` BIGINT), \n"
    "   `floatingnumber` DOUBLE, \n" + "   `integer` BIGINT, \n" + "   `primitivearray` ARRAY<VARCHAR>, \n" + "   `string` VARCHAR, \n" + "   `text` VARCHAR" + ") \n" + "TYPE 'datastoreV1' \n" + "LOCATION '" + projectId + "/" + KIND_ALL_TYPES + "'";
    sqlEnv.executeDdl(createTableStatement);
    String selectTableStatement = "SELECT * FROM TEST";
    PCollection<Row> output = BeamSqlRelUtils.toPCollection(readPipeline, sqlEnv.parseQuery(selectTableStatement));
    assertThat(output.getSchema(), equalTo(expectedSchema));
    PipelineResult.State state = readPipeline.run().waitUntilFinish(Duration.standardMinutes(5));
    assertThat(state, equalTo(State.DONE));
}
Also used : State(org.apache.beam.sdk.PipelineResult.State) Schema(org.apache.beam.sdk.schemas.Schema) PipelineResult(org.apache.beam.sdk.PipelineResult) BeamSqlEnv(org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv) ByteString(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.avatica.util.ByteString) Row(org.apache.beam.sdk.values.Row) EntityToRow(org.apache.beam.sdk.io.gcp.datastore.EntityToRow) Test(org.junit.Test)

Example 13 with State

use of org.apache.beam.sdk.PipelineResult.State in project beam by apache.

the class DataStoreReadWriteIT method testDataStoreV1SqlWriteRead.

@Test
public void testDataStoreV1SqlWriteRead() {
    BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(new DataStoreV1TableProvider());
    String projectId = options.getProject();
    String createTableStatement = "CREATE EXTERNAL TABLE TEST( \n" + "   `__key__` VARBINARY, \n" + "   `content` VARCHAR \n" + ") \n" + "TYPE 'datastoreV1' \n" + "LOCATION '" + projectId + "/" + KIND + "'";
    sqlEnv.executeDdl(createTableStatement);
    Key ancestor = makeKey(KIND, UUID.randomUUID().toString()).build();
    Key itemKey = makeKey(ancestor, KIND, UUID.randomUUID().toString()).build();
    String insertStatement = "INSERT INTO TEST VALUES ( \n" + keyToSqlByteString(itemKey) + ", \n" + "'2000' \n" + ")";
    BeamSqlRelUtils.toPCollection(writePipeline, sqlEnv.parseQuery(insertStatement));
    writePipeline.run().waitUntilFinish();
    String selectTableStatement = "SELECT * FROM TEST";
    PCollection<Row> output = BeamSqlRelUtils.toPCollection(readPipeline, sqlEnv.parseQuery(selectTableStatement));
    assertThat(output.getSchema(), equalTo(SOURCE_SCHEMA));
    PipelineResult.State state = readPipeline.run().waitUntilFinish(Duration.standardMinutes(5));
    assertThat(state, equalTo(State.DONE));
}
Also used : State(org.apache.beam.sdk.PipelineResult.State) PipelineResult(org.apache.beam.sdk.PipelineResult) BeamSqlEnv(org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv) ByteString(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.avatica.util.ByteString) Row(org.apache.beam.sdk.values.Row) EntityToRow(org.apache.beam.sdk.io.gcp.datastore.EntityToRow) Key(com.google.datastore.v1.Key) DatastoreHelper.makeKey(com.google.datastore.v1.client.DatastoreHelper.makeKey) Test(org.junit.Test)

Example 14 with State

use of org.apache.beam.sdk.PipelineResult.State in project beam by apache.

the class AvroTableProviderTest method testWriteAndReadTable.

@Test
public void testWriteAndReadTable() {
    File destinationFile = new File(tempFolder.getRoot(), "person-info.avro");
    String query = "INSERT INTO PersonInfo VALUES ('Alan', 22, 'England'), ('John', 42, 'USA')";
    String ddl = String.format("CREATE EXTERNAL TABLE PersonInfo %s TYPE avro LOCATION '%s'", FIELD_NAMES, destinationFile.getAbsolutePath());
    writePipeline.apply(SqlTransform.query(query).withDdlString(ddl));
    writePipeline.run().waitUntilFinish();
    String readQuery = "SELECT age, country FROM PersonInfo WHERE age > 25";
    PCollection<Row> rows = readPipeline.apply(SqlTransform.query(readQuery).withDdlString(ddl));
    PAssert.that(rows).containsInAnyOrder(Row.withSchema(OUTPUT_ROW_SCHEMA).addValues(42L, "USA").build());
    PipelineResult.State state = readPipeline.run().waitUntilFinish();
    assertEquals(State.DONE, state);
}
Also used : State(org.apache.beam.sdk.PipelineResult.State) PipelineResult(org.apache.beam.sdk.PipelineResult) Row(org.apache.beam.sdk.values.Row) File(java.io.File) Test(org.junit.Test)

Example 15 with State

use of org.apache.beam.sdk.PipelineResult.State in project beam by apache.

the class BigQueryReadWriteIT method testSQLRead_withExport.

@Test
public void testSQLRead_withExport() throws IOException {
    bigQueryTestingTypes.insertRows(SOURCE_SCHEMA_TWO, row(SOURCE_SCHEMA_TWO, 9223372036854775807L, (byte) 127, (short) 32767, 2147483647, (float) 1.0, 1.0, true, parseTimestampWithUTCTimeZone("2018-05-28 20:17:40.123"), "varchar", "char", Arrays.asList("123", "456")));
    BeamSqlEnv sqlEnv = BeamSqlEnv.inMemory(new BigQueryTableProvider());
    String createTableStatement = "CREATE EXTERNAL TABLE TEST( \n" + "   c_bigint BIGINT, \n" + "   c_tinyint TINYINT, \n" + "   c_smallint SMALLINT, \n" + "   c_integer INTEGER, \n" + "   c_float FLOAT, \n" + "   c_double DOUBLE, \n" + "   c_boolean BOOLEAN, \n" + "   c_timestamp TIMESTAMP, \n" + "   c_varchar VARCHAR, \n " + "   c_char CHAR, \n" + "   c_arr ARRAY<VARCHAR> \n" + ") \n" + "TYPE 'bigquery' \n" + "LOCATION '" + bigQueryTestingTypes.tableSpec() + "'" + "TBLPROPERTIES " + "'{ " + METHOD_PROPERTY + ": \"" + Method.EXPORT.toString() + "\" }'";
    sqlEnv.executeDdl(createTableStatement);
    String selectTableStatement = "SELECT * FROM TEST";
    PCollection<Row> output = BeamSqlRelUtils.toPCollection(readPipeline, sqlEnv.parseQuery(selectTableStatement));
    PAssert.that(output).containsInAnyOrder(row(SOURCE_SCHEMA_TWO, 9223372036854775807L, (byte) 127, (short) 32767, 2147483647, (float) 1.0, 1.0, true, parseTimestampWithUTCTimeZone("2018-05-28 20:17:40.123"), "varchar", "char", Arrays.asList("123", "456")));
    PipelineResult.State state = readPipeline.run().waitUntilFinish(Duration.standardMinutes(5));
    assertThat(state, equalTo(State.DONE));
}
Also used : State(org.apache.beam.sdk.PipelineResult.State) PipelineResult(org.apache.beam.sdk.PipelineResult) BeamSqlEnv(org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv) Row(org.apache.beam.sdk.values.Row) Test(org.junit.Test)

Aggregations

State (org.apache.beam.sdk.PipelineResult.State)23 Test (org.junit.Test)18 PipelineResult (org.apache.beam.sdk.PipelineResult)14 Row (org.apache.beam.sdk.values.Row)12 BeamSqlEnv (org.apache.beam.sdk.extensions.sql.impl.BeamSqlEnv)10 IOException (java.io.IOException)4 Job (com.google.api.services.dataflow.model.Job)3 EntityToRow (org.apache.beam.sdk.io.gcp.datastore.EntityToRow)3 ByteString (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.avatica.util.ByteString)3 File (java.io.File)2 Pipeline (org.apache.beam.sdk.Pipeline)2 BeamPushDownIOSourceRel (org.apache.beam.sdk.extensions.sql.impl.rel.BeamPushDownIOSourceRel)2 BeamRelNode (org.apache.beam.sdk.extensions.sql.impl.rel.BeamRelNode)2 Dataflow (com.google.api.services.dataflow.Dataflow)1 Messages (com.google.api.services.dataflow.Dataflow.Projects.Locations.Jobs.Messages)1 JobMetrics (com.google.api.services.dataflow.model.JobMetrics)1 MetricUpdate (com.google.api.services.dataflow.model.MetricUpdate)1 Key (com.google.datastore.v1.Key)1 DatastoreHelper.makeKey (com.google.datastore.v1.client.DatastoreHelper.makeKey)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1