示例#1
0
JNIEXPORT jint JNICALL Java_gov_lbl_fastbit_FastBit_number_1of_1rows
(JNIEnv * env, jobject jo, jstring jdir) {
    jint            ierr;
    jboolean        iscopy;
    const char     *cdir;
    if (jdir == 0) {
	ierr = -1;
	return ierr;
    }

    cdir = (*env)->GetStringUTFChars(env, jdir, &iscopy);
    ierr = fastbit_rows_in_partition(cdir);
    (*env)->ReleaseStringUTFChars(env, jdir, cdir);
    return ierr;
} /* Java_gov_lbl_fastbit_FastBit_number_1of_1rows */
示例#2
0
/** Create a set of sample data and run some canned queries.

    The sample data contains 100 rows and 3 columns.  The columns are named
    'a', 'b', and 'c'.  They are of types 'int', 'short', and 'float'
    respectively.   The columns a and b have values 0, ..., 99 and column c
    has values 100, 99, ..., 1.
 */
static void builtin(const char *nm, FILE* output) {
    int nerrors = 0;
    int i, mult;
    int32_t ivals[100];
    int16_t svals[100];
    float fvals[100];
    const char *dir = "tmp";
    int counts[] = {5, 24, 19, 10, 50};
    const char* conditions[] =
	{"a<5", "a+b>150", "a < 60 and c < 60", "c > 90", "c > a"};

    /* prepare a sample data */
    for (i = 0; i < 100; ++ i) {
	ivals[i] = i;
	svals[i] = (int16_t) i;
	fvals[i] = (float) (1e2 - i);
    }
    fastbit_add_values("a", "int", ivals, 100, 0);
    fastbit_add_values("b", "short", svals, 100, 0);
    fastbit_add_values("c", "float", fvals, 100, 0);
    fastbit_flush_buffer(dir);
    /* test the queries */
    mult = fastbit_rows_in_partition(dir);
    if (mult % 100 != 0) { /* no an exact multiple */
	fprintf(output, "Directory %s contains %d rows, but expected 100, "
		"remove the directory and try again\n", dir, mult);
	return;
    }

    mult /= 100;
    if (mult > 0) {
	int nh1, nh2;
	FastBitQueryHandle h1, h2;
	for (i = 0; i < 5; ++ i) {
	    h1 = fastbit_build_query(0, dir, conditions[i]);
	    nh1 = fastbit_get_result_rows(h1);
	    if (nh1 != mult * counts[i]) {
		++ nerrors;
		fprintf(output, "%s: query \"%s\" on %d built-in records found "
			"%d hits, but %d were expected\n", nm, conditions[i],
			(int)(mult*100), nh1, (int)(mult*counts[i]));
	    }
	    fastbit_destroy_query(h1);
	}

	/* try the empty where clause */
	h2 = fastbit_build_query(0, dir, 0);
	nh2 = fastbit_get_result_rows(h2);
	if (nh2 != 100 * mult) {
	    ++ nerrors;
	    fprintf(output, "%s: query expected to return %d rows, "
		    "but got %d instead\n", nm, 100*mult, nh2);
	}
	fastbit_destroy_query(h2);
    }

    /* try to append the same data again */
    fastbit_add_values("a", "int", ivals, 100, 0);
    fastbit_add_values("b", "short", svals, 100, 0);
    fastbit_add_values("c", "float", fvals, 100, 0);
    fastbit_flush_buffer(dir);
    /* test the same queries once more */
    ++ mult;
    for (i = 0; i < 5; ++ i) {
	FastBitQueryHandle h = fastbit_build_query(0, dir, conditions[i]);
	int nhits = fastbit_get_result_rows(h);
	if (nhits != mult * counts[i]) {
	    ++ nerrors;
	    fprintf(output, "%s: query \"%s\" on %d built-in records found "
		    "%d hits, but %d were expected\n", nm, conditions[i],
		    (int)(mult*100), nhits, (int)(mult*counts[i]));
	}
	fastbit_destroy_query(h);
    }
    fprintf(output, "%s: built-in tests finished with nerrors = %d\n",
	    nm, nerrors);
} /* builtin */