Package org.apache.pig.backend.datastorage

Examples of org.apache.pig.backend.datastorage.ElementDescriptor


    }
   
    static public InputStream open(String fileSpec, PigContext pigContext) throws IOException {
        fileSpec = checkDefaultPrefix(pigContext.getExecType(), fileSpec);
        if (!fileSpec.startsWith(LOCAL_PREFIX)) {
            ElementDescriptor elem = pigContext.getDfs().asElement(fullPath(fileSpec, pigContext));
            return openDFSFile(elem);
        }
        else {
            fileSpec = fileSpec.substring(LOCAL_PREFIX.length());
            //buffering because we only want buffered streams to be passed to load functions.
            /*return new BufferedInputStream(new FileInputStream(fileSpec));*/
            ElementDescriptor elem = pigContext.getLfs().asElement(fullPath(fileSpec, pigContext));
            return openLFSFile(elem);
        }
    }
View Full Code Here


     */
    static public SeekableInputStream open(String fileSpec, long offset, PigContext pigContext) throws IOException {
       
        fileSpec = checkDefaultPrefix(pigContext.getExecType(), fileSpec);
       
        ElementDescriptor elem;
        if (!fileSpec.startsWith(LOCAL_PREFIX))
            elem = pigContext.getDfs().asElement(fullPath(fileSpec, pigContext));
               
        else{
            fileSpec = fileSpec.substring(LOCAL_PREFIX.length());
            elem = pigContext.getLfs().asElement(fullPath(fileSpec, pigContext));           
        }
       
        if (elem.exists() && (!elem.getDataStorage().isContainer(elem.toString()))) {
            try {
                if (elem.systemElement())
                    throw new IOException ("Attempt is made to open system file " + elem.toString());
               
                SeekableInputStream sis = elem.sopen();
                sis.seek(offset, FLAGS.SEEK_SET);
                return sis;
            }
            catch (DataStorageException e) {
                throw new IOException("Failed to determine if elem=" + elem + " is container", e);
View Full Code Here

    }

    static public OutputStream create(String fileSpec, boolean append, PigContext pigContext) throws IOException {
        fileSpec = checkDefaultPrefix(pigContext.getExecType(), fileSpec);
        if (!fileSpec.startsWith(LOCAL_PREFIX)) {
            ElementDescriptor elem = pigContext.getDfs().asElement(fileSpec);
            return elem.create();
        }
        else {
            fileSpec = fileSpec.substring(LOCAL_PREFIX.length());

            // TODO probably this should be replaced with the local file system
View Full Code Here

    }
   
    static public boolean delete(String fileSpec, PigContext pigContext) throws IOException{
        fileSpec = checkDefaultPrefix(pigContext.getExecType(), fileSpec);
        if (!fileSpec.startsWith(LOCAL_PREFIX)) {
            ElementDescriptor elem = pigContext.getDfs().asElement(fileSpec);
            elem.delete();
            return true;
        }
        else {
            fileSpec = fileSpec.substring(LOCAL_PREFIX.length());
            boolean ret = true;
View Full Code Here

    }

    public static void deleteTempFiles() {
        while (!toDelete().empty()) {
            try {
                ElementDescriptor elem = toDelete().pop();
                elem.delete();
            }
            catch (IOException e) {
                log.error(e);
            }
        }
View Full Code Here

            relative = relativeRoot(pigContext);
        }
        if (!relativeRoot(pigContext).exists()) {
            relativeRoot(pigContext).create();
        }
        ElementDescriptor elem=
            pigContext.getDfs().asElement(relative.toString(), "tmp" + r.nextInt());
        toDelete().push(elem);
        return elem;
    }
View Full Code Here

        toDelete().push(elem);
        return elem;
    }

    public static Path getTemporaryPath(PigContext pigContext) throws IOException {
        ElementDescriptor relative = relativeRoot(pigContext);
   
        if (!relativeRoot(pigContext).exists()) {
            relativeRoot(pigContext).create();
        }
        ElementDescriptor elem=
            pigContext.getDfs().asElement(relative.toString(), "tmp" + r.nextInt());
        toDelete().push(elem);
        return ((HPath)elem).getPath();
    }
View Full Code Here

    public static String hadoopify(String filename, PigContext pigContext) throws IOException {
        if (filename.startsWith(LOCAL_PREFIX)) {
            filename = filename.substring(LOCAL_PREFIX.length());
        }
       
        ElementDescriptor localElem =
            pigContext.getLfs().asElement(filename);
           
        if (!localElem.exists()) {
            throw new FileNotFoundException(filename);
        }
           
        ElementDescriptor distribElem =
            getTemporaryPath(null, pigContext);
   
        int suffixStart = filename.lastIndexOf('.');
        if (suffixStart != -1) {
            distribElem = pigContext.getDfs().asElement(distribElem.toString() +
                    filename.substring(suffixStart));
        }
           
        // TODO: currently the copy method in Data Storage does not allow to specify overwrite
        //       so the work around is to delete the dst file first, if it exists
        if (distribElem.exists()) {
            distribElem.delete();
        }
        localElem.copy(distribElem, null, false);
           
        return distribElem.toString();
    }
View Full Code Here

    }

    public static String fullPath(String filename, PigContext pigContext) throws IOException {
        try {
            if (filename.charAt(0) != '/') {
                ElementDescriptor currentDir = pigContext.getDfs().getActiveContainer();
                ElementDescriptor elem = pigContext.getDfs().asElement(currentDir.toString(),
                                                                                  filename);
               
                return elem.toString();
            }
            return filename;
        }
        catch (DataStorageException e) {
            return filename;
View Full Code Here

     * @deprecated Use {@link #fileExists(String, PigContext)} instead
     */
    @Deprecated
    public static boolean fileExists(String filename, DataStorage store)
            throws IOException {
        ElementDescriptor elem = store.asElement(filename);
        return elem.exists() || globMatchesFiles(elem, store);
    }
View Full Code Here

TOP

Related Classes of org.apache.pig.backend.datastorage.ElementDescriptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.