MonetDB: embedded-java - Fix miltiple column type cast

Dimitar Nedev dimitar.nedev at monetdbsolutions.com
Wed Oct 21 15:32:25 CEST 2015


I *need* to map it to a (primitive) type in Java. I can keep creating my own types but nobody's gonna know what to do with them. The expected behaviour should be the same as with JDBC.

Best,
Dimitar

> On 2015-Oct-21, at 15:27, Sjoerd Mullender <sjoerd at acm.org> wrote:
> 
> Columns do not contain values of type short, long, float or double.
> They might contain values of type sht, lng, flt and dbl.  You should not
> use type long in your code unless an external API requires it.  Long is
> not portable since it can be either 32 or 64 bits, even on a 64 bit
> architecture.
> A good rule is, if you created a BAT with a TYPE_xxx, use xxx as the
> name of the C type.
> 
> On 21/10/15 14:55, Dimitar Nedev wrote:
>> Changeset: bf487cfa489a for MonetDB
>> URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=bf487cfa489a
>> Modified Files:
>> 	java/embedded/org_monetdb_embedded_result_EmbeddedQueryResult.c
>> Branch: embedded-java
>> Log Message:
>> 
>> Fix miltiple column type cast
>> 
>> 
>> diffs (90 lines):
>> 
>> diff --git a/java/embedded/org_monetdb_embedded_result_EmbeddedQueryResult.c b/java/embedded/org_monetdb_embedded_result_EmbeddedQueryResult.c
>> --- a/java/embedded/org_monetdb_embedded_result_EmbeddedQueryResult.c
>> +++ b/java/embedded/org_monetdb_embedded_result_EmbeddedQueryResult.c
>> @@ -29,18 +29,18 @@ static jobject getBooleanColumn(JNIEnv *
>> 	jboolean nul_tmp[size];
>> 	if (b->T->nonil && !b->T->nil) {
>> 		for (i = 0; i < size; i++) {
>> -			val_tmp[i] = (jboolean) ((jboolean*) Tloc(b, BUNfirst(b)))[i];
>> +			val_tmp[i] = (bit) ((bit*) Tloc(b, BUNfirst(b)))[i];
>> 			nul_tmp[i] = false;
>> 		}
>> 	}
>> 	else {
>> 		for (i = 0; i < size; i++) {
>> -			int v = ((jboolean*) Tloc(b, BUNfirst(b)))[i];
>> +			int v = ((bit*) Tloc(b, BUNfirst(b)))[i];
>> 			if (v == bit_nil) {
>> 				val_tmp[i] = 0;
>> 				nul_tmp[i] = true;
>> 			} else {
>> -				val_tmp[i] = (jboolean)v;
>> +				val_tmp[i] = (bit)v;
>> 				nul_tmp[i] = false;
>> 			}
>> 		}
>> @@ -78,7 +78,7 @@ static jobject getByteColumn(JNIEnv *env
>> 	}
>> 	else {
>> 		for (i = 0; i < size; i++) {
>> -			int v = ((bte*) Tloc(b, BUNfirst(b)))[i];
>> +			bte v = ((bte*) Tloc(b, BUNfirst(b)))[i];
>> 			if (v == bte_nil) {
>> 				val_tmp[i] = 0;
>> 				nul_tmp[i] = true;
>> @@ -121,7 +121,7 @@ static jobject getShortColumn(JNIEnv *en
>> 	}
>> 	else {
>> 		for (i = 0; i < size; i++) {
>> -			int v = ((short*) Tloc(b, BUNfirst(b)))[i];
>> +			short v = ((short*) Tloc(b, BUNfirst(b)))[i];
>> 			if (v == sht_nil) {
>> 				val_tmp[i] = 0;
>> 				nul_tmp[i] = true;
>> @@ -207,7 +207,7 @@ static jobject getLongColumn(JNIEnv *env
>> 	}
>> 	else {
>> 		for (i = 0; i < size; i++) {
>> -			int v = ((long*) Tloc(b, BUNfirst(b)))[i];
>> +			long v = ((long*) Tloc(b, BUNfirst(b)))[i];
>> 			if (v == lng_nil) {
>> 				val_tmp[i] = 0;
>> 				nul_tmp[i] = true;
>> @@ -250,7 +250,7 @@ static jobject getFloatColumn(JNIEnv *en
>> 	}
>> 	else {
>> 		for (i = 0; i < size; i++) {
>> -			int v = ((float*) Tloc(b, BUNfirst(b)))[i];
>> +			float v = ((float*) Tloc(b, BUNfirst(b)))[i];
>> 			if (v == flt_nil) {
>> 				val_tmp[i] = 0.0;
>> 				nul_tmp[i] = true;
>> @@ -293,7 +293,7 @@ static jobject getDoubleColumn(JNIEnv *e
>> 	}
>> 	else {
>> 		for (i = 0; i < size; i++) {
>> -			int v = ((double*) Tloc(b, BUNfirst(b)))[i];
>> +			double v = ((double*) Tloc(b, BUNfirst(b)))[i];
>> 			if (v == dbl_nil) {
>> 				val_tmp[i] = 0.0;
>> 				nul_tmp[i] = true;
>> @@ -346,7 +346,6 @@ static jobject getStringColumn(JNIEnv *e
>> 			j++;
>> 		}
>> 	}
>> -
>> 	// Create the column object
>> 	// from Java StringColumn(String[] values, int columnSize, boolean[] nullIndex)
>> 	column = (*env)->NewObject(env, columnClass, columnConstructor, values, size, nulls);
>> @@ -380,11 +379,9 @@ JNIEXPORT jobject JNICALL Java_org_monet
>> 		return getLongColumn(env, b);
>> 		break;
>> 	case TYPE_flt:
>> -		printf("float1\n");
>> 		return getFloatColumn(env, b);
>> 		break;
>> 	case TYPE_dbl:
>> -		printf("double1\n");
>> 		return getDoubleColumn(env, b);
>> 		break;
>> 	case TYPE_str:
>> _______________________________________________
>> checkin-list mailing list
>> checkin-list at monetdb.org
>> https://www.monetdb.org/mailman/listinfo/checkin-list
>> 
> 
> 
> --
> Sjoerd Mullender
> 
> _______________________________________________
> developers-list mailing list
> developers-list at monetdb.org
> https://www.monetdb.org/mailman/listinfo/developers-list

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 842 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://www.monetdb.org/pipermail/developers-list/attachments/20151021/ff4d8abd/attachment.sig>


More information about the developers-list mailing list