def test_query_with_date(self):
        dt = '2014-07-01'
        kwargs = {'import_date': datetime.datetime.strptime(dt, '%Y-%m-%d').date()}
        task = ImportVoucherTask(**kwargs)
        query = task.query()
        expected_query = textwrap.dedent(
            """
            USE default;
            DROP TABLE IF EXISTS `voucher_voucher`;
            CREATE EXTERNAL TABLE `voucher_voucher` (
                `id` INT,`name` STRING,`code` STRING,`usage` STRING,`start_datetime` TIMESTAMP,`end_datetime` TIMESTAMP,`num_basket_additions` INT,`num_orders` INT,`total_discount` DECIMAL(12, 2),`date_created` TIMESTAMP
            )
            PARTITIONED BY (dt STRING)

            LOCATION 's3://foo/bar/voucher_voucher';
            ALTER TABLE `voucher_voucher` ADD PARTITION (dt = '{dt}');
            """.format(dt=dt)
        )
        self.assertEquals(query, expected_query)
    def test_query_with_date(self):
        dt = '2014-07-01'
        kwargs = {'import_date': datetime.datetime.strptime(dt, '%Y-%m-%d').date()}
        task = ImportVoucherTask(**kwargs)
        query = task.query()
        expected_query = textwrap.dedent(
            """
            USE default;
            DROP TABLE IF EXISTS `voucher_voucher`;
            CREATE EXTERNAL TABLE `voucher_voucher` (
                `id` INT,`name` STRING,`code` STRING,`usage` STRING,`start_datetime` TIMESTAMP,`end_datetime` TIMESTAMP,`num_basket_additions` INT,`num_orders` INT,`total_discount` DECIMAL(12, 2),`date_created` TIMESTAMP
            )
            PARTITIONED BY (dt STRING)

            LOCATION 's3://foo/bar/voucher_voucher';
            ALTER TABLE `voucher_voucher` ADD PARTITION (dt = '{dt}');
            """.format(dt=dt)
        )
        self.assertEquals(query, expected_query)
Esempio n. 3
0
    def requires(self):  # pragma: no cover
        for requirement in super(EnterpriseEnrollmentDataTask, self).requires():
            yield requirement

        # the process that generates the source table used by this query
        yield (
            ImportAuthUserTask(),
            ImportAuthUserProfileTask(),
            ImportEnterpriseCustomerTask(),
            ImportEnterpriseCustomerUserTask(),
            ImportEnterpriseCourseEnrollmentUserTask(),
            ImportDataSharingConsentTask(),
            ImportUserSocialAuthTask(),
            ImportStudentCourseEnrollmentTask(),
            ImportPersistentCourseGradeTask(),
            CoursePartitionTask(
                date=self.date,
                warehouse_path=self.warehouse_path,
                api_root_url=self.api_root_url,
                api_page_size=self.api_page_size,
            ),
            UserActivityTableTask(
                warehouse_path=self.warehouse_path,
                overwrite_n_days=0,
                date=self.date
            ),
            ExternalCourseEnrollmentSummaryPartitionTask(
                date=self.date
            ),
        )

        kwargs = {
            'credentials': self.otto_credentials,
            'database': self.otto_database,
        }
        yield (
            ImportProductCatalog(**kwargs),
            ImportCurrentOrderLineState(**kwargs),
            ImportCurrentOrderDiscountState(**kwargs),
            ImportVoucherTask(**kwargs),
            ImportStockRecordTask(**kwargs),
            ImportCurrentOrderState(**kwargs),
            ImportEcommerceUser(**kwargs),
            ImportConditionalOfferTask(**kwargs),
            ImportBenefitTask(**kwargs),
        )