Пример #1
0
def test_query_with_parameters(bqtk: BQTestKit):
    result = bqtk.query_template(from_="select @int_param as nb") \
                 .with_query_parameters([
                     ScalarQueryParameter("int_param", "INT64", 1)
                 ]) \
                 .run()
    assert len(result.rows) == 1
    assert result.rows[0]["nb"] == 1
Пример #2
0
def test_change_query_parameters():
    pfl = PackageFileLoader("tests/ut/bq_test_kit/bq_dsl/resources/dummy_query.sql")
    conf = BQTestKitConfig({DEFAULT_LOCATION: "EU"})
    bq_tpl = BQQueryTemplate(from_=pfl, bqtk_config=conf, bq_client=None)
    assert bq_tpl.job_config.query_parameters == []
    params = [ScalarQueryParameter("p1", "STRING", "v1")]
    bq_tpl = bq_tpl.with_query_parameters(params)
    assert bq_tpl.job_config.query_parameters is not None
Пример #3
0
    def test_instance_getter_w_non_empty_list(self):
        from google.cloud.bigquery.query import ScalarQueryParameter

        query_parameters = [ScalarQueryParameter("foo", 'INT64', 123)]
        _, klass = self._descriptor_and_klass()
        instance = klass()
        instance._properties['queryParameters'] = query_parameters

        self.assertEqual(instance.query_parameters, query_parameters)
Пример #4
0
    def test_instance_setter_w_valid_udf(self):
        from google.cloud.bigquery.query import ScalarQueryParameter

        query_parameters = [ScalarQueryParameter("foo", 'INT64', 123)]
        _, klass = self._descriptor_and_klass()
        instance = klass()

        instance.query_parameters = query_parameters

        self.assertEqual(instance.query_parameters, query_parameters)
Пример #5
0
    def test_instance_setter_w_none(self):
        from google.cloud.bigquery.query import ScalarQueryParameter

        query_parameters = [ScalarQueryParameter("foo", 'INT64', 123)]
        _, klass = self._descriptor_and_klass()
        instance = klass()
        instance._query_parameters = query_parameters

        with self.assertRaises(ValueError):
            instance.query_parameters = None
Пример #6
0
def _make_subparam(name, type_, value):
    from google.cloud.bigquery.query import ScalarQueryParameter

    return ScalarQueryParameter(name, type_, value)