Exemplo n.º 1
0
def get_orders_restricted_projected(startdate, enddate):
    """Execute the equivalent of the following SQL query, querying the CSV file orders.csv:
        SELECT
            orderkey, custkey
        FROM
            orders
        WHERE
            startdate <= orders.orderdate and orders.orderdate < enddate

    :param startdate: The lower boundary (inclusive) of the date range for the column 'orderdate'.
    :param enddate: The upper boundary (exclusive) of the date range for the column 'orderdate'.
    """
    timer = FunctionTimer()
    short_prints = True

    def read_date(date_str: str) -> datetime:
        return datetime.strptime(date_str, "%Y-%m-%d").date()

    orders_types = {"orderkey": int, "custkey": int, "orderdate": read_date, "totalprice": float, "shippriority": int}
    orders = csv.import_csv("orders.csv", orders_types)
    timer.lap("orders", short=short_prints)

    def select_dates(rel) -> bool:
        orderdate = rel("orderdate").value
        return (startdate <= orderdate) and (orderdate < enddate)

    orders_restricted = sets.restrict(orders, select_dates)
    timer.lap("orders_restricted", short=short_prints)

    orders_restricted_projected = clans.project(orders_restricted, "orderkey", "custkey")
    timer.end("orders_restricted_projected", short=short_prints)

    return orders_restricted_projected
Exemplo n.º 2
0
    def test_restrict(self):
        self.assertIs(restrict(Undef(), Undef()), Undef())

        s1 = Set(1, 2, 3)

        self.assertRaises(TypeError, lambda: restrict(s1, Undef()))
        self.assertRaises(TypeError, lambda: restrict(s1, 1))
        self.assertRaises(TypeError, lambda: restrict(s1, 'a'))

        self.assertEqual(restrict(s1, lambda x: x.value < 3), Set(1, 2))
        self.assertEqual(restrict(s1, lambda x: x.value > 1), Set(2, 3))
Exemplo n.º 3
0
    def test_restrict(self):
        self.assertIs(restrict(Undef(), Undef()), Undef())

        s1 = Set(1, 2, 3)

        self.assertRaises(TypeError, lambda: restrict(s1, Undef()))
        self.assertRaises(TypeError, lambda: restrict(s1, 1))
        self.assertRaises(TypeError, lambda: restrict(s1, 'a'))

        self.assertEqual(restrict(s1, lambda x: x.value < 3), Set(1, 2))
        self.assertEqual(restrict(s1, lambda x: x.value > 1), Set(2, 3))
Exemplo n.º 4
0
def get_orders_restricted_projected(startdate, enddate):
    """Execute the equivalent of the following SQL query, querying the CSV file orders.csv:
        SELECT
            orderkey, custkey
        FROM
            orders
        WHERE
            startdate <= orders.orderdate and orders.orderdate < enddate

    :param startdate: The lower boundary (inclusive) of the date range for the column 'orderdate'.
    :param enddate: The upper boundary (exclusive) of the date range for the column 'orderdate'.
    """
    timer = FunctionTimer()
    short_prints = True

    def read_date(date_str: str) -> datetime:
        return datetime.strptime(date_str, '%Y-%m-%d').date()

    orders_types = {
        'orderkey': int,
        'custkey': int,
        'orderdate': read_date,
        'totalprice': float,
        'shippriority': int
    }
    orders = csv.import_csv('orders.csv', orders_types)
    timer.lap('orders', short=short_prints)

    def select_dates(rel) -> bool:
        orderdate = rel('orderdate').value
        return (startdate <= orderdate) and (orderdate < enddate)

    orders_restricted = sets.restrict(orders, select_dates)
    timer.lap('orders_restricted', short=short_prints)

    orders_restricted_projected = clans.project(orders_restricted, 'orderkey',
                                                'custkey')
    timer.end('orders_restricted_projected', short=short_prints)

    return orders_restricted_projected