Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: lack of distinct options to process data #215

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

yrashk
Copy link
Contributor

@yrashk yrashk commented Jun 30, 2023

Your choices are either SQL with all its expressive power, potential parallelization, optimizations, etc. or a few imperative or functional languages, starting from PL/pgSQL.

Other approaches are not quite available.

Solution: provide a proof-of-concept integration of Prolog

It uses SWI-Prolog as the implementation of choice. It's not the fastest one, or ISO-compliant. But it does integrate relatively well and packs a lot of features. It's actively developed and has a good community. Being a relative newcomer to Prolog, I can't tell if this is a perfect decision long-term, but it does make sense now.

Why Prolog?

As I was working on Postgres package management, I ended up choosing Prolog as the language for describing constraints and rules for building packages in varieties of configurations and settings. And since I was integrating it with C codebase, I thought: "hey, maybe this is a good candidate for a language in Postgres!". It certainly allows to process data from the database in a different, unique, and valuable way.

This current implementation is incomplete but shows the general idea and even implements a sandboxed (trusted) version of the language using library(sandbox).

@yrashk yrashk marked this pull request as draft June 30, 2023 13:03
@ghost
Copy link

ghost commented Jun 30, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

Your choices are either SQL with all its expressive power,
potential parallelization, optimizations, etc. or a few imperative or
functional languages, starting from PL/pgSQL.

Other approaches are not quite available.

Solution: provide a proof-of-concept integration of Prolog

It uses SWI-Prolog as the implementation of choice. It's not the fastest
one, or ISO-compliant. But it does integrate relatively well and packs a
lot of features. It's actively developed and has a good community.
Being a relative newcomer to Prolog, I can't tell if this is a perfect
decision long-term, but it does make sense now.

Why Prolog?

As I was working on Postgres package management, I ended up choosing
Prolog as the language for describing constraints and rules for building
packages in varieties of configurations and settings. And since I was
integrating it with C codebase, I thought: "hey, maybe this is a good
candidate for a language in Postgres!". It certainly allows to process
data from the database in a different, unique, and valuable way.

This current implementation is incomplete but shows the general idea and
even implements a sandboxed (trusted) version of the language using
`library(sandbox)`.
Solution: ensure we use older API on Postgres 13
This is limiting their usefulness.

Solution: implement basic support for these

Note that it currently only supports "materialize" method mostly for
simplicity's sake. It's possible to do the function call convention by
saving the engine in the context. Can be done at a later point.
It's not describing and everything and describes something it doesn't do
(printing).

Solution: adjust the commentary to reflect the reality
Mostly because we don't check the results of some functions.

Solution: make them all required to pass successfully

I wrote a `PL_require(cond)` macro for this.
Not sure if they are reported correctly if set is not expected.

Solution: write a test
It does something "funny" when it encounters such types: it creates an
`unsupported` atom. This is not a good behaviour.

Solution: raise an exception instead
Solution: ensure PL_require is called by its correct name

It was originally called PL_iff but was then renamed using IDE and it
didn't rename the #ifndef-outed name.
This is because initialization is delayed until first invocation.

Solution: initialize with the extension in _PG_init
This is less than ideal as the output of it is less predictable.

Solution: just throw an error
This will make it harder to discover it.

Solution: list it
Solution: fix the target of the comment
Solution: switch to the development branch

They are generally quite stable and pack a lot of new features that can
be useful.
Solution: update to a newer one
In particular, it uses `success` field that has been removed.

Solution: use `error` alone
Solution: switch it to migrations
When building in isolation, it fails to load omni_prolog_stub:

```
open_shared_object/3: dlopen(omni_prolog_stub.so, 0x0001): tried: 'omni_prolog_stub.so' (no such file)
```

Solution: ensure the target that requires it depends on it
Solution: upgrade to 9.1.21
The error reporting suggests `$omni_load_code/2` could not be found.

Solution: ensure we're not deallocating the path to the library
when handing it off to SWI Prolog's initializer.
Solution: ensure we allocate the results in the correct context

Results were previously allocated in (primarily) "SPI Proc" context
which was deleted before the return from the language handler.
Solution: start writing tests

Currently, dynamic predicates are shared. Static aren't.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant