null_value.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. from textwrap import dedent
  10. from materialize.checks.actions import Testdrive
  11. from materialize.checks.checks import Check
  12. class NullValue(Check):
  13. def initialize(self) -> Testdrive:
  14. return Testdrive(
  15. dedent(
  16. """
  17. > CREATE TABLE null_value_table (f1 INTEGER, f2 INTEGER DEFAULT NULL);
  18. > INSERT INTO null_value_table DEFAULT VALUES;
  19. > INSERT INTO null_value_table VALUES (NULL, NULL);
  20. > INSERT INTO null_value_table VALUES (NULL, NULL);
  21. """
  22. )
  23. )
  24. def manipulate(self) -> list[Testdrive]:
  25. return [
  26. Testdrive(dedent(s))
  27. for s in [
  28. """
  29. > CREATE VIEW null_value_view1 AS
  30. SELECT f1, f2, NULL
  31. FROM null_value_table
  32. WHERE f1 IS NULL OR f1 IS NOT NULL OR f1 = NULL;
  33. > INSERT INTO null_value_table SELECT * FROM null_value_table;
  34. """,
  35. """
  36. > CREATE MATERIALIZED VIEW null_value_view2 AS
  37. SELECT f1, f2, NULL
  38. FROM null_value_table
  39. WHERE f1 IS NULL OR f1 IS NOT NULL OR f1 = NULL;
  40. > INSERT INTO null_value_table SELECT * FROM null_value_table;
  41. """,
  42. ]
  43. ]
  44. def validate(self) -> Testdrive:
  45. return Testdrive(
  46. dedent(
  47. """
  48. > SELECT * FROM null_value_view1;
  49. <null> <null> <null>
  50. <null> <null> <null>
  51. <null> <null> <null>
  52. <null> <null> <null>
  53. <null> <null> <null>
  54. <null> <null> <null>
  55. <null> <null> <null>
  56. <null> <null> <null>
  57. <null> <null> <null>
  58. <null> <null> <null>
  59. <null> <null> <null>
  60. <null> <null> <null>
  61. > SELECT * FROM null_value_view2;
  62. <null> <null> <null>
  63. <null> <null> <null>
  64. <null> <null> <null>
  65. <null> <null> <null>
  66. <null> <null> <null>
  67. <null> <null> <null>
  68. <null> <null> <null>
  69. <null> <null> <null>
  70. <null> <null> <null>
  71. <null> <null> <null>
  72. <null> <null> <null>
  73. <null> <null> <null>
  74. """
  75. )
  76. )