chdb-io / chdb

chDB is an in-process OLAP SQL Engine 🚀 powered by ClickHouse
https://clickhouse.com/chdb
Apache License 2.0
2.13k stars 75 forks source link

Session unexpected behavior on CREATE OR REPLACE TABLE #135

Closed lmangani closed 12 months ago

lmangani commented 12 months ago

Example

Let's use the following script to reproduce our issue:

test.py
import chdb
from chdb import session as chs

sess = chs.Session('.chdb_data')
sess.query("CREATE DATABASE IF NOT EXISTS a;")
sess.query("CREATE OR REPLACE TABLE a.test (id UInt64, updated_at DateTime DEFAULT now(),updated_at_date Date DEFAULT toDate(updated_at)) ENGINE = MergeTree ORDER BY id;")
sess.query("INSERT INTO a.test (id) Values (1);")

print(sess.query("SELECT * FROM a.test;"))

The inserted line is returned correctly.

# python3 test.py
1,"2023-11-19 11:58:40","2023-11-19"

When running the same script again, the following error is produced over the results:

# python3 test.py
Code: 1001. DB::Exception: std::__1::__fs::filesystem::filesystem_error: filesystem error: in rename: No such file or directory ["/root/.chdb_data/store/ef2/ef2caebe-7031-4bc2-948d-e3e596968dff/_tmp_replace_221b5146cd0d8526_6bd9.sql"] ["/tmp/clickhouse-local-4095066-1700391519-1943312659563932811/metadata_dropped/a._tmp_replace_221b5146cd0d8526_6bd9.35f960fa-0ad9-42d8-bbe1-67580f93c99b.sql"]. (STD_EXCEPTION)
1,"2023-11-19 11:58:45","2023-11-19"

The issue seems caused by the CREATE OR REPLACE TABLE query.

Note the results are actually returned after the exception, which seems to have no apparent effect on the query itself.

djouallah commented 12 months ago

still does not work for me replace view with table and it does stop working

https://colab.research.google.com/drive/1o07UEUUAxcdR9WCdYt53mVZBvqqbqzxn?usp=sharing

from chdb import session as chs
sess = chs.Session("xxxx")
sess.query("CREATE DATABASE IF NOT EXISTS db_xxx ENGINE = Atomic ; use db_xxx")
for tbl in ['nation','region','customer','supplier','lineitem','orders','partsupp','part'] :
  sess.query(f'CREATE OR REPLACE view {tbl}  as select * from file("./{sf}/{tbl}/*.parquet", Parquet)')
djouallah commented 12 months ago

never mind forgot to add ENGINE = Log