https://delta.io logo
a

Abolfazl karimian

08/02/2023, 10:33 AM
Hi every one I'm using delta-kernel to read from a table using JAVA. I'm able to get table files but i'm not able to read data.
Copy code
Configuration conf = new Configuration(); 

        TableClient myTableClient = DefaultTableClient.create(conf);  

        Table myTable = Table.forPath("Table/Path");  
        Snapshot mySnapshot = myTable.getLatestSnapshot(myTableClient);  


        Scan myScan = mySnapshot.getScanBuilder(myTableClient).build();
        Row state = myScan.getScanState(myTableClient);
        
        CloseableIterator<ColumnarBatch> FilesBatchIter = myScan.getScanFiles(myTableClient);
        Optional<Expression> exp = Optional.empty();
this is the configuration that seems right.(I dont know about Optional<Expression>) Not i want to use them to fetch data from table
Copy code
while (FilesBatchIter.hasNext()) {
            CloseableIterator<Row> files = FilesBatchIter.next().getRows();
            CloseableIterator<DataReadResult> dataResult = Scan.readData(myTableClient, state, files, exp);
            
            // prints the file names
            while (files.hasNext()) {
                Row file = files.next();
                String column1Value = file.getString(0);
                System.out.println(column1Value);

            }

            // Checking if any result is fetched by Scan.readData
            while (dataResult.hasNext()) {
                System.out.println("Data Found!");
            }


        }
It will prints file names but it seems there would be nothing in dataResult. Any Ideas? or any sample code? (edited)
t

Tom van Bussel

08/02/2023, 2:25 PM
Does it work if you remove the loop over
files
?
Scan.readData
uses the argument iterator directly, instead of creating a copy of it. With your current code the iterator is completely emptied by the time that
dataResult.hasNext()
is called.
a

Abolfazl karimian

08/05/2023, 8:44 AM
thanks a lot @Tom van Bussel It worked.