druid-io / pydruid

A Python connector for Druid
Other
506 stars 194 forks source link

Columns are casted to wrong Data type #157

Open Makesh-Gmak opened 5 years ago

Makesh-Gmak commented 5 years ago

Currently I have a SQLLachemy model like below with column_property(). But the PyDruid compils the query where BIGINT is converted to LONG, which leads to the error.

class wikipedia_model(Base):
    __tablename__ = 'wikipedia'

    page = Column(VARCHAR, primary_key=True)
    delta = Column(BIGINT)
    delta_round_off = column_property(cast(delta / 10, BIGINT) * 10) 

query = db_session.query(wikipedia_model).filter(wikipedia_model.page.like('%A')).limit(2) 
result = query.all()

Error:

sqlalchemy.exc.ProgrammingError: (pydruid.db.exceptions.ProgrammingError) Unknown exception (org.apache.calcite.tools.ValidationException): 
java.lang.UnsupportedOperationException: class org.apache.calcite.sql.SqlIdentifier: LONG

[SQL: u'SELECT CAST("wikipedia"."delta" / %(param_1)s AS LONG) * %(param_2)s AS "anon_1", "wikipedia"."page" AS "wikipedia_page", "wikipedia"."delta" AS "wikipedia_delta" \nFROM "wikipedia" \nWHERE "wikipedia"."page" LIKE %(page_1)s\n LIMIT %(param_3)s'] [parameters: {u'page_1': '%A', u'param_1': 10, u'param_3': 2, u'param_2': 10}]

I observed the druid compiler is configured to return LONGfor BIGINTat https://github.com/druid-io/pydruid/blob/master/pydruid/db/sqlalchemy.py#L58

More info : https://github.com/apache/incubator-druid/blob/master/docs/content/querying/sql.md#data-types-and-casts

MSadeghzadehG commented 4 years ago

Is it still open?