EvgSkv / logica

Logica is a logic programming language that compiles to SQL. It runs on DuckDB, Google BigQuery, PostgreSQL and SQLite.
https://logica.dev
Apache License 2.0
1.74k stars 91 forks source link

Re-digest predicates from DB #295

Open yilinxia opened 11 months ago

yilinxia commented 11 months ago

I tried to pass one predicate to another with the following scripts on local PC

%%logica Child

@Engine("sqlite");

@AttachDatabase("mydata", "my_database.db");
@Dataset("ParentTable");

Parent(..r) :- mydata.ParentTable(..r);

Child(x):- Parent(child:x);

The Child table is supposed to be created successfully, but I encountered the error below

Running predicate: Child
--- SQL ---
SELECT
  JSON_EXTRACT(mydata_ParentTable, "$.child") AS col0
FROM
  mydata.ParentTable AS mydata_ParentTable
[ Error ] Error while executing SQL:
Execution failed on sql 'SELECT
  JSON_EXTRACT(mydata_ParentTable, "$.child") AS col0
FROM
  mydata.ParentTable AS mydata_ParentTable': no such column: mydata_ParentTable
EvgSkv commented 11 months ago

@yilinxia I've tried in my colab and it worked: https://colab.research.google.com/drive/1n8TG1THH6nr0aCyHx-GAIx4r7pVnXLcb?usp=sharing

Can you please take a look and see what's the difference?

yilinxia commented 11 months ago

@EvgSkv I compared the SQL in Colab and Jupyter
Colab

SELECT
  JSON_EXTRACT(JSON_OBJECT('child', mydata_ParentTable.child), "$.child") AS col0
FROM
  mydata.ParentTable AS mydata_ParentTable;

JupyterLab

SELECT
  JSON_EXTRACT(mydata_ParentTable, "$.child") AS col0
FROM
  mydata.ParentTable AS mydata_ParentTable

somehow they are different, although we are using the same script

EvgSkv commented 11 months ago

Maybe this was fixed after you installed logica? Can you please try upgrading to the latest version and seeing if it helps?

yilinxia commented 11 months ago

the update works! and the one i used is version: 1.3.1415926