Package org.apache.pig.backend.datastorage

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


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


   
    private String createHadoopTempFile(PigContext ctx) throws Throwable {
       
        File fp1 = generateTempFile() ;
               
        ElementDescriptor localElem =
            ctx.getLfs().asElement(fp1.getAbsolutePath());          
           
        String path = fp1.getAbsolutePath();
        if (System.getProperty("os.name").toUpperCase().startsWith("WINDOWS"))
            path = FileLocalizer.parseCygPath(path, FileLocalizer.STYLE_UNIX);
           
        ElementDescriptor distribElem = ctx.getDfs().asElement(path) ;
   
        localElem.copy(distribElem, null, false);
           
        return distribElem.toString();
    }
View Full Code Here

        
        String path = fp1.getAbsolutePath();
        if (System.getProperty("os.name").toUpperCase().startsWith("WINDOWS"))
            path = FileLocalizer.parseCygPath(path, FileLocalizer.STYLE_UNIX);
       
        ElementDescriptor distribElem = ctx.getDfs().asElement(path) ;
       
        if (distribElem.exists()) {
            distribElem.delete() ;
        }  
           
        return distribElem.toString();
    }
View Full Code Here

        System.out.println("testing capacity");
        long capacity = pig.capacity();
        assertTrue(capacity > 0);
        String sampleFileName = "/tmp/fileTest";
        if (!pig.existsFile(sampleFileName)) {
            ElementDescriptor path = pigContext.getDfs().asElement(sampleFileName);
            OutputStream os = path.create();
            os.write("Ben was here!".getBytes());
            os.close();
        }
        long length = pig.fileSize(sampleFileName);
        assertTrue(length > 0);
View Full Code Here

     * @return length of the file in bytes
     * @throws IOException
     */
    public long fileSize(String filename) throws IOException {
        DataStorage dfs = pigContext.getDfs();
        ElementDescriptor elem = dfs.asElement(filename);
        Map<String, Object> stats = elem.getStatistics();
        long length = (Long) stats.get(ElementDescriptor.LENGTH_KEY);
        int replication = (Short) stats
                .get(ElementDescriptor.BLOCK_REPLICATION_KEY);

        return length * replication;
 
View Full Code Here

        return length * replication;
    }
   
    public boolean existsFile(String filename) throws IOException {
        ElementDescriptor elem = pigContext.getDfs().asElement(filename);
        return elem.exists();
    }
View Full Code Here

        ElementDescriptor elem = pigContext.getDfs().asElement(filename);
        return elem.exists();
    }
   
    public boolean deleteFile(String filename) throws IOException {
        ElementDescriptor elem = pigContext.getDfs().asElement(filename);
        elem.delete();
        return true;
    }
View Full Code Here

        Collection<String> allPaths = new ArrayList<String>();
        ContainerDescriptor container = pigContext.getDfs().asContainer(dir);
        Iterator<ElementDescriptor> iter = container.iterator();
           
        while (iter.hasNext()) {
            ElementDescriptor elem = iter.next();
            allPaths.add(elem.toString());
        }
           
        String[] type = new String[1];
        return allPaths.toArray(type);
    }
View Full Code Here

    {
        executeBatch();

        try {
            byte buffer[] = new byte[65536];
            ElementDescriptor dfsPath = mDfs.asElement(path);
            int rc;
           
            if (!dfsPath.exists())
                throw new IOException("Directory " + path + " does not exist.");
   
            if (mDfs.isContainer(path)) {
                ContainerDescriptor dfsDir = (ContainerDescriptor) dfsPath;
                Iterator<ElementDescriptor> paths = dfsDir.iterator();
               
                while (paths.hasNext()) {
                    ElementDescriptor curElem = paths.next();
                   
                    if (mDfs.isContainer(curElem.toString())) {
                        continue;
                    }
                   
                    InputStream is = curElem.open();
                    while ((rc = is.read(buffer)) > 0) {
                        System.out.write(buffer, 0, rc);
                    }
                    is.close();               
                }
View Full Code Here

       
    @Override
    protected void processLS(String path) throws IOException
    {
        try {
            ElementDescriptor pathDescriptor;
           
            if (path == null) {
                pathDescriptor = mDfs.getActiveContainer();
            }
            else {
                pathDescriptor = mDfs.asElement(path);
            }

            if (!pathDescriptor.exists()) {
                throw new IOException("File or directory " + path + " does not exist.");               
            }
           
            if (mDfs.isContainer(pathDescriptor.toString())) {
                ContainerDescriptor container = (ContainerDescriptor) pathDescriptor;
                Iterator<ElementDescriptor> elems = container.iterator();
               
                while (elems.hasNext()) {
                    ElementDescriptor curElem = elems.next();
                   
                    if (mDfs.isContainer(curElem.toString())) {
                           System.out.println(curElem.toString() + "\t<dir>");
                    } else {
                        printLengthAndReplication(curElem);
                    }
                }
            } else {
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.