bigquery_tests.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. from sqlalchemy import column
  18. from superset.db_engine_specs.bigquery import BigQueryEngineSpec
  19. from tests.db_engine_specs.base_tests import DbEngineSpecTestCase
  20. class BigQueryTestCase(DbEngineSpecTestCase):
  21. def test_bigquery_sqla_column_label(self):
  22. label = BigQueryEngineSpec.make_label_compatible(column("Col").name)
  23. label_expected = "Col"
  24. self.assertEqual(label, label_expected)
  25. label = BigQueryEngineSpec.make_label_compatible(column("SUM(x)").name)
  26. label_expected = "SUM_x__5f110"
  27. self.assertEqual(label, label_expected)
  28. label = BigQueryEngineSpec.make_label_compatible(column("SUM[x]").name)
  29. label_expected = "SUM_x__7ebe1"
  30. self.assertEqual(label, label_expected)
  31. label = BigQueryEngineSpec.make_label_compatible(column("12345_col").name)
  32. label_expected = "_12345_col_8d390"
  33. self.assertEqual(label, label_expected)
  34. def test_convert_dttm(self):
  35. dttm = self.get_dttm()
  36. self.assertEqual(
  37. BigQueryEngineSpec.convert_dttm("DATE", dttm), "CAST('2019-01-02' AS DATE)"
  38. )
  39. self.assertEqual(
  40. BigQueryEngineSpec.convert_dttm("DATETIME", dttm),
  41. "CAST('2019-01-02T03:04:05.678900' AS DATETIME)",
  42. )
  43. self.assertEqual(
  44. BigQueryEngineSpec.convert_dttm("TIMESTAMP", dttm),
  45. "CAST('2019-01-02T03:04:05.678900' AS TIMESTAMP)",
  46. )