Hi, Jose,

Here is a sample test code based on some input from a user.

In the source code distribution, there is a java directory that
provides some minimal functions accessible through java.

Good luck.

John


On 7/15/15 1:28 PM, José Vitor Delgado Leite wrote:
> Hello everybody,
> 
> I need to add a column in a partition that already have other columns,
> so I made a scipt in Java for generate the binary file of this new
> column in the same directory. But FastBit isn't reading the binary
> file correctly.
> 
> Since I'm programming in Java, I don't think that I could use the
> native data type for storage as same as FastBit does. I would like to
> know how the binary files are created in a partition. Which is the
> encoding of those files?
> 
> Is there any way of create this binary file in Java and FastBit be
> able to read it?
> 
> Thank you,
> José Leite
> 
> 
> _______________________________________________
> FastBit-users mailing list
> [email protected]
> https://hpcrdm.lbl.gov/cgi-bin/mailman/listinfo/fastbit-users
> 
/** a tester based on code fragments from Bailu Ding (LinkedIn)

    Started on May 29, 2013.
 */
import java.io.*;
import java.util.Random;
import gov.lbl.fastbit.*;

public class bailu {
    public static void main(String args[]) {
        try {
            int cnt = buildPart("tmp", 750);
            queryTest("tmp", cnt);
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }

    /** Build a data partition for testing.  Return the number of string
     * values that are equal to '0123456789'.
     */
    public static int buildPart(String partdir, long key)
        throws FastBitStringWriterException {
        int size = 10;
        Random rand = new Random();
        int resCnt = 0;

        String[] strArr = new String[size];
        long[] longArr = new long[size];
                
        for (int i = 0; i < size; ++i) {
            longArr[i] = rand.nextLong() % 1024;
            if (longArr[i] < key) {
                // System.out.println("@ " + i);
                strArr[i] = "123456789";
                ++resCnt;
            }
            else {
                strArr[i] = "987654321";
            }
        }
                
        FastBit fb = new FastBit(null);
        FastBitStringWriter writer = new FastBitStringWriter();
                
        fb.add_longs("long", longArr);
        fb.write_buffer(partdir);
                
        writer.addText(partdir, "str", strArr, "UTF-8");
        writer.addStringColumnToMetadata(partdir, "str", "text");
        return resCnt;
    }

    public static void queryTest(String partdir, int cnt)
        throws FastBitStringWriterException {
        FastBit fb = new FastBit(null);
        fb.set_message_level(8);
        String where = "str = '123456789'";
        FastBit.QueryHandle handle = fb.build_query("", partdir, where);
        int resCnt = fb.get_result_size(handle);
        if (cnt == resCnt) {
            System.out.println("queryTest found " + cnt
                               + " tuples as expected");
        }
        else {
            System.out.println("Warning -- queryTest found " + resCnt
                               + " tuples, but " + cnt + " was expected");
        }
    }
}
_______________________________________________
FastBit-users mailing list
[email protected]
https://hpcrdm.lbl.gov/cgi-bin/mailman/listinfo/fastbit-users

Reply via email to