Beispiel #1
0
def test_socrata_sortkeys():
    assert sortkeys_to_socrata([]) == ":id"
    assert sortkeys_to_socrata([S("col")]) == "`col` ASC"
    assert (
        sortkeys_to_socrata([S("col", nulls_first=True, is_reversed=True), S("col2")])
        == "`col` DESC,`col2` ASC"
    )

    with pytest.raises(ValueError):
        sortkeys_to_socrata([S("col"), S("col2", nulls_first=False, is_reversed=True)])
Beispiel #2
0
    def explain(self, quals, columns, sortkeys=None, verbose=False):
        query = quals_to_socrata(quals, self.column_map)
        select = cols_to_socrata(columns, self.column_map)
        order = sortkeys_to_socrata(sortkeys, self.column_map)

        return [
            "Socrata query to %s" % self.domain,
            "Socrata dataset ID: %s" % self.table,
            "Query: %s" % query,
            "Columns: %s" % select,
            "Order: %s" % order,
        ]
Beispiel #3
0
    def execute(self, quals, columns, sortkeys=None):
        """Main Multicorn entry point."""
        query = quals_to_socrata(quals, self.column_map)
        select = cols_to_socrata(columns, self.column_map)
        order = sortkeys_to_socrata(sortkeys, self.column_map)

        logging.debug("Socrata query: %r, select: %r, order: %r", query,
                      select, order)

        # TODO offsets stop working after some point?
        result = self.client.get_all(
            dataset_identifier=self.table,
            where=query,
            select=select,
            limit=self.batch_size,
            order=order,
        )

        for r in result:
            r = to_json(r, columns, self.column_map)
            yield r