public static Path createTemporaryPath(ConnectorSession session, HdfsContext context, HdfsEnvironment hdfsEnvironment, Path targetPath)
    {
        // use a per-user temporary directory to avoid permission problems
        String temporaryPrefix = getTemporaryStagingDirectoryPath(session)
                .replace("${USER}", context.getIdentity().getUser());

        // use relative temporary directory on ViewFS
        if (isViewFileSystem(context, hdfsEnvironment, targetPath)) {
            if (pathExists(context, hdfsEnvironment, targetPath)) {
                temporaryPrefix = ".hive-staging";
            }
            else {
                //use the temporary folder in parent when target path does not exist
                temporaryPrefix = "../.hive-staging";
            }
        }

        // create a temporary directory on the same filesystem
        Path temporaryRoot = new Path(targetPath, temporaryPrefix);
        if (!pathExists(context, hdfsEnvironment, temporaryRoot)) {
            createDirectory(context, hdfsEnvironment, temporaryRoot);
        }
        Path temporaryPath = new Path(temporaryRoot, randomUUID().toString());

        createDirectory(context, hdfsEnvironment, temporaryPath);

        return temporaryPath;
    }
@Test void testCreateTemporaryPathOnNonViewFS()
    {
        HdfsEnvironment hdfsEnvironment = createTestHdfsEnvironment(new HiveClientConfig(), new MetastoreClientConfig());
        Path nonViewfsPath = new Path("file://" + Files.createTempDir());

        Path temporaryPath = createTemporaryPath(SESSION, CONTEXT, hdfsEnvironment, nonViewfsPath);

        assertEquals(temporaryPath.getParent().toString(), "file:/tmp/presto-user");
        try {
            UUID.fromString(temporaryPath.getName());
        }
        catch (IllegalArgumentException e) {
            fail("Expected a UUID folder name ");
        }
    }