davisusanibar commented on issue #315:
URL: https://github.com/apache/arrow-cookbook/issues/315#issuecomment-1636861035

   Hi @pronzato. I appreciate you pointing out the HDFS issue. With this PR, 
HDFS will be enabled by default on Java Dataset module 
https://github.com/apache/arrow/pull/36704
   
   As a result of the new changes, I am now able to read HDFS parquet files, 
but the program will not shut down for some reason.
   
   ```java
   import org.apache.arrow.dataset.file.FileFormat;
   import org.apache.arrow.dataset.file.FileSystemDatasetFactory;
   import org.apache.arrow.dataset.jni.NativeMemoryPool;
   import org.apache.arrow.dataset.scanner.ScanOptions;
   import org.apache.arrow.dataset.scanner.Scanner;
   import org.apache.arrow.dataset.source.Dataset;
   import org.apache.arrow.dataset.source.DatasetFactory;
   import org.apache.arrow.memory.BufferAllocator;
   import org.apache.arrow.memory.RootAllocator;
   import org.apache.arrow.vector.ipc.ArrowReader;
   import org.apache.arrow.vector.types.pojo.Schema;
   
   public class ReadHdfsParquet {
       public static void main(String[] args) {
           //declare JVM environment variable: HADOOP_HOME = 
/Users/dsusanibar/hadoop-3.3.2
           //where to search for: lib/native/libhdfs.dylib
           String uri = 
"hdfs://localhost:9000/Users/dsusanibar/data4_2rg_gzip.parquet";
           ScanOptions options = new ScanOptions(/*batchSize*/ 32768);
           try (
               BufferAllocator allocator = new RootAllocator();
               DatasetFactory datasetFactory = new 
FileSystemDatasetFactory(allocator, NativeMemoryPool.getDefault(), 
FileFormat.PARQUET, uri);
               Dataset dataset = datasetFactory.finish();
               Scanner scanner = dataset.newScan(options);
               ArrowReader reader = scanner.scanBatches()
           ) {
               Schema schema = scanner.schema();
               System.out.println(schema);
               while (reader.loadNextBatch()) {
                   
System.out.println(reader.getVectorSchemaRoot().contentToTSVString());
                   System.out.println("RowCount: " + 
reader.getVectorSchemaRoot().getRowCount());
               }
           } catch (Exception e) {
               e.printStackTrace();
           }
       }
   }
   ```
   <img width="1654" alt="image" 
src="https://github.com/apache/arrow-cookbook/assets/4554485/8e3d4f72-de1c-471f-93a7-fdbd8d9060ed";>
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to