You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
expression in table columns is converted to literal column twice #617
After interacting with the Sqlalchemy issue support, #3737 - Bitbucket,
I have implemented and tested the solution to escape the double percentage getting displayed for literal_column. This solution is basically a decorated method that takes care of removing back the added percentages for type of DateTime in ColumnClause.
As @yejianye pointed out this issue also breaks 'week' and 'month' time grains on SQLite but the fix that was applied only applies to column expressions, so I think that time grains are still broken for SQLite.
There's a bunch of tangled issues being discussed here, can someone open a new issue that explains exactly what is going on? I'm pretty sure the double % is not an issue anymore.
The time grain code for SQLite uses strftime to truncate the date, but the %d is doubled up to %%d and consequently the strftime doesn't work, and so the date doesn't get truncated.
The SQL that gets generated by that query_obj is
SELECTDATE(received, -strftime('%%d', received) ||' days', '+1 day') AS __timestamp,
SUM(value) AS sum__value
FROM test_datasource
WHERE received >='2001-01-01 00:00:00.000000'AND received <='2001-12-31 00:00:00.000000'GROUP BYDATE(received, -strftime('%%d', received) ||' days', '+1 day')
ORDER BY sum__value DESC
Activity
rhp4515 commentedon Jun 15, 2016
@mistercrunch
ntantri commentedon Jul 5, 2016
I tried looking into this issue and found that there is this sqlalchemy method
literal_columnwhich uses a replace text method and is reported as a bug in sqlalchemy project: https://bitbucket.org/zzzeek/sqlalchemy/issues/3740/clean-up-doubling-of-percent-signs-base-onWill try and see the update of whether it can be directly used with help of sqlalchemy's
textmethod.ntantri commentedon Jul 12, 2016
After interacting with the Sqlalchemy issue support, #3737 - Bitbucket,
I have implemented and tested the solution to escape the double percentage getting displayed for literal_column. This solution is basically a decorated method that takes care of removing back the added percentages for type of
DateTimeinColumnClause.yejianye commentedon Sep 12, 2016
Met the same problem, hope the PR could be merged soon.
yejianye commentedon Sep 12, 2016
Also notice 'week' and 'month' time grain is broken for SQLite because of this issue as well. Both have percent sign in its sql expression.
Fix double escaping of dttm expressions (#744) (#1103)
Fix double escaping of dttm expressions (apache#744) (apache#1103)
rhunwicks commentedon Sep 18, 2017
As @yejianye pointed out this issue also breaks 'week' and 'month' time grains on SQLite but the fix that was applied only applies to column expressions, so I think that time grains are still broken for SQLite.
stonecharioteer commentedon Oct 5, 2017
@rhunwicks Time grains are still broken! Is there another bug report related to this?
rhunwicks commentedon Oct 5, 2017
@vinay87 I'm not aware of another bug report - I think this one should be reopened.
mistercrunch commentedon Oct 5, 2017
There's a bunch of tangled issues being discussed here, can someone open a new issue that explains exactly what is going on? I'm pretty sure the double
%is not an issue anymore.rhunwicks commentedon Oct 5, 2017
@mistercrunch when you run a query against a SQLite database that has a time grain of week or month, you pass a
query_objsomething like:{ 'groupby': [], 'metrics': ['sum__value'], 'granularity': 'received', 'from_dttm': datetime.datetime(2001, 1, 1), 'to_dttm': datetime.datetime(2001, 12, 31), 'filter': [], 'is_timeseries': True, 'timeseries_limit': 50, 'timeseries_limit_metric': None, 'row_limit': 5000, 'extras': { 'time_grain_sqla': 'month', }, 'order_desc': True, }The time grain code for SQLite uses
strftimeto truncate the date, but the%dis doubled up to%%dand consequently thestrftimedoesn't work, and so the date doesn't get truncated.The SQL that gets generated by that
query_objisbetodealmeida commentedon Jan 23, 2018
@mistercrunch can confirm this is still a problem, I hit it today. Will take a look.
betodealmeida commentedon Jan 23, 2018
This should be fixed in SQLAlchemy 1.2: http://docs.sqlalchemy.org/en/latest/changelog/migration_12.html#percent-signs-in-literal-column-now-conditionally-escaped
betodealmeida commentedon Jan 23, 2018
I tested with 1.2.1 and can confirm it works, here's the generated query without the
%%: