Class TestBigQuery

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    public class TestBigQuery
    extends java.lang.Object
    implements org.junit.rules.TestRule
    Test rule which creates a new table with specified schema, with randomized name and exposes few APIs to work with it.

    Deletes the table on test shutdown.

    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base, org.junit.runner.Description description)  
      TestBigQuery.RowsAssertion assertThatAllRows​(org.apache.beam.sdk.schemas.Schema rowSchema)  
      static TestBigQuery create​(org.apache.beam.sdk.schemas.Schema tableSchema)
      Creates an instance of this rule.
      java.util.List<org.apache.beam.sdk.values.Row> getFlatJsonRows​(org.apache.beam.sdk.schemas.Schema rowSchema)
      Loads rows from BigQuery into Rows with given Schema.
      com.google.api.services.bigquery.model.TableDataInsertAllResponse insertRows​(org.apache.beam.sdk.schemas.Schema rowSchema, org.apache.beam.sdk.values.Row... rows)  
      com.google.api.services.bigquery.model.TableReference tableReference()  
      java.lang.String tableSpec()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • create

        @Experimental(SCHEMAS)
        public static TestBigQuery create​(org.apache.beam.sdk.schemas.Schema tableSchema)
        Creates an instance of this rule.

        Loads GCP configuration from TestPipelineOptions.

      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Specified by:
        apply in interface org.junit.rules.TestRule
      • tableSpec

        @RequiresNonNull("table")
        public java.lang.String tableSpec()
      • tableReference

        @RequiresNonNull("table")
        public com.google.api.services.bigquery.model.TableReference tableReference()
      • insertRows

        @Experimental(SCHEMAS)
        @RequiresNonNull("table")
        public com.google.api.services.bigquery.model.TableDataInsertAllResponse insertRows​(org.apache.beam.sdk.schemas.Schema rowSchema,
                                                                                            org.apache.beam.sdk.values.Row... rows)
                                                                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • getFlatJsonRows

        @Experimental(SCHEMAS)
        public java.util.List<org.apache.beam.sdk.values.Row> getFlatJsonRows​(org.apache.beam.sdk.schemas.Schema rowSchema)
        Loads rows from BigQuery into Rows with given Schema.

        Current implementation only supports flat Rows and target Schemas with Schema.FieldType.STRING fields only.

      • assertThatAllRows

        @Experimental(SCHEMAS)
        public TestBigQuery.RowsAssertion assertThatAllRows​(org.apache.beam.sdk.schemas.Schema rowSchema)