Skip to content
This repository was archived by the owner on Sep 28, 2022. It is now read-only.
This repository was archived by the owner on Sep 28, 2022. It is now read-only.

Something wrong when I use query of row(XXX, from_=datetime(2013, 9, 14, 19, 40)) #153

@Yuhjiang

Description

@Yuhjiang

When I read the getting-started and ran the python code, If I just passed one of from_ and to, it raised an error of 'NoneType'.

import os
import sys
import time
from datetime import datetime
import pilosa

from pilosa import Client, Index, TimeQuantum, URI
from pilosa.imports import csv_column_reader, csv_row_id_column_id


uri = URI('http', '10.0.16.15', 10101)
client = Client(cluster_or_uri=uri, use_manual_address=True)
schema = client.schema()
client.sync_schema(schema)

repository = schema.index('repository')
stargazer = repository.field('stargazer',
                             time_quantum=pilosa.TimeQuantum.YEAR_MONTH_DAY)
language = repository.field('language')

client.sync_schema(schema)

time_func = lambda s: int(time.mktime(time.strptime(s, '%Y-%m-%dT%H:%M')))
with open('stargazer.csv') as f:
    stargazer_reader = csv_column_reader(f, timefunc=time_func)
    client.import_field(stargazer, stargazer_reader)


with open('language.csv') as f:
    language_reader = csv_column_reader(f, csv_row_id_column_id)
    client.import_field(language, language_reader)


response = client.query(stargazer.row(14, from_=datetime(2013, 9, 14, 19, 40)))
print('User 14 starred: ', response.result.row.columns)

Error Info

Traceback (most recent call last):
  File "/Users/yuhao/PycharmProjects/djangoProject1/temp.py", line 34, in <module>
    response = client.query(stargazer.row(14, from_=datetime(2013, 9, 14, 19, 40)))
  File "/Users/yuhao/mulian/lib/python3.7/site-packages/pilosa/orm.py", line 539, in row
    return self._row_range(row_idkey, from_, to)
  File "/Users/yuhao/mulian/lib/python3.7/site-packages/pilosa/orm.py", line 631, in _row_range
    end_str = end.strftime(_TIME_FORMAT)
AttributeError: 'NoneType' object has no attribute 'strftime'

But the doc says that both from and to parameters are optional. Maybe there is some bug in the source code which I can fix it.

def _row_range(self, row, start, end):
    """Creates a Row query with timestamps."""
    row_str = idkey_as_str(row)
    start_str = start.strftime(_TIME_FORMAT)
    end_str = end.strftime(_TIME_FORMAT)
    parts = ['%s=%s' % (self.name, row_str)]
    if start:
        parts.append("from='%s'" % start_str)
    if end:
        parts.append("to='%s'" % end_str)
    return PQLQuery(u"Row(%s)" % ','.join(parts), self.index)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions