Example #1
0
JNIEXPORT jintArray JNICALL
Java_gov_lbl_fastbit_FastBit_get_1qualified_1ints
(JNIEnv * env, jobject jo, jobject jhandle, jstring jcol) {
    jboolean        iscopy;
    const char     *ccol;
    jintArray       ret;
    const int32_t  *carr;
    jint            nrows;
    FastBitQueryHandle chandle = (FastBitQueryHandle)
	((*env)->GetDirectBufferAddress(env, jhandle));
    if (jhandle == NULL || jcol == NULL)
	return (jintArray) NULL;

    nrows = fastbit_get_result_rows(chandle);
    if (nrows <= 0) {
	ret = (*env)->NewIntArray(env, 0);
	return ret;
    }

    ccol = (*env)->GetStringUTFChars(env, jcol, &iscopy);
    carr = fastbit_get_qualified_ints(chandle, ccol);
    if (carr != 0) {
	ret = (*env)->NewIntArray(env, nrows);
	if (ret != NULL) {
	    (*env)->SetIntArrayRegion(env, ret, 0, nrows, carr);
	}
    } else {
	ret = NULL;
    }

    (*env)->ReleaseStringUTFChars(env, jcol, ccol);
    return ret;
} /* Java_gov_lbl_fastbit_FastBit_get_1qualified_1ints */
Example #2
0
int main(int argc, char **argv) {
    int ierr, nhits, vselect;
    const char *conffile;
    const char *logfile;
    FILE* output;
    FastBitQueryHandle qh;
    FastBitResultSetHandle rh;

    ierr = 0;
    vselect = 1;
    logfile = 0;
    conffile = 0;
#if defined(DEBUG) || defined(_DEBUG)
#if DEBUG + 0 > 10 || _DEBUG + 0 > 10
    ierr = INT_MAX;
#elif DEBUG + 0 > 0
    ierr += 7 * DEBUG;
#elif _DEBUG + 0 > 0
    ierr += 5 * _DEBUG;
#else
    ierr += 3;
#endif
#endif
    /* process arguments started with - */
    while (vselect < argc && argv[vselect][0] == '-') {
	if (argv[vselect][1] == 'c' || argv[vselect][1] == 'C') {
	    if (vselect+1 < argc) {
		conffile = argv[vselect+1];
		vselect += 2;
	    }
	    else {
		vselect += 1;
	    }
	}
	else if (argv[vselect][1] == 'h' || argv[vselect][1] == 'H') {
	    usage(*argv);
	    vselect += 1;
	}
#if defined(TCAPI_USE_LOGFILE)
	else if (argv[vselect][1] == 'l' || argv[vselect][1] == 'L') {
	    if (vselect+1 < argc) {
		logfile = argv[vselect+1];
		vselect += 2;
	    }
	    else {
		vselect += 1;
	    }
	}
#endif
	else if (argv[vselect][1] == 'm' || argv[vselect][1] == 'M' ||
		 argv[vselect][1] == 'v' || argv[vselect][1] == 'V') {
	    if (vselect+1 < argc &&
		(isdigit(argv[vselect+1][0]) != 0 ||
		 (argv[vselect+1][0] == '-' &&
		  isdigit(argv[vselect+1][1]) != 0))) {
		ierr += atoi(argv[vselect+1]);
		vselect += 2;
	    }
	    else {
		ierr += 1;
		vselect += 1;
	    }
	}
	else {
	    fprintf(stderr, "%s: unknown option %s\n", *argv, argv[vselect]);
	    ++ vselect;
	}
    }

    fastbit_init((const char*)conffile);
    fastbit_set_verbose_level(ierr);
    fastbit_set_logfile(logfile);
#if defined(TCAPI_USE_LOGFILE)
    output = fastbit_get_logfilepointer();
    printf("%s: output=0x%8.8x, stdout=0x%8.8x\n", *argv, output, stdout);
#else
    output = stdout;
#endif
    if (argc <= vselect) {
	builtin(*argv, output);
	return -1;
    }

    if (argc == vselect+1) /* buld indexes */
	return fastbit_build_indexes(argv[vselect], (const char*)0);

    qh = fastbit_build_query(0, argv[vselect], argv[vselect+1]);
    if (qh == 0) {
	fprintf(output, "%s failed to process query \"%s\" on data in %s\n",
		argv[0], argv[vselect+1], argv[vselect]);
	fastbit_cleanup();
	return -2;
    }

    nhits = fastbit_get_result_rows(qh);
    fprintf(output, "%s: applying \"%s\" on data in %s produced %d hit%s\n",
	    argv[0], argv[vselect+1], argv[vselect], nhits,
	    (nhits>1 ? "s" : ""));
    if (nhits <= 0)
	return 0;

    /* print the selected values specified in the select clause.  Since the
       select clause was nil in the call to fastbit_build_query, there
       would be nothing to print here! */
    rh = fastbit_build_result_set(qh);
    if (rh != 0) {
	int ncols = fastbit_get_result_columns(qh);
	fprintf(output, "%s\n", fastbit_get_select_clause(qh));
	while (fastbit_result_set_next(rh) == 0) {
	    int i;
	    fprintf(output, "%s", fastbit_result_set_getString(rh, 0));
	    for (i = 1; i < ncols; ++ i)
		fprintf(output, ", %s", fastbit_result_set_getString(rh, i));
	    fprintf(output, "\n");
	}
	fastbit_destroy_result_set(rh);
    }
    fflush(output);

    vselect += 2;
    /* print attributes explicitly specified on the command line */
    if (argc > vselect) {
	int i, j;
	for (i = vselect; i < argc; i += 2) {
	    char t = (i+1<argc ? argv[i+1][0] : 'i');
	    switch (t) {
	    default:
	    case 'i':
	    case 'I': {
		const int32_t *tmp = fastbit_get_qualified_ints(qh, argv[i]);
		if (tmp != 0) {
		    fprintf(output, "%s[%d]=", argv[i], nhits);
		    for (j = 0; j < nhits; ++ j)
			fprintf(output, "%d ", (int)tmp[j]);
		    fprintf(output, "\n");
		}
		else {
		    fprintf(output, "%s: failed to retrieve values for "
			    "column %s (requested type %c)\n",
			    argv[0], argv[i], t);
		}
		break;}
	    case 'u':
	    case 'U': {
		const uint32_t *tmp = fastbit_get_qualified_uints(qh, argv[i]);
		if (tmp != 0) {
		    fprintf(output, "%s[%d]=", argv[i], nhits);
		    for (j = 0; j < nhits; ++ j)
			fprintf(output, "%u ", (unsigned)tmp[j]);
		    fprintf(output, "\n");
		}
		else {
		    fprintf(output, "%s: failed to retrieve value for "
			    "column %s (requested type %c)\n",
			    argv[0], argv[i], t);
		}
		break;}
	    case 'l':
	    case 'L': {
		const int64_t *tmp = fastbit_get_qualified_longs(qh, argv[i]);
		if (tmp != 0) {
		    fprintf(output, "%s[%d]=", argv[i], nhits);
		    for (j = 0; j < nhits; ++ j)
			fprintf(output, "%lld ", (long long)tmp[j]);
		    fprintf(output, "\n");
		}
		else {
		    fprintf(output, "%s: failed to retrieve value for "
			    "column %s (requested type %c)\n",
			    argv[0], argv[i], t);
		}
		break;}
	    case 'r':
	    case 'R':
	    case 'f':
	    case 'F': {
		const float *tmp = fastbit_get_qualified_floats(qh, argv[i]);
		if (tmp != 0) {
		    fprintf(output, "%s[%d]=", argv[i], nhits);
		    for (j = 0; j < nhits; ++ j)
			fprintf(output, "%g ", tmp[j]);
		    fprintf(output, "\n");
		}
		else {
		    fprintf(output, "%s: failed to retrieve value for "
			    "column %s (requested type %c)\n",
			    argv[0], argv[i], t);
		}
		break;}
	    case 'd':
	    case 'D': {
		const double *tmp = fastbit_get_qualified_doubles(qh, argv[i]);
		if (tmp != 0) {
		    fprintf(output, "%s[%d]=", argv[i], nhits);
		    for (j = 0; j < nhits; ++ j)
			fprintf(output, "%lG ", tmp[j]);
		    fprintf(output, "\n");
		}
		else {
		    fprintf(output, "%s: failed to retrieve value for "
			    "column %s (requested type %c)\n",
			    argv[0], argv[i], t);
		}
		break;}
	    case 's':
	    case 'S':
	    case 't':
	    case 'T': {
		const char **tmp = fastbit_get_qualified_strings(qh, argv[i]);
		if (tmp != 0) {
		    fprintf(output, "%s[%d]=", argv[i], nhits);
		    for (j = 0; j < nhits; ++ j)
			fprintf(output, "\"%s\" ", tmp[j]);
		    fprintf(output, "\n");
		}
		else {
		    fprintf(output, "%s: failed to retrieve value for "
			    "column %s (requested type %c)\n",
			    argv[0], argv[i], t);
		}
		break;}
	    }
	}
    }

    ierr = fastbit_destroy_query(qh);
    fastbit_cleanup();
    return ierr;
} /* main */