django-clickhouse-backend icon indicating copy to clipboard operation
django-clickhouse-backend copied to clipboard

[BUG] Unknown data type JSON

Open aida-mirabadi opened this issue 6 months ago • 5 comments

Description This package raises a data type error for JSONFeild, although this type is supported and available in your sample model inside the README file.

Sample code

# models.py
class Event(models.ClickhouseModel):
    content = models.JSONField(default=dict)

# migrations/0001_initial.py
("content", clickhouse_backend.models.JSONField(default=dict)),
           (
                "timestamp",
                clickhouse_backend.models.DateTime64Field(
                    default=django.utils.timezone.now
                ),
           ),

# command
$ python manage.py migrate --database clickhouse

Error

Exception: Unknown data type family: JSON. Stack trace:

0. DB::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, int, bool) @ 0xaebee1a in /usr/bin/clickhouse
1. DB::DataTypeFactory::findCreatorByName(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const @ 0x14378ba4 in /usr/bin/clickhouse
2. DB::DataTypeFactory::get(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::IAST> const&) const @ 0x14377bfa in /usr/bin/clickhouse
3. DB::InterpreterCreateQuery::getColumnsDescription(DB::ASTExpressionList const&, std::__1::shared_ptr<DB::Context const>, bool) @ 0x14bb5ae5 in /usr/bin/clickhouse
4. DB::InterpreterCreateQuery::getTablePropertiesAndNormalizeCreateQuery(DB::ASTCreateQuery&) const @ 0x14bb7bf7 in /usr/bin/clickhouse
5. DB::InterpreterCreateQuery::createTable(DB::ASTCreateQuery&) @ 0x14bbef16 in /usr/bin/clickhouse
6. DB::InterpreterCreateQuery::execute() @ 0x14bc6f6b in /usr/bin/clickhouse
7. ? @ 0x14ee9bd9 in /usr/bin/clickhouse
8. DB::executeQuery(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::shared_ptr<DB::Context>, bool, DB::QueryProcessingStage::Enum) @ 0x14ee7755 in /usr/bin/clickhouse
9. DB::TCPHandler::runImpl() @ 0x159f059a in /usr/bin/clickhouse
10. DB::TCPHandler::run() @ 0x15a04579 in /usr/bin/clickhouse
11. Poco::Net::TCPServerConnection::start() @ 0x18668b6f in /usr/bin/clickhouse
12. Poco::Net::TCPServerDispatcher::run() @ 0x1866afc1 in /usr/bin/clickhouse
13. Poco::PooledThread::run() @ 0x1881b6a9 in /usr/bin/clickhouse
14. Poco::ThreadImpl::runnableEntry(void*) @ 0x18818da0 in /usr/bin/clickhouse
15. ? @ 0x7fee4afed609 in ?
16. __clone @ 0x7fee4af14293 in ?

Expected behavior As you have supported JSONField inside the models/fields/json.py, I assume it would be no problem to create a column with JSON datatype. Of course, as far as I know, Clickhouse doesn't support JSON by default and it's necessary to save it as a string and then convert it to JSON in result.

Versions

  • ClickHouse 22.2.3.1
  • Python 3.12
  • Clickhouse-driver 0.2.8
  • Django 5.0.7
  • Django clickhouse backend 1.3.0

aida-mirabadi avatar Aug 12 '24 09:08 aida-mirabadi