[Pljava-dev] UDT send and receive

From: schabi at logix-tt(dot)com (Markus Schaber)
To:
Subject: [Pljava-dev] UDT send and receive
Date: 2006-09-25 19:51:31
Message-ID: 45183343.8000105@logix-tt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pljava-dev

Hi, Thomas,

[Foreword: Currently, I don't have any intent of defining the PostGIS
datatype as a full pljava-defined UDT (the C code deals fine with this).
A "simple" mapping (and thus the readSQL/writeSQL methods) are enough
for me now. I just want to ensure that my understanding of the whole
issue is correct, and that we remove all limitations that would prevent
others (or me in the future) from implementing full UDT mappings.]

Thomas Hallgren wrote:

> We're talking past each other here. The send/receive functions are the
> ones that perform the conversion. If you do it in Java, you write
> send/receive functions in Java. What you see is just the middle man,
> passing data to/from such functions. It pays no specific attention to
> representation. That is something you must do yourself in the
> corresponding methods of the SQLData implementation.

Ah, now I understand.

I erroneously assumed the same Magic like the input/output functions
mapping to parse()/toString().

You suggest to implement send and receive as normal static functions in
Java, and then use CREATE FUNCTION without the "UDT[foo] output" special
syntax.

The Problem I see here is that, for the receive function, the Datatype
"internal" is used as function parameter, which currently has no mapping
for pljava, at least according to
http://wiki.tada.se/wiki/display/pljava/Default+Type+Mapping

So I can define the send function (which returns bytea) the way you
suggest, but not the receive function.

> Well, yes. But if you want to use the data types in you'll need to have
> corresponding functions there. Are you suggesting that when reading, the
> receive in the CREATE DATATYPE should be called first, and then, another
> function should be called that would create the actual Java object from
> the result of what the receive would output?

Yes, at least that's how I understand PostgreSQL under the hoods.

Let me clarify my view of the things:

We have (at least) 4 different representations:

A) the "canonical text representation"
B) the "canonical binary representation"
C) the "internal" representation
D) Java Objects.

C) is what PostgreSQL passes around (to PostGIS C functions as well as
to the PLJava glue code), and stores on disk. The size is defined as
"internallength" in the datatype, and contained in a 4-byte VARLEN
header for variable length datatypes which have internallength set to
-1. (let's ignore TOAST and 0-terminated Strings for simplification.)

D) is what's passed around in "user functions" in pljava lands, obviously.

A) is used in psql, pg_dump, non-binary COPY, the V2 protocol and the
text mode of the V3 protocol.

B) is used in binary COPY and the binary mode of the V3 protocol.

The pljava UDT mapping converts between C and D via the readSQL() and
writeSQL() methods.

PostgreSQL uses the input and output functions defined for the type to
convert between A and C.

The send and receive functions for the datatype convert between B and C.

http://www.postgresql.org/docs/8.1/interactive/xtypes.html contains an
example with some less-sophisticated, but explicitly coded send and
receive functions.

I hope it is understandable what I try to explain.

Thanks for your patience,
Markus
--
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf. | Software Development GIS

Fight against software patents in Europe! www.ffii.org
www.nosoftwarepatents.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: <http://lists.pgfoundry.org/pipermail/pljava-dev/attachments/20060925/8b4194bd/attachment.bin>

In response to

Responses

Browse pljava-dev by date

  From Date Subject
Next Message Markus Schaber 2006-09-25 20:16:17 [Pljava-dev] JNI_CreateJavaVM
Previous Message Lyle Giese 2006-09-25 19:08:35 [Pljava-dev] JNI_CreateJavaVM