hive-protolib/src/main/java/com/streamsets/pipeline/stage/lib/hive/HiveMetastoreUtil.java
public static String serializeSchemaToHDFS(
      UserGroupInformation loginUGI,
      final FileSystem fs,
      final String location,
      final String schemaFolder,
      final String databaseName,
      final String tableName,
      final String schemaJson
  ) throws StageException {
    String folderLocation;
    if (schemaFolder.startsWith(SEP)) {
      folderLocation = schemaFolder;
    } else {
      folderLocation = location + SEP + schemaFolder;
    }
    final Path schemasFolderPath = new Path(folderLocation);
    final String path =  folderLocation + SEP + String.format(
        AVRO_SCHEMA_FILE_FORMAT,
        databaseName,
        tableName,
        UUID.randomUUID().toString()
    );
    try {
      loginUGI.doAs(new PrivilegedExceptionAction<Void>() {
        @Override
        public Void run() throws Exception{
          if (!fs.exists(schemasFolderPath)) {
            fs.mkdirs(schemasFolderPath);
          }
          Path schemaFilePath = new Path(path);
          //This will never happen unless two HMS targets are writing, we will error out for this
          //and let user handle this via error record handling.
          if (!fs.exists(schemaFilePath)) {
            try (FSDataOutputStream os = fs.create(schemaFilePath)) {
              byte []schemaBytes = schemaJson.getBytes("UTF-8");
              os.write(schemaBytes, 0, schemaBytes.length);
            }
          } else {
            LOG.error(Utils.format("Already schema file {} exists in HDFS", path));
            throw new IOException("Already schema file exists");
          }
          return null;
        }
      });
    } catch (Exception e) {
      LOG.error("Error in Writing Schema to HDFS: " + e.toString(), e);
      throw new StageException(Errors.HIVE_18, path, e.getMessage());
    }
    return path;
  }
public static String serializeSchemaToHDFS(
      UserGroupInformation loginUGI,
      final FileSystem fs,
      final String location,
      final String schemaFolder,
      final String databaseName,
      final String tableName,
      final String schemaJson
  ) throws StageException {
    String folderLocation;
    if (schemaFolder.startsWith(SEP)) {
      folderLocation = schemaFolder;
    } else {
      folderLocation = location + SEP + schemaFolder;
    }
    final Path schemasFolderPath = new Path(folderLocation);
    final String path =  folderLocation + SEP + String.format(
        AVRO_SCHEMA_FILE_FORMAT,
        databaseName,
        tableName,
        UUID.randomUUID().toString()
    );
    try {
      loginUGI.doAs(new PrivilegedExceptionAction<Void>() {
        @Override
        public Void run() throws Exception{
          if (!fs.exists(schemasFolderPath)) {
            fs.mkdirs(schemasFolderPath);
          }
          Path schemaFilePath = new Path(path);
          //This will never happen unless two HMS targets are writing, we will error out for this
          //and let user handle this via error record handling.
          if (!fs.exists(schemaFilePath)) {
            try (FSDataOutputStream os = fs.create(schemaFilePath)) {
              byte []schemaBytes = schemaJson.getBytes("UTF-8");
              os.write(schemaBytes, 0, schemaBytes.length);
            }
          } else {
            LOG.error(Utils.format("Already schema file {} exists in HDFS", path));
            throw new IOException("Already schema file exists");
          }
          return null;
        }
      });
    } catch (Exception e) {
      LOG.error("Error in Writing Schema to HDFS: " + e.toString(), e);
      throw new StageException(Errors.HIVE_18, path, e.getMessage());
    }
    return path;
  }
public static String serializeSchemaToHDFS ( UserGroupInformation loginUGI , final FileSystem fs , final String location , final String schemaFolder , final String databaseName , final String tableName , final String schemaJson ) throws StageException { String folderLocation ; if ( schemaFolder . startsWith ( SEP ) ) { folderLocation = schemaFolder ; } else { folderLocation = location + SEP + schemaFolder ; } final Path schemasFolderPath = new Path ( folderLocation ) ; final String path = folderLocation + SEP + String . format ( AVRO_SCHEMA_FILE_FORMAT , databaseName , tableName , UUID . randomUUID ( ) . toString ( ) ) ; try { loginUGI . doAs ( new PrivilegedExceptionAction < Void > ( ) { @ Override public Void run ( ) throws Exception { if ( ! fs . exists ( schemasFolderPath ) ) { fs . mkdirs ( schemasFolderPath ) ; } Path schemaFilePath = new Path ( path ) ; //This will never happen unless two HMS targets are writing, we will error out for this //and let user handle this via error record handling. if ( ! fs . exists ( schemaFilePath ) ) { try ( FSDataOutputStream os = fs . create ( schemaFilePath ) ) { byte [ ] schemaBytes = schemaJson . getBytes ( "UTF-8" ) ; os . write ( schemaBytes , 0 , schemaBytes . length ) ; } } else { LOG . error ( Utils . format ( "Already schema file {} exists in HDFS" , path ) ) ; throw new IOException ( "Already schema file exists" ) ; } return null ; } } ) ; } catch ( Exception e ) { LOG . error ( "Error in Writing Schema to HDFS: " + e . toString ( ) , e ) ; throw new StageException ( Errors . HIVE_18 , path , e . getMessage ( ) ) ; } return path ; }
Returns the hdfs paths where the avro schema is stored after serializing.
Path is appended with current time so as to have an ordering.
@param schemaFolder Schema Folder (If this starts with '/' it is considered absolute)
@return Hdfs Path String.
Returns the hdfs paths where the avro schema is stored after serializing . Path is appended with current time so as to have an ordering .