Search code examples
pythondjangohivepyodbcdjango-pyodbc-azure

Django Hive connectivity


DATABASES = {
    'default': {
        'ENGINE': 'sql_server.pyodbc',
        'NAME': 'sampletest',
        'OPTIONS': {
           'driver': '/opt/cloudera/hiveodbc/lib/64/libclouderahiveodbc64.so',
           'dsn': 'Hive1',
           'host_is_server': True,
        },
    }
}

Above is the Django settings for the connectivity with the Hive database; Here I am facing an issue when I run the project which is given below:

django.db.utils.Error: ('HY000', u"[HY000] [Cloudera][Hardy] (80) Syntax or semantic analysis error thrown in server while executing query. Error message from server: Error while compiling statement: FAILED: ParseException line 1:7 character '@' not supported here\nline 1:8 character '@' not supported here (80) (SQLExecDirectW)")

The query where it is occurring is actually a standard query

"SELECT @@TRANCOUNT"

which is triggered by Django while connectivity

Please suggest solution. Thanks in Advance.


Solution

  • AFAIK, Django is not compatible with Hive. The database engine you're using, django-pyodbc-azure, is for SQL Server only. Django supports PostgreSQL, MySQL, SQLite and Oracle out of the box. SQL Server is supported through third party engines such as django-pyodbc-azure. I don't know of any other currently supported engines (MongoDB used to have an engine, but hasn't been maintained).

    That said, you can probably use one of the above engines for Django's default setting and ORM interactions, and use pyodbc directly to connect to Hive at the Python level; I do something similar, where I use PostgreSQL for Django, and an unsupported database for data. Good luck!