Class SchemasUtils


  • public class SchemasUtils
    extends java.lang.Object
    The SchemasUtils Class to read JSON based schema. Is there available to read from file or from string. Currently supported local File System and GCS.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEADLETTER_SCHEMA  
    • Constructor Summary

      Constructors 
      Constructor Description
      SchemasUtils​(java.lang.String schema)  
      SchemasUtils​(java.lang.String path, java.nio.charset.Charset encoding)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.apache.beam.sdk.schemas.Schema getBeamSchema()  
      com.google.api.services.bigquery.model.TableSchema getBigQuerySchema()  
      static java.lang.String getGcsFileAsString​(java.lang.String filePath)
      Reads a file from GCS and returns it as a string.
      java.lang.String getJsonBeamSchema()  
      static byte[] readGcsFile​(java.lang.String gcsFilePath)
      Method to read a schema file from GCS and return the file contents as a string.
      • Methods inherited from class java.lang.Object

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

      • DEADLETTER_SCHEMA

        public static final java.lang.String DEADLETTER_SCHEMA
        See Also:
        Constant Field Values
    • Constructor Detail

      • SchemasUtils

        public SchemasUtils​(java.lang.String schema)
      • SchemasUtils

        public SchemasUtils​(java.lang.String path,
                            java.nio.charset.Charset encoding)
                     throws java.io.IOException
        Throws:
        java.io.IOException
    • Method Detail

      • getBigQuerySchema

        public com.google.api.services.bigquery.model.TableSchema getBigQuerySchema()
      • readGcsFile

        public static byte[] readGcsFile​(java.lang.String gcsFilePath)
                                  throws java.io.IOException
        Method to read a schema file from GCS and return the file contents as a string.
        Parameters:
        gcsFilePath - path to file in GCS in format "gs://your-bucket/path/to/file"
        Returns:
        byte array with file contents
        Throws:
        java.io.IOException - thrown if not able to read file
      • getBeamSchema

        public org.apache.beam.sdk.schemas.Schema getBeamSchema()
      • getJsonBeamSchema

        public java.lang.String getJsonBeamSchema()
      • getGcsFileAsString

        public static java.lang.String getGcsFileAsString​(java.lang.String filePath)
        Reads a file from GCS and returns it as a string.
        Parameters:
        filePath - path to file in GCS
        Returns:
        contents of the file as a string
        Throws:
        java.io.IOException - thrown if not able to read file