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

no such function: MagicalEntangle #361

Open
mikko-ahonen opened this issue Aug 1, 2024 · 4 comments
Open

no such function: MagicalEntangle #361

mikko-ahonen opened this issue Aug 1, 2024 · 4 comments

Comments

@mikko-ahonen
Copy link

mikko-ahonen commented Aug 1, 2024

I am having an issue with sqlite database. I just installed fresh logica and sqlite3 (pip install logica, apt install sqlite3) on Debian.

root@80dcb49fb4fc:/src# cat foo.l
@Engine("sqlite");

Foo(id:"E1", name:"Foo 1");
Foo(id:"E2", name:"Foo 2");

Bar(id:id, name:name) :- Foo(id:"E1", name:);

CountNotE1(count? += 1) distinct :- Foo(id:), ~Bar(id:);
root@80dcb49fb4fc:/src# python -m logica foo.l print CountNotE1 > foo.sql
root@80dcb49fb4fc:/src# cat foo.sql
WITH t_0_Foo AS (SELECT * FROM (
  
    SELECT
      'E1' AS id,
      'Foo 1' AS name
   UNION ALL
  
    SELECT
      'E2' AS id,
      'Foo 2' AS name
  
) AS UNUSED_TABLE_NAME  )
SELECT
  SUM(1) AS count
FROM
  t_0_Foo AS Foo
WHERE
  ((SELECT
    MIN(MagicalEntangle(1, x_3.value)) AS logica_value
  FROM
    t_0_Foo AS t_1_Foo, JSON_EACH(JSON_ARRAY(0)) as x_3
  WHERE
    (t_1_Foo.id = 'E1')) IS NULL);
root@80dcb49fb4fc:/src# sqlite3 ':memory:' '.read foo.sql'
Error: near line 1: no such function: MagicalEntangle
root@80dcb49fb4fc:/src# 
@EvgSkv
Copy link
Owner

EvgSkv commented Aug 6, 2024

Hello @mikko-ahonen !

Thank you for clear instructions to reproduce the error!

Yes, this is exected. Raw SQLite is generally missing some functions that advanced Logica functions need to be implemented, so Logica is enriching SQLite with more functions from Python. This includes MagicalEntangle function
which is used to disambiguate scope in aggregating expressions. You are using negation, which is implemented via aggregating expression and thus getting this error.

You can run only very simple programs via sqlite3 binary.

It is supposed that you'd run Logica program directly with logica like so:

$ python3 -m logica foo.l run CountNotE1
+-------+
| count |
+-------+
| 1     |
+-------+

Btw, in the rule Bar(id:id, name:name) :- Foo(id:"E1", name:); you don't have variable id assigned. It's probably intended to be as such Bar(id:id, name:name) :- Foo(id:, name:), id = "E1";.

Is this is a workable method for you?

If not, I'd be curious to learn about your usecase and we can try to find a solution.

Thank you!
Evgeny.

@mikko-ahonen
Copy link
Author

This is not really a problem for me, as I am executing the queries from python.

But I think this could bite others starting with the product. I would expect "print" command to print out sufficient functions so that I can copy paste the code into the SQLite command line tool.

This would help the debugging.

But like said, this is not blocking me or anything.

@mikko-ahonen
Copy link
Author

Just to add, I imagine typically people who are taking the product for a spin would do exactly like I did. So they probably use print because that shows you exactly what is happening, and then you can copy-paste it to command line SQL client. Also using SQLite is probably the first option because it does not require you to set iany server up. In many places in the public docs it appears as if only BigTable is supported which was a huge blocker for me. Luckily I tried it out anyway.

@EvgSkv
Copy link
Owner

EvgSkv commented Aug 8, 2024

Yeah, that's a good point. I'll be clean up docs asap. Thank you!

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

No branches or pull requests

2 participants