Re: [sqlite] User Defined Types implementations ...

2019-05-23 Thread Keith Medcalf

On Thursday, 23 May, 2019 14:39, Jens Alfke  wrote:

>> On May 22, 2019, at 8:16 PM, Keith Medcalf 
>wrote:

>> Basically, User Defined Types (UDT) were implemented in a fashion
>analgous to a C++ class (remember that at this time C++ was just a
>pre-processor for C and a C++ class was nothing more than a struct
>and mangled function names to operate on the class).

>…and a vtable to provide polymorphic dispatch of virtual methods,
>which is required for OOP.

>> Basically, when you declared something as a UDT you were giving a
>"blob" a type-domain.  Whenever you tried to do something with a UDT
>a "mangled function name" was generated that took that blob as the
>first argument

>Was DB2 using early or late binding of types to blobs? That is, was
>the type of a blob declared as part of the table column, or were
>individual blob values tagged with their own types? This makes a huge
>difference. In the former (early) case the UDTs are just syntactic
>sugar, while with late-binding they really do act like objects. Late-
>binding is also required if user-defined functions are to be allowed
>to return UDTs.

The initial version was entirely early binding via column declarations of the 
type, so they were syntactic sugar, not real polymorphic objects (in the sense 
of how real objects and types work).  Now I believe you can implement UDT's as 
true objects (but still early bound via the column declaration) as C++ or Java 
or whatever classes.  It was a long time ago and I haven't touched DB2 for a 
long time ... I only remember because at the time I was doing Level 2.5 support 
for the IBM CSet++ Compiler package at TOROLAB6 and we had lots of interaction 
with the DB2 developers who were just up the road

>> you merely implemented a bunch of functions with the appropriate
>names that DB2 would use whenever you referred to that UDT type,
>rather than using the builtin functions (this is similar to the way
>languages like Python implement classes).

>Not really; in Python (and Ruby, and Objective-C, and Smalltalk, and
>sort-of JavaScript…) a class is a dictionary that maps method names
>to anonymous functions. The functions themselves don't have names.
>(Sorry to be pedantic, but I'm a bit of a language geek.)

No need, but you are correct.  I believe that in fact the implementation that 
was released was based on proper dictionary based method dispatch and that all 
the other "standard internal types" ended up being implemented in the same 
fashion (just with standardized builtin models).  That is, even a standard 
"varchar(20)" or "integer" or "decimal(10,4)" was nothing more than a binary 
blob in the database that had a builtin method dictionary attached via the 
declaration.  The nice part was that the system implementation was extensible 
by being able to provide your own binding dictionaries, and that everything, 
whether an "internal" or UDT was implemented using the same methods.  I don't 
know if the types were ever actually polymorphic or supported multiple 
inheritance or not.

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.




___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] User Defined Types implementations ...

2019-05-23 Thread Jens Alfke


> On May 22, 2019, at 8:16 PM, Keith Medcalf  wrote:
> 
> Basically, User Defined Types (UDT) were implemented in a fashion analgous to 
> a C++ class (remember that at this time C++ was just a pre-processor for C 
> and a C++ class was nothing more than a struct and mangled function names to 
> operate on the class). 

…and a vtable to provide polymorphic dispatch of virtual methods, which is 
required for OOP.

> Basically, when you declared something as a UDT you were giving a "blob" a 
> type-domain.  Whenever you tried to do something with a UDT a "mangled 
> function name" was generated that took that blob as the first argument

Was DB2 using early or late binding of types to blobs? That is, was the type of 
a blob declared as part of the table column, or were individual blob values 
tagged with their own types? This makes a huge difference. In the former 
(early) case the UDTs are just syntactic sugar, while with late-binding they 
really do act like objects. Late-binding is also required if user-defined 
functions are to be allowed to return UDTs.

> you merely implemented a bunch of functions with the appropriate names that 
> DB2 would use whenever you referred to that UDT type, rather than using the 
> builtin functions (this is similar to the way languages like Python implement 
> classes).

Not really; in Python (and Ruby, and Objective-C, and Smalltalk, and sort-of 
JavaScript…) a class is a dictionary that maps method names to anonymous 
functions. The functions themselves don't have names. (Sorry to be pedantic, 
but I'm a bit of a language geek.)

—Jens
___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] User Defined Types implementations ...

2019-05-23 Thread James K. Lowden
On Wed, 22 May 2019 21:16:04 -0600
"Keith Medcalf"  wrote:

> Basically, when you declared something as a UDT you were giving a
> "blob" a type-domain.  Whenever you tried to do something with a UDT
> a "mangled function name" was generated that took that blob as the
> first argument and you merely implemented a bunch of functions with
> the appropriate names that DB2 would use whenever you referred to
> that UDT type, rather than using the builtin functions (this is
> similar to the way languages like Python implement classes).

I see.  First, declare a type U.  Then define a function, say, 

U max( U, U ) .

Now, if we have a table 

T( U u )

we can 

SELECT max(u) from T

to invoke our function instead of the built-in max().  

What about operators, then, as long as we're talking C++?  

U operator<(U u) ?

If you could define equivalence and less-than, you can join on, sort
by, or get the maximium.  In fact (speaking of Python), you get those
for free if there's an implicit conversion to string.  

--jkl

___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] User Defined Types implementations ...

2019-05-22 Thread Keith Medcalf
On Wednesday, 22 May, 2019 16:56, James K. Lowden  
wrote:

>On Wed, 22 May 2019 14:20:11 -0600
>"Keith Medcalf"  wrote:

>>  (such as was added to DB2 back in the late 80's early 90's, and
>> which I do not think anyone else has implemented as nicely anywhere
>> else)

>That's an interesting aside.  It would make an interesting OT thread,
>if you're inclined to start it.  ;-)

>I've always thought user-defined types were unnecessary except as a
>convenience.  There are few new primitive types; most user-defined
>types I can think of are "structures" -- sets of columns -- that one
>might like to name and constrain as a new type that may appear in
>many tables.  About the only primitive type I can imagine are
>mathematical: complex numbers or exact numeric representations.

Well, User Defined Types as they were added to DB2 were a rather interesting 
way of doing the addition.  Remember these were added in the late 80's early 
90's when DB2 was just the a simple non-extensible RDBMS and not the thing that 
it is now.

Basically, User Defined Types (UDT) were implemented in a fashion analgous to a 
C++ class (remember that at this time C++ was just a pre-processor for C and a 
C++ class was nothing more than a struct and mangled function names to operate 
on the class).  DB2 UDTs were implemented on top of blobs.  Basically, when you 
declared something as a UDT you were giving a "blob" a type-domain.  Whenever 
you tried to do something with a UDT a "mangled function name" was generated 
that took that blob as the first argument and you merely implemented a bunch of 
functions with the appropriate names that DB2 would use whenever you referred 
to that UDT type, rather than using the builtin functions (this is similar to 
the way languages like Python implement classes).

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.






___
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users