MonetDB: embedded-java - Fix miltiple column type cast

Sjoerd Mullender sjoerd at acm.org
Wed Oct 21 15:47:00 CEST 2015


On 21/10/15 15:32, Dimitar Nedev wrote:
> 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.

Be that as it may, you can still not use long.  If the C type that you
get from Java really is long, you need to use C preprocessor
conditionals to distinguish between int (4 bytes) and lng (8 bytes).
You can not cast the result of Tloc() to (long *).  Period.
You can depend on float being equal to flt, and double being equal to dbl.
You have to make some sort of mapping between the native Java types and
the MonetDB types.  But that does not involve long on the MonetDB side
of things.

> 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
> 


-- 
Sjoerd Mullender

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: OpenPGP digital signature
URL: <http://www.monetdb.org/pipermail/developers-list/attachments/20151021/b8dd337e/attachment-0001.sig>


More information about the developers-list mailing list