Querying of date/datetime with year 1-999 is incorrect on some platforms
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 45/100
Research direction
Start with pyhive.common.ParamEscaper.escape_datetime and reproduce the issue using the supplied year-0001 table, timestamp, and SQLAlchemy query. Compare the formatted values produced with and without the year padding, then verify that the query returns the expected row on the affected platform.
Written by the indexing model from the issue text.
Description
Pyhive sqlachemy dialect can not do 'where' filtering for dates/timestamps with year lower than 1000 because leading zeros are omitted when %Y is used.
Years 1-999 are rare is real use, but may be used for relative timestamps for example, or when only time part is used.
This problem may appear on some systems depending of strftime implementation of system libraries. See https://bugs.python.org/issue13305
problematic method: pyhive.common.ParamEscaper.escape_datetime
This is a issue with python itself, but a workaround can be implemented for this case.
One solution is to use %04Y to set fixed with of 4, but it is also platform dependent.
Another is to use hack:
dt_str = '{:0>4}{}'.format(
item.strftime('%Y'),
item.strftime(format_.lstrip('%Y'))
)
This should be portable.
Reproduce
CREATE TABLE DateTimeTable(
date DATE,
timestamp TIMESTAMP
);
insert into DateTimeTable values ('0001-01-01', '0001-01-01T00:00:00.000000Z');
from datetime import datetime
from sqlalchemy import MetaData
...
meta = MetaData()
meta.reflect(bind=dbfs_engine)
ts = datetime.strptime('0001-01-01T00:00:00.000000', "%Y-%m-%dT%H:%M:%S.%f")
print(ts.strftime('%04Y-%m-%d %H:%M:%S.%f'))
print(ts.strftime('%Y-%m-%d %H:%M:%S.%f'))
table = meta.tables['datetimetable']
q = table.select(table.c['timestamp'] == ts)
q.bind = dbfs_engine
res = dbfs_engine.execute(q)
for r in res:
print(r)
# Nothing here
# Expected 1 row
- Dominant language
- Python
- Stars
- 1.7k
- Forks
- 545
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dropbox/PyHive
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
syfoud/Simulated_Scepter#172 ·
-
A cancelled tests run makes the coverage comment workflow fail and reports it as a red check on main Openarea: ci bug perceived difficulty: 3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Nitjsefnie-Harness-Commons/daedalus#921 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
EleutherAI/lm-evaluation-harness#4207 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
ClickHouse/clickhouse-connect#1057 ·