Thread: Implementing a new Scripting Language

Implementing a new Scripting Language

From
"Igal @ Lucee.org"
Date:
Hi all,<br /><br /> We have an open source scripting engine named Lucee that is used primarily for web application --
<aclass="moz-txt-link-freetext" href="https://github.com/lucee/Lucee">https://github.com/lucee/Lucee</a> -- it is
writtenin Java and is usually run as a servlet, but can be accessed in other ways (like JSR-223).<br /><br /> You can
thinkof the language as a combination of PHP and Javascript, albeit much simpler and more intuitive IMHO.<br /><br /> I
waswondering how difficult it would be to implement a Postgres extension that will act as a wrapper around it and will
allowto write functions in that language?  <br /><br /> I am a Java developer myself and have a very limited knowledge
ofC/C++, but if someone can point me in the right direction of whatever documentation there is on the subject -- that
wouldbe great.<br /><br /> Thanks,<br /><br /><div class="moz-signature">-- <br /><p>Igal Sapir <br /> Lucee Core
Developer<br /><a href="http://lucee.org/">Lucee.org</a></div> 

Re: Implementing a new Scripting Language

From
Vladimir Sitnikov
Date:
Why do you want that at the database level?
Do you have end-to-end scenario that benefits from using Lucee?

>I was wondering how difficult it would be to implement a Postgres extension that will act as a wrapper around it and
willallow to write functions in that language?
 

Have you checked PL/Java?

Vladimir



Re: Implementing a new Scripting Language

From
"Igal @ Lucee.org"
Date:
On 1/27/2016 8:40 AM, Vladimir Sitnikov wrote:
> Why do you want that at the database level?
> Do you have end-to-end scenario that benefits from using Lucee?
Lucee is very intuitive and powerful, so it's more for ease of use than 
anything, and to attract more Lucee users to use PostgreSQL (most of 
them use SQL Server or MySQL).

If the pl/v8 was easily ported to Windows then I probably wouldn't even 
try to add Lucee, but it seems to be quite difficult to compile the 
latest versions for Windows and it looks like the project is not 
maintained (for example, it uses an older version of V8 with no known 
intention to upgrade).

If I had more experience with C++ then I'd probably try to update V8, 
but so far my attempts have not been very fruitful.
>
>> I was wondering how difficult it would be to implement a Postgres extension that will act as a wrapper around it and
willallow to write functions in that language?
 
> Have you checked PL/Java?
That seems like a good place to start, thanks.  Are there also any docs 
about the subject?


Igal



Re: Implementing a new Scripting Language

From
Vladimir Sitnikov
Date:
> If the pl/v8 was easily ported to Windows then I probably wouldn't even try to add Lucee,

That is a good question. ChakraCore has been open sourced recently. It
might be easier to build under Windows.

>That seems like a good place to start, thanks
I am not sure you would be able to bind high performance java runtime
with the backend. There are no that many JREs, and not much of them
are good at "in-backend" operation.

Thus your question boils down to 2 possibilities:
1) You execute Lucee in some JRE that runs in the backend (frankly
speaking, I doubt it is a good way to go)
2) You implement Lucee parser/executor/compiler in C and use it as
typical PostgreSQL extension

Vladimir



Re: Implementing a new Scripting Language

From
Chapman Flack
Date:
On 01/27/2016 11:46 AM, Igal @ Lucee.org wrote:

>> Have you checked PL/Java?
> That seems like a good place to start, thanks.  Are there also any docs
> about the subject?

I just did a quick search on Lucee and what I found suggests that
it compiles to JVM bytecode and runs on a JVM. If that is the
case, and it can compile methods that will have the sort of
method signatures PL/Java expects, and you can put the .class
files in a jar and load it, your job should be just about done. :)

Or, you might end up writing thin wrappers in Java, probably
nothing more.

Another possibility: Java has pluggable script engine support
(java specification request 233, see the javax.script package).
Does Lucee have an existing JSR 233 engine implementation?

PL/Java does not _currently_ have JSR233 support, but it is
definitely being thought about ... the idea being, put a Lucee
JSR233 engine jar on the classpath, define it as a new PostgreSQL
language (PL/Java will handle the interfacing), and then actually
write stuff like

DO $$echo("Hello World");$$ LANGUAGE lucee;

As I said, in current PL/Java version, JSR 233 is still
science fiction ... but it's "hard science fiction", not the
fantasy stuff.

http://tada.github.io/pljava/

-Chap



Re: Implementing a new Scripting Language

From
"Igal @ Lucee.org"
Date:
On 1/27/2016 9:58 AM, jflack wrote:
> I just did a quick search on Lucee and what I found suggests that
> it compiles to JVM bytecode and runs on a JVM. If that is the
> case, and it can compile methods that will have the sort of
> method signatures PL/Java expects, and you can put the .class
> files in a jar and load it, your job should be just about done. :)
yes, Lucee uses ASM4 to construct class files which are mostly POJOs
> Or, you might end up writing thin wrappers in Java, probably
> nothing more.
>
> Another possibility: Java has pluggable script engine support
> (java specification request 233, see the javax.script package).
> Does Lucee have an existing JSR 233 engine implementation?
the next version of Lucee (currently in Beta) does support JSR-223, 
which I actually mentioned as a viable solution in my first email in 
this thread.  That would be awesome if PL/Java would support JSR-223.

thanks,


Igal



Re: Implementing a new Scripting Language

From
"Igal @ Lucee.org"
Date:
On 1/27/2016 9:57 AM, Vladimir Sitnikov wrote:
> That is a good question. ChakraCore has been open sourced recently. It
> might be easier to build under Windows.
interesting.  but now we will need to write an extension for that, e.g. 
PL/Chakra, which brings back my original question:
are there any docs as to how to implement a new scripting language? ;)
> I am not sure you would be able to bind high performance java runtime
> with the backend. There are no that many JREs, and not much of them
> are good at "in-backend" operation.
>
> Thus your question boils down to 2 possibilities:
> 1) You execute Lucee in some JRE that runs in the backend (frankly
> speaking, I doubt it is a good way to go)
yes, that's what I had in mind.  I wasn't thinking of an embedded JRE.  
TBH I didn't think there were any of those until your email.

thanks,


Igal



Re: Implementing a new Scripting Language

From
Pavel Stehule
Date:


2016-01-27 19:21 GMT+01:00 Igal @ Lucee.org <igal@lucee.org>:
On 1/27/2016 9:57 AM, Vladimir Sitnikov wrote:
That is a good question. ChakraCore has been open sourced recently. It
might be easier to build under Windows.
interesting.  but now we will need to write an extension for that, e.g. PL/Chakra, which brings back my original question:
are there any docs as to how to implement a new scripting language? ;)

David Fetter wrote some presentation - some years ago was popular to write own PL

source code of plpgsql is good example - it pretty simple

you have to write handler

https://github.com/petere/plsh



I am not sure you would be able to bind high performance java runtime
with the backend. There are no that many JREs, and not much of them
are good at "in-backend" operation.

Thus your question boils down to 2 possibilities:
1) You execute Lucee in some JRE that runs in the backend (frankly
speaking, I doubt it is a good way to go)
yes, that's what I had in mind.  I wasn't thinking of an embedded JRE.  TBH I didn't think there were any of those until your email.

thanks,


Igal



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Re: Implementing a new Scripting Language

From
Pavel Stehule
Date:


2016-01-27 19:37 GMT+01:00 Pavel Stehule <pavel.stehule@gmail.com>:


2016-01-27 19:21 GMT+01:00 Igal @ Lucee.org <igal@lucee.org>:
On 1/27/2016 9:57 AM, Vladimir Sitnikov wrote:
That is a good question. ChakraCore has been open sourced recently. It
might be easier to build under Windows.
interesting.  but now we will need to write an extension for that, e.g. PL/Chakra, which brings back my original question:
are there any docs as to how to implement a new scripting language? ;)

David Fetter wrote some presentation - some years ago was popular to write own PL

source code of plpgsql is good example - it pretty simple

you have to write handler

https://github.com/petere/plsh





I am not sure you would be able to bind high performance java runtime
with the backend. There are no that many JREs, and not much of them
are good at "in-backend" operation.

Thus your question boils down to 2 possibilities:
1) You execute Lucee in some JRE that runs in the backend (frankly
speaking, I doubt it is a good way to go)
yes, that's what I had in mind.  I wasn't thinking of an embedded JRE.  TBH I didn't think there were any of those until your email.

thanks,


Igal



--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: Implementing a new Scripting Language

From
"Igal @ Lucee.org"
Date:
On 1/27/2016 10:41 AM, Pavel Stehule wrote:

2016-01-27 19:37 GMT+01:00 Pavel Stehule <pavel.stehule@gmail.com>:

David Fetter wrote some presentation - some years ago was popular to write own PL

source code of plpgsql is good example - it pretty simple

you have to write handler

https://github.com/petere/plsh


Thanks!  I'll take a look.


Igal

Re: Implementing a new Scripting Language

From
Chapman Flack
Date:
On 01/27/2016 01:17 PM, Igal @ Lucee.org wrote:

> the next version of Lucee (currently in Beta) does support JSR-223,
> which I actually mentioned as a viable solution in my first email in

Sorry, I jumped in late.

> this thread.  That would be awesome if PL/Java would support JSR-223.

Ok, if your 233 support is already in beta, you'll get there
before we do, but the paths should intersect eventually. :)

-Chap



Re: Implementing a new Scripting Language

From
"Igal @ Lucee.org"
Date:
On 1/27/2016 10:48 AM, Chapman Flack wrote:
>
> Ok, if your 233 support is already in beta, you'll get there
> before we do, but the paths should intersect eventually. :)

Actually, once your support for JSR-223 is implemented (it's 
two-twenty-three, not thirty ;)), we will be able to use Javascript 
through that via the Nashorn project, which seems like a better (at 
least as a cross-platform) solution than V8 or Chakra.
http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html

Now that would be very exciting IMO!


Igal





Re: Implementing a new Scripting Language

From
Chapman Flack
Date:
On 01/27/2016 02:06 PM, Igal @ Lucee.org wrote:

> two-twenty-three, not thirty ;)),

Thanks. :)  On occasions in the past I have written it
correctly ... there is evidence in the archives ....

> we will be able to use Javascript
> through that via the Nashorn project,

Yes, that's an attraction for me, as the JSR-two-twenty-three
engine for JS is now typically already included with the JRE.
(Technically, I keep reading that there is no two-twenty-three
engine that *needs* to be included and it's totally up to the
JRE packager ... but there have actually been some JavaScript
snippets in PL/Java's build process since July 2014 and no one
has yet reported they broke the build.)

-Chap



Re: Implementing a new Scripting Language

From
"Igal @ Lucee.org"
Date:
On 1/27/2016 11:47 AM, Chapman Flack wrote:
>
> Thanks. :)  On occasions in the past I have written it
> correctly ... there is evidence in the archives ....
I believe that!  I actually never remember if it's 223 or 233 and I 
always google it before I post, so in a way I cheated ;)
>
>> we will be able to use Javascript
>> through that via the Nashorn project,
> Yes, that's an attraction for me, as the JSR-two-twenty-three
> engine for JS is now typically already included with the JRE.
> (Technically, I keep reading that there is no two-twenty-three
> engine that *needs* to be included and it's totally up to the
> JRE packager ... but there have actually been some JavaScript
> snippets in PL/Java's build process since July 2014 and no one
> has yet reported they broke the build.)
This can be a major thing.  I will open a ticket in 
https://github.com/tada/pljava -- or is it already on the roadmap?



Re: Implementing a new Scripting Language

From
Chapman Flack
Date:
On 01/27/16 16:31, Igal @ Lucee.org wrote:

> This can be a major thing.  I will open a ticket in
> https://github.com/tada/pljava -- or is it already on the roadmap?

Now that you mention it, it isn't officially in a ticket. Though it's
not like I was going to forget. :)  I can guarantee it won't be in 1.5...

Speaking of tickets, I should probably make actual tickets, for after
1.5.0, out of all the items now showing in the "known issues" section
of the draft release notes. More chores....

-Chap



Re: Implementing a new Scripting Language

From
"Igal @ Lucee.org"
Date:
On 1/27/2016 7:12 PM, Chapman Flack wrote:
>
> Now that you mention it, it isn't officially in a ticket. Though it's
> not like I was going to forget. :)  I can guarantee it won't be in 1.5...
>
> Speaking of tickets, I should probably make actual tickets, for after
> 1.5.0, out of all the items now showing in the "known issues" section
> of the draft release notes. More chores....

Well, I'm not very familiar with PostgreSQL yet, but am trying to learn.

If I can help with anything with the pl/Java project I'd love to help.


Igal



Re: Implementing a new Scripting Language

From
Chapman Flack
Date:
On 01/27/16 22:26, Igal @ Lucee.org wrote:

> If I can help with anything with the pl/Java project I'd love to help.

Man, you do NOT know what you just walked into.  :D

The most imminent thing I see happening is s/1.5.0-SNAPSHOT/1.5.0-BETA1
which is not far off, so testing is always good. Maybe a good opportunity
for you to try it out, get some Lucee code running ... but by separately
compiling and installing jars at first, no JSR two-twenty-three for the
near future. See if it even does what you're hoping it'll do. Depending
on what's reported during beta, there could be delightful diagnostic
diversions too.

I guess getting some time in playing with PostgreSQL and installing
PL/Java would be the right way to start.  Discussion that's specific
to PL/Java and might not interest all of -hackers can also happen on
pljava-dev@lists.pgfoundry.org.

Cheers,
-Chap



Re: Implementing a new Scripting Language

From
"Igal @ Lucee.org"
Date:
On 1/27/2016 8:07 PM, Chapman Flack wrote:
> I guess getting some time in playing with PostgreSQL and installing
> PL/Java would be the right way to start.  Discussion that's specific
> to PL/Java and might not interest all of -hackers can also happen on
> pljava-dev@lists.pgfoundry.org.

Sounds like a good place to start.

I will continue the conversation at pljava-dev@lists.pgfoundry.org


Igal