Beispiel #1
0
    def test_execute(self, mock_hook):
        operator = BigQueryCreateEmptyTableOperator(task_id=TASK_ID,
                                                    dataset_id=TEST_DATASET,
                                                    project_id=TEST_GCP_PROJECT_ID,
                                                    table_id=TEST_TABLE_ID)

        operator.execute(None)
        mock_hook.return_value \
            .get_conn.return_value \
            .cursor.return_value \
            .create_empty_table \
            .assert_called_once_with(
                dataset_id=TEST_DATASET,
                project_id=TEST_GCP_PROJECT_ID,
                table_id=TEST_TABLE_ID,
                schema_fields=None,
                time_partitioning={},
                labels=None,
                encryption_configuration=None
            )
Beispiel #2
0
    def test_create_clustered_empty_table(self, mock_hook):

        schema_fields = [{
            "name": "emp_name",
            "type": "STRING",
            "mode": "REQUIRED"
        }, {
            "name": "date_hired",
            "type": "DATE",
            "mode": "REQUIRED"
        }, {
            "name": "date_birth",
            "type": "DATE",
            "mode": "NULLABLE"
        }]
        time_partitioning = {"type": "DAY", "field": "date_hired"}
        cluster_fields = ["date_birth"]
        operator = BigQueryCreateEmptyTableOperator(
            task_id=TASK_ID,
            dataset_id=TEST_DATASET,
            project_id=TEST_GCP_PROJECT_ID,
            table_id=TEST_TABLE_ID,
            schema_fields=schema_fields,
            time_partitioning=time_partitioning,
            cluster_fields=cluster_fields)

        operator.execute(None)
        mock_hook.return_value \
            .create_empty_table \
            .assert_called_once_with(
                dataset_id=TEST_DATASET,
                project_id=TEST_GCP_PROJECT_ID,
                table_id=TEST_TABLE_ID,
                schema_fields=schema_fields,
                time_partitioning=time_partitioning,
                cluster_fields=cluster_fields,
                labels=None,
                view=None,
                encryption_configuration=None
            )