dcs-sdk 2.3.0__tar.gz → 2.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/PKG-INFO +2 -2
  2. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/README.md +1 -1
  3. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/common/errors.py +38 -0
  4. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/common/models/data_source_resource.py +13 -0
  5. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/datasource/sql_datasource.py +78 -1
  6. dcs_sdk-2.3.2/dcs_core/core/datasource/structure_probes.py +411 -0
  7. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/mssql.py +96 -11
  8. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/postgres.py +48 -2
  9. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/__version__.py +1 -1
  10. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/pyproject.toml +1 -1
  11. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/__init__.py +0 -0
  12. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/__main__.py +0 -0
  13. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/abcs/__init__.py +0 -0
  14. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/abcs/compiler.py +0 -0
  15. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/abcs/database_types.py +0 -0
  16. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/config.py +0 -0
  17. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/__init__.py +0 -0
  18. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/_connect.py +0 -0
  19. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/base.py +0 -0
  20. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/bigquery.py +0 -0
  21. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/clickhouse.py +0 -0
  22. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/databricks.py +0 -0
  23. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/db2.py +0 -0
  24. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/duckdb.py +0 -0
  25. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/mssql.py +0 -0
  26. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/mysql.py +0 -0
  27. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/oracle.py +0 -0
  28. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/postgresql.py +0 -0
  29. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/presto.py +0 -0
  30. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/redis.py +0 -0
  31. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/redshift.py +0 -0
  32. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/sap_hana.py +0 -0
  33. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/snowflake.py +0 -0
  34. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/sybase.py +0 -0
  35. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/trino.py +0 -0
  36. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/databases/vertica.py +0 -0
  37. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/diff_tables.py +0 -0
  38. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/errors.py +0 -0
  39. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/format.py +0 -0
  40. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/hashdiff_tables.py +0 -0
  41. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/info_tree.py +0 -0
  42. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/joindiff_tables.py +0 -0
  43. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/lexicographic_space.py +0 -0
  44. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/parse_time.py +0 -0
  45. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/py.typed +0 -0
  46. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/queries/__init__.py +0 -0
  47. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/queries/api.py +0 -0
  48. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/queries/ast_classes.py +0 -0
  49. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/queries/base.py +0 -0
  50. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/queries/extras.py +0 -0
  51. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/query_utils.py +0 -0
  52. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/schema.py +0 -0
  53. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/streaming.py +0 -0
  54. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/table_segment.py +0 -0
  55. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/thread_utils.py +0 -0
  56. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/utils.py +0 -0
  57. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/data_diff/version.py +0 -0
  58. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/__init__.py +0 -0
  59. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/__main__.py +0 -0
  60. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/__version__.py +0 -0
  61. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/cli/__init__.py +0 -0
  62. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/cli/cli.py +0 -0
  63. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/__init__.py +0 -0
  64. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/common/__init__.py +0 -0
  65. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/common/models/__init__.py +0 -0
  66. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/common/models/configuration.py +0 -0
  67. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/common/models/dashboard.py +0 -0
  68. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/common/models/metric.py +0 -0
  69. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/common/models/profile.py +0 -0
  70. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/common/models/validation.py +0 -0
  71. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/common/models/widget.py +0 -0
  72. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/configuration/__init__.py +0 -0
  73. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/configuration/config_loader.py +0 -0
  74. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/configuration/configuration_parser.py +0 -0
  75. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/configuration/configuration_parser_arc.py +0 -0
  76. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/datasource/__init__.py +0 -0
  77. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/datasource/base.py +0 -0
  78. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/datasource/file_datasource.py +0 -0
  79. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/datasource/manager.py +0 -0
  80. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/datasource/search_datasource.py +0 -0
  81. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/inspect.py +0 -0
  82. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/logger/__init__.py +0 -0
  83. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/logger/base.py +0 -0
  84. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/logger/default_logger.py +0 -0
  85. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/metric/__init__.py +0 -0
  86. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/metric/base.py +0 -0
  87. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/metric/combined_metric.py +0 -0
  88. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/metric/custom_metric.py +0 -0
  89. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/metric/manager.py +0 -0
  90. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/metric/numeric_metric.py +0 -0
  91. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/metric/reliability_metric.py +0 -0
  92. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/observability/__init__.py +0 -0
  93. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/observability/connection_observer.py +0 -0
  94. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/profiling/__init__.py +0 -0
  95. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/profiling/datasource_profiling.py +0 -0
  96. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/profiling/numeric_field_profiling.py +0 -0
  97. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/profiling/text_field_profiling.py +0 -0
  98. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/repository/__init__.py +0 -0
  99. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/repository/metric_repository.py +0 -0
  100. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/utils/__init__.py +0 -0
  101. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/utils/log.py +0 -0
  102. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/utils/tracking.py +0 -0
  103. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/utils/utils.py +0 -0
  104. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/validation/__init__.py +0 -0
  105. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/validation/base.py +0 -0
  106. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/validation/completeness_validation.py +0 -0
  107. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/validation/custom_query_validation.py +0 -0
  108. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/validation/manager.py +0 -0
  109. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/validation/numeric_validation.py +0 -0
  110. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/validation/reliability_validation.py +0 -0
  111. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/validation/uniqueness_validation.py +0 -0
  112. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/core/validation/validity_validation.py +0 -0
  113. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/__init__.py +0 -0
  114. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/__init__.py +0 -0
  115. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/azure_blob.py +0 -0
  116. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/bigquery.py +0 -0
  117. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/clickhouse.py +0 -0
  118. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/databricks.py +0 -0
  119. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/db2.py +0 -0
  120. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/duck_db.py +0 -0
  121. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/elasticsearch.py +0 -0
  122. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/mysql.py +0 -0
  123. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/opensearch.py +0 -0
  124. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/oracle.py +0 -0
  125. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/presto.py +0 -0
  126. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/redshift.py +0 -0
  127. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/sap_hana.py +0 -0
  128. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/snowflake.py +0 -0
  129. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/spark_df.py +0 -0
  130. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/sybase.py +0 -0
  131. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/trino.py +0 -0
  132. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/databases/vertica.py +0 -0
  133. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/storage/__init__.py +0 -0
  134. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/storage/local_file.py +0 -0
  135. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/utils/__init__.py +0 -0
  136. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/integrations/utils/utils.py +0 -0
  137. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/__init__.py +0 -0
  138. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/dashboard.py +0 -0
  139. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/models.py +0 -0
  140. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/static/assets/fonts/DMSans-Bold.ttf +0 -0
  141. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/static/assets/fonts/DMSans-Medium.ttf +0 -0
  142. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/static/assets/fonts/DMSans-Regular.ttf +0 -0
  143. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/static/assets/fonts/DMSans-SemiBold.ttf +0 -0
  144. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/static/assets/images/docs.svg +0 -0
  145. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/static/assets/images/github.svg +0 -0
  146. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/static/assets/images/logo.svg +0 -0
  147. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/static/assets/images/slack.svg +0 -0
  148. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/static/index.js +0 -0
  149. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_core/report/static/index.js.LICENSE.txt +0 -0
  150. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/__init__.py +0 -0
  151. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/__main__.py +0 -0
  152. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/cli/__init__.py +0 -0
  153. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/cli/cli.py +0 -0
  154. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/__init__.py +0 -0
  155. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/config/__init__.py +0 -0
  156. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/config/config_loader.py +0 -0
  157. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/data_diff/__init__.py +0 -0
  158. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/data_diff/data_differ.py +0 -0
  159. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/rules/__init__.py +0 -0
  160. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/rules/rules_mappping.py +0 -0
  161. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/rules/rules_repository.py +0 -0
  162. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/rules/schema_rules.py +0 -0
  163. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/utils/__init__.py +0 -0
  164. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/utils/serializer.py +0 -0
  165. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/utils/similarity_score/__init__.py +0 -0
  166. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/utils/similarity_score/base_provider.py +0 -0
  167. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/utils/similarity_score/cosine_similarity_provider.py +0 -0
  168. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/utils/similarity_score/jaccard_provider.py +0 -0
  169. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/utils/similarity_score/levenshtein_distance_provider.py +0 -0
  170. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/utils/table.py +0 -0
  171. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/utils/themes.py +0 -0
  172. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/sdk/utils/utils.py +0 -0
  173. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/utils/__init__.py +0 -0
  174. {dcs_sdk-2.3.0 → dcs_sdk-2.3.2}/dcs_sdk/utils/temp_objects.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dcs-sdk
3
- Version: 2.3.0
3
+ Version: 2.3.2
4
4
  Summary: SDK for DataChecks
5
5
  Author: Waterdip Labs
6
6
  Author-email: hello@waterdip.ai
@@ -94,7 +94,7 @@ Requires-Dist: virtualenv (>=20.36.2,<21.0.0)
94
94
  Description-Content-Type: text/markdown
95
95
 
96
96
  <h1 align="center">
97
- DCS SDK v2.3.0
97
+ DCS SDK v2.3.2
98
98
  </h1>
99
99
 
100
100
  > SDK for DataChecks
@@ -1,5 +1,5 @@
1
1
  <h1 align="center">
2
- DCS SDK v2.3.0
2
+ DCS SDK v2.3.2
3
3
  </h1>
4
4
 
5
5
  > SDK for DataChecks
@@ -19,6 +19,8 @@ ERROR_METRIC_GENERATION = "metric_generation_error"
19
19
  ERROR_FETCHING_TABLE = "table_fetch_error"
20
20
  ERROR_FETCHING_COLUMN = "column_fetch_error"
21
21
  ERROR_ESTATE_SURFACE_UNAVAILABLE = "estate_surface_unavailable"
22
+ ERROR_STRUCTURE_PROBES_UNSUPPORTED = "structure_probes_unsupported"
23
+ ERROR_STRUCTURE_PROBE_COLUMN_UNSUPPORTED = "structure_probe_column_unsupported"
22
24
 
23
25
 
24
26
  class DataChecksRuntimeError(Exception):
@@ -138,6 +140,42 @@ class EstateSurfaceUnavailableError(Exception):
138
140
  self.reason = reason
139
141
 
140
142
 
143
+ class StructureProbesUnsupportedError(Exception):
144
+ """Raised when a dialect has no structure probes at all.
145
+
146
+ The probes (``structure_*`` on ``StructureProbeMixin``) are implemented per
147
+ engine. On any other engine every probe raises this, so a caller can tell
148
+ "this engine cannot be measured" apart from a measurement that failed.
149
+
150
+ :param dialect: the datasource class that was asked, e.g. ``"MysqlDataSource"``.
151
+ :param method: the probe that was called, e.g. ``"structure_table_counts"``.
152
+ """
153
+
154
+ def __init__(self, message: str, dialect: str, method: str):
155
+ super().__init__(message)
156
+ self.error_code = ERROR_STRUCTURE_PROBES_UNSUPPORTED
157
+ self.dialect = dialect
158
+ self.method = method
159
+
160
+
161
+ class StructureProbeColumnUnsupported(Exception):
162
+ """Raised, before any SQL is sent, when a probe would have to compare a
163
+ column the engine cannot compare -- SQL Server ``image`` is the case: it
164
+ cannot be grouped, cast to text or tested for equality.
165
+
166
+ :param table: the table the column belongs to.
167
+ :param column: the column's name.
168
+ :param data_type: its declared type, as passed in.
169
+ """
170
+
171
+ def __init__(self, message: str, table: str, column: str, data_type=None):
172
+ super().__init__(message)
173
+ self.error_code = ERROR_STRUCTURE_PROBE_COLUMN_UNSUPPORTED
174
+ self.table = table
175
+ self.column = column
176
+ self.data_type = data_type
177
+
178
+
141
179
  # ---------------------------------------------------------------------------
142
180
  # SQL Server connection failures
143
181
  #
@@ -68,6 +68,19 @@ class RawColumnInfo:
68
68
  character_maximum_length: Optional[int] = None
69
69
 
70
70
 
71
+ @dataclass(frozen=True)
72
+ class ProbeColumn:
73
+ """A column as the structure probes need it: its name, plus the declared
74
+ type facts that decide how it is compared. ``data_type`` is spelled as the
75
+ catalog spells it (``"nvarchar"``, ``"character varying"``);
76
+ ``character_maximum_length`` is ``-1`` for SQL Server ``(max)`` types."""
77
+
78
+ name: str
79
+ data_type: Optional[str] = None
80
+ numeric_scale: Optional[int] = None
81
+ character_maximum_length: Optional[int] = None
82
+
83
+
71
84
  @dataclass
72
85
  class SybaseDriverTypes:
73
86
  is_ase: bool = False
@@ -33,7 +33,9 @@ from sqlalchemy.engine import Connection, Engine
33
33
  from dcs_core.core.common.errors import (
34
34
  DependencyParseError,
35
35
  EstateSurfaceUnavailableError,
36
+ StructureProbesUnsupportedError,
36
37
  )
38
+ from dcs_core.core.common.models.data_source_resource import ProbeColumn
37
39
  from dcs_core.core.datasource.base import DataSource
38
40
  from dcs_core.core.observability.connection_observer import (
39
41
  notify_connection_closed,
@@ -199,7 +201,10 @@ class SQLDataSource(DataSource):
199
201
  def get_table_foreign_key_info(self, table_name: str, schema: str | None = None):
200
202
  """
201
203
  Return a table's foreign keys as a list of dicts with keys: constraint_name,
202
- table_name, fk_column, referenced_table, referenced_column.
204
+ table_name, fk_column, referenced_schema, referenced_table, referenced_column.
205
+ ``referenced_schema`` is the parent table's own schema, independent of the
206
+ child table's -- required so a caller can resolve a foreign key whose parent
207
+ lives in a different schema instead of assuming it shares the child's.
203
208
  Override in each datasource subclass. Default returns empty so a scan of an engine
204
209
  without FK introspection (or with no FK concept, e.g. Trino/Presto) doesn't fail -
205
210
  the foreign-key sync simply records none instead of raising.
@@ -1872,3 +1877,75 @@ class SQLDataSource(DataSource):
1872
1877
  :return: list of dicts describing each remote/linked server.
1873
1878
  """
1874
1879
  raise self._estate_surface_unsupported("linked_servers")
1880
+
1881
+ # ------------------------------------------------------------------
1882
+ # Structure probes
1883
+ #
1884
+ # Implemented by StructureProbeMixin (structure_probes.py), which the
1885
+ # engines that have probes list first in their bases, so its methods
1886
+ # override these. On every other engine each probe raises
1887
+ # StructureProbesUnsupportedError instead of answering.
1888
+ # ------------------------------------------------------------------
1889
+
1890
+ def _structure_probes_unsupported(self, method: str) -> StructureProbesUnsupportedError:
1891
+ """The 'this dialect has no structure probes' error, phrased consistently."""
1892
+ return StructureProbesUnsupportedError(
1893
+ f"{self.__class__.__name__} has no structure probes ('{method}' is not implemented for this dialect)",
1894
+ dialect=self.__class__.__name__,
1895
+ method=method,
1896
+ )
1897
+
1898
+ def structure_table_counts(self, table: str, columns: List[ProbeColumn]) -> Dict[str, Any]:
1899
+ """Row count and per-column distinct / non-null counts. See StructureProbeMixin."""
1900
+ raise self._structure_probes_unsupported("structure_table_counts")
1901
+
1902
+ def structure_sample_rows(
1903
+ self, table: str, columns: List[ProbeColumn], limit: int
1904
+ ) -> Tuple[List[tuple], List[str]]:
1905
+ """The first ``limit`` rows, unordered. See StructureProbeMixin."""
1906
+ raise self._structure_probes_unsupported("structure_sample_rows")
1907
+
1908
+ def structure_duplicate_group_count(self, table: str, columns: List[ProbeColumn]) -> int:
1909
+ """Value tuples occurring more than once. See StructureProbeMixin."""
1910
+ raise self._structure_probes_unsupported("structure_duplicate_group_count")
1911
+
1912
+ def structure_max_group_size(self, table: str, columns: List[ProbeColumn]) -> int:
1913
+ """Most rows sharing one value tuple. See StructureProbeMixin."""
1914
+ raise self._structure_probes_unsupported("structure_max_group_size")
1915
+
1916
+ def structure_duplicate_group_rows(
1917
+ self,
1918
+ table: str,
1919
+ key_columns: List[ProbeColumn],
1920
+ all_columns: List[ProbeColumn],
1921
+ max_groups: int = 3,
1922
+ max_rows: int = 40,
1923
+ ) -> Tuple[List[tuple], List[str]]:
1924
+ """Rows of the first duplicate groups, with a group ordinal. See StructureProbeMixin."""
1925
+ raise self._structure_probes_unsupported("structure_duplicate_group_rows")
1926
+
1927
+ def structure_distinct_tuple_count(
1928
+ self, table: str, columns: List[ProbeColumn], non_null_only: bool = False
1929
+ ) -> int:
1930
+ """Distinct value tuples. See StructureProbeMixin."""
1931
+ raise self._structure_probes_unsupported("structure_distinct_tuple_count")
1932
+
1933
+ def structure_non_null_row_count(self, table: str, columns: List[ProbeColumn]) -> int:
1934
+ """Rows with every column non-NULL. See StructureProbeMixin."""
1935
+ raise self._structure_probes_unsupported("structure_non_null_row_count")
1936
+
1937
+ def structure_orphan_count(
1938
+ self,
1939
+ child_table: str,
1940
+ child_columns: List[ProbeColumn],
1941
+ parent_table: str,
1942
+ parent_columns: List[ProbeColumn],
1943
+ compare: str = "text",
1944
+ binary: bool = False,
1945
+ ) -> int:
1946
+ """Distinct child key tuples with no parent row. See StructureProbeMixin."""
1947
+ raise self._structure_probes_unsupported("structure_orphan_count")
1948
+
1949
+ def structure_session_setup(self, statement_timeout_s: int, read_only: bool = True) -> None:
1950
+ """Statement timeout and read-only session. See StructureProbeMixin."""
1951
+ raise self._structure_probes_unsupported("structure_session_setup")
@@ -0,0 +1,411 @@
1
+ # Copyright 2022-present, the Waterdip Labs Pvt. Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Structure probes: the measurements structure inference takes of a source.
16
+
17
+ Structure inference decides what one row of a table means, which columns are
18
+ its natural key and which tables link to which. Every fact it measures comes
19
+ from the ``structure_*`` methods here, so these are the only queries it sends
20
+ to a customer database.
21
+
22
+ The methods are written once, against a few hooks each engine implements:
23
+ identifier quoting, the expression a column is grouped by, the text form it is
24
+ compared across tables by, the count function and the row limit. Engines
25
+ without the hooks do not inherit this mixin, and ``SQLDataSource`` answers
26
+ every probe with ``StructureProbesUnsupportedError``.
27
+
28
+ Rules every query here keeps:
29
+
30
+ - it goes through ``fetchall`` / ``fetchone`` / ``fetchall_with_col_names``,
31
+ so a stubbed datasource sees exactly what would be sent;
32
+ - every identifier is quoted with embedded quote characters escaped;
33
+ - every column of a derived table is named (T-SQL rejects an unnamed one with
34
+ "No column name was specified");
35
+ - a column the engine cannot compare raises ``StructureProbeColumnUnsupported``
36
+ before any SQL is sent;
37
+ - every count comes back as a Python ``int``.
38
+ """
39
+
40
+ from typing import Any, Dict, List, Optional, Sequence, Set, Tuple
41
+
42
+ from dcs_core.core.common.errors import StructureProbeColumnUnsupported
43
+ from dcs_core.core.common.models.data_source_resource import ProbeColumn
44
+
45
+ __all__ = ["ProbeColumn", "StructureProbeMixin"]
46
+
47
+ ORPHAN_COMPARE_MODES = ("text", "native")
48
+
49
+
50
+ def _as_int(value: Any) -> int:
51
+ """A count from the driver as an ``int``; ``None`` (an aggregate over no rows) is 0."""
52
+ if value is None:
53
+ return 0
54
+ return int(value)
55
+
56
+
57
+ class StructureProbeMixin:
58
+ """Structure probes, for a ``SQLDataSource`` subclass that implements the hooks.
59
+
60
+ List it FIRST in the datasource's bases, so these methods override the
61
+ ``SQLDataSource`` stubs that raise ``StructureProbesUnsupportedError``.
62
+ Tables are resolved in the connection's schema (``self.schema_name``).
63
+ """
64
+
65
+ #: Most items one SELECT list may carry, or None for no practical limit.
66
+ #: ``structure_table_counts`` splits its aggregate across queries when a
67
+ #: table is wider than this.
68
+ _PROBE_MAX_SELECT_ITEMS: Optional[int] = None
69
+
70
+ # ------------------------------------------------------------------
71
+ # Hooks. Defaults are ANSI where one exists.
72
+ # ------------------------------------------------------------------
73
+
74
+ def _probe_quote(self, name: str) -> str:
75
+ """``name`` as a quoted identifier, embedded quote characters escaped."""
76
+ return '"' + name.replace('"', '""') + '"'
77
+
78
+ def _probe_table(self, table: str) -> str:
79
+ """The table, qualified by the connection's schema when it has one."""
80
+ schema = getattr(self, "schema_name", None)
81
+ if schema:
82
+ return f"{self._probe_quote(schema)}.{self._probe_quote(table)}"
83
+ return self._probe_quote(table)
84
+
85
+ def _probe_ident(self, column: str) -> str:
86
+ """A column name as a quoted identifier."""
87
+ return self._probe_quote(column)
88
+
89
+ def _probe_comparable(self, expr: str, col: ProbeColumn) -> Optional[str]:
90
+ """``expr`` in a form ``GROUP BY`` / ``DISTINCT`` / ``=`` accept, or None
91
+ when the column cannot be compared at all."""
92
+ return expr
93
+
94
+ def _probe_text(self, expr: str, col: ProbeColumn, binary: bool) -> Optional[str]:
95
+ """``expr`` as text, for comparing columns of different tables, or None
96
+ when the column has no text form. There is no portable default: the
97
+ wrong cast is silently lossy (a VARCHAR cast drops unicode on SQL
98
+ Server), so each engine states its own."""
99
+ raise NotImplementedError(f"{self.__class__.__name__} has no structure-probe text form")
100
+
101
+ def _probe_count(self) -> str:
102
+ """The count function. An engine whose COUNT is 32-bit returns its 64-bit one."""
103
+ return "COUNT"
104
+
105
+ def _probe_top(self, n: int) -> str:
106
+ """A row-limit prefix for the SELECT list (``"TOP n "``), or ``""``."""
107
+ return ""
108
+
109
+ def _probe_limit(self, n: int) -> str:
110
+ """A row-limit suffix for the query (``" LIMIT n"``), or ``""``."""
111
+ return f" FETCH FIRST {n} ROWS ONLY"
112
+
113
+ def _probe_masked_columns(self, table: str) -> Set[str]:
114
+ """Columns whose values this login sees masked, so their value counts
115
+ are meaningless. Engines without data masking return an empty set."""
116
+ return set()
117
+
118
+ def _probe_session_setup(self, statement_timeout_s: int, read_only: bool) -> None:
119
+ """Apply a statement timeout (and read-only mode, where the engine has
120
+ one) to this connection."""
121
+ raise NotImplementedError(f"{self.__class__.__name__} has no structure-probe session setup")
122
+
123
+ # ------------------------------------------------------------------
124
+ # Builders
125
+ # ------------------------------------------------------------------
126
+
127
+ @staticmethod
128
+ def _probe_check_table(table: str) -> None:
129
+ if not isinstance(table, str) or not table:
130
+ raise ValueError("a table name is required")
131
+ if "\x00" in table:
132
+ raise ValueError(f"refusing to probe table {table!r}")
133
+
134
+ @staticmethod
135
+ def _probe_check_columns(columns: Sequence[ProbeColumn], what: str) -> List[ProbeColumn]:
136
+ cols = list(columns or [])
137
+ if not cols:
138
+ raise ValueError(f"{what}: at least one column is required")
139
+ seen = set()
140
+ for col in cols:
141
+ if not isinstance(col, ProbeColumn):
142
+ raise TypeError(f"{what}: expected ProbeColumn, got {type(col).__name__}")
143
+ if not col.name or "\x00" in col.name:
144
+ raise ValueError(f"{what}: refusing to probe column {col.name!r}")
145
+ if col.name in seen:
146
+ raise ValueError(f"{what}: column {col.name!r} is listed twice")
147
+ seen.add(col.name)
148
+ return cols
149
+
150
+ @staticmethod
151
+ def _probe_check_positive(value: int, what: str) -> int:
152
+ if isinstance(value, bool) or not isinstance(value, int) or value < 1:
153
+ raise ValueError(f"{what} must be a positive integer, got {value!r}")
154
+ return value
155
+
156
+ def _probe_col(self, col: ProbeColumn, alias: Optional[str] = None) -> str:
157
+ ident = self._probe_ident(col.name)
158
+ return f"{alias}.{ident}" if alias else ident
159
+
160
+ def _probe_unsupported(self, table: str, col: ProbeColumn, how: str) -> StructureProbeColumnUnsupported:
161
+ return StructureProbeColumnUnsupported(
162
+ f"{table}.{col.name} ({col.data_type}) cannot be {how} on {self.__class__.__name__}",
163
+ table=table,
164
+ column=col.name,
165
+ data_type=col.data_type,
166
+ )
167
+
168
+ def _probe_group_expr(self, table: str, col: ProbeColumn, alias: Optional[str] = None) -> str:
169
+ """The comparable expression, or StructureProbeColumnUnsupported."""
170
+ expr = self._probe_comparable(self._probe_col(col, alias), col)
171
+ if expr is None:
172
+ raise self._probe_unsupported(table, col, "grouped or compared")
173
+ return expr
174
+
175
+ def _probe_text_expr(self, table: str, col: ProbeColumn, alias: str, binary: bool) -> str:
176
+ """The text form, or StructureProbeColumnUnsupported."""
177
+ expr = self._probe_text(self._probe_col(col, alias), col, binary)
178
+ if expr is None:
179
+ raise self._probe_unsupported(table, col, "compared as text")
180
+ return expr
181
+
182
+ def _probe_not_null(self, cols: Sequence[ProbeColumn], alias: Optional[str] = None) -> str:
183
+ return " AND ".join(f"{self._probe_col(c, alias)} IS NOT NULL" for c in cols)
184
+
185
+ def _probe_select(self, items: str, rest: str, limit: Optional[int] = None) -> str:
186
+ """``SELECT [TOP n] items rest [LIMIT n]``."""
187
+ if limit is None:
188
+ return f"SELECT {items} {rest}"
189
+ return f"SELECT {self._probe_top(limit)}{items} {rest}{self._probe_limit(limit)}"
190
+
191
+ def _probe_scalar(self, query: str) -> int:
192
+ row = self.fetchone(query)
193
+ return _as_int(row[0] if row is not None else None)
194
+
195
+ # ------------------------------------------------------------------
196
+ # Probes
197
+ # ------------------------------------------------------------------
198
+
199
+ def structure_table_counts(self, table: str, columns: Sequence[ProbeColumn]) -> Dict[str, Any]:
200
+ """Row count, and distinct / non-null counts per column, in one aggregate
201
+ (several only when the table is wider than one SELECT list may be).
202
+
203
+ ``distinct`` is None for a column that cannot be compared, and for a
204
+ masked column (its values aggregate to nothing, so a count would read
205
+ as a measurement it is not); ``masked`` says which. ``non_null`` is
206
+ counted with ``CASE WHEN c IS NOT NULL``, which works on every type and
207
+ is unaffected by masking.
208
+
209
+ :return: ``{"rows": int, "columns": {name: {"distinct": int | None,
210
+ "non_null": int, "masked": bool}}}``
211
+ """
212
+ self._probe_check_table(table)
213
+ cols = self._probe_check_columns(columns, "structure_table_counts")
214
+ count = self._probe_count()
215
+ masked = {name.casefold() for name in self._probe_masked_columns(table)}
216
+
217
+ items: List[Tuple[str, str]] = []
218
+ plan: List[Tuple[ProbeColumn, bool, bool]] = []
219
+ for i, col in enumerate(cols):
220
+ is_masked = col.name.casefold() in masked
221
+ quoted = self._probe_col(col)
222
+ distinct_expr = None if is_masked else self._probe_comparable(quoted, col)
223
+ if distinct_expr is not None:
224
+ items.append((f"d_{i}", f"{count}(DISTINCT {distinct_expr})"))
225
+ items.append((f"n_{i}", f"{count}(CASE WHEN {quoted} IS NOT NULL THEN 1 END)"))
226
+ plan.append((col, is_masked, distinct_expr is not None))
227
+
228
+ # One query unless the table is wider than one SELECT list may be; then
229
+ # the row count comes from the first of the queries.
230
+ size = max(1, (self._PROBE_MAX_SELECT_ITEMS or len(items) + 1) - 1)
231
+ batches = [items[start : start + size] for start in range(0, len(items), size)]
232
+ table_sql = self._probe_table(table)
233
+ values: Dict[str, Any] = {}
234
+ for index, batch in enumerate(batches):
235
+ aliases = (["rows_"] if index == 0 else []) + [alias for alias, _ in batch]
236
+ exprs = ([f"{count}(*) AS rows_"] if index == 0 else []) + [f"{sql} AS {alias}" for alias, sql in batch]
237
+ row = self.fetchone(self._probe_select(", ".join(exprs), f"FROM {table_sql}"))
238
+ values.update(zip(aliases, row if row is not None else ()))
239
+
240
+ return {
241
+ "rows": _as_int(values.get("rows_")),
242
+ "columns": {
243
+ col.name: {
244
+ "distinct": _as_int(values.get(f"d_{i}")) if has_distinct else None,
245
+ "non_null": _as_int(values.get(f"n_{i}")),
246
+ "masked": is_masked,
247
+ }
248
+ for i, (col, is_masked, has_distinct) in enumerate(plan)
249
+ },
250
+ }
251
+
252
+ def structure_sample_rows(
253
+ self, table: str, columns: Sequence[ProbeColumn], limit: int
254
+ ) -> Tuple[List[tuple], List[str]]:
255
+ """The first ``limit`` rows the engine returns, unordered, normalised
256
+ with ``normalize_sample_rows``. Non-comparable columns are read too.
257
+
258
+ :return: ``(rows, column_names)``, names as requested.
259
+ """
260
+ self._probe_check_table(table)
261
+ cols = self._probe_check_columns(columns, "structure_sample_rows")
262
+ limit = self._probe_check_positive(limit, "limit")
263
+ items = ", ".join(self._probe_col(c) for c in cols)
264
+ rows, _ = self.fetchall_with_col_names(self._probe_select(items, f"FROM {self._probe_table(table)}", limit))
265
+ return self.normalize_sample_rows(rows), [c.name for c in cols]
266
+
267
+ def structure_duplicate_group_count(self, table: str, columns: Sequence[ProbeColumn]) -> int:
268
+ """How many value tuples of ``columns`` occur more than once. 0 means
269
+ the columns are unique (a NULL tuple groups like any other value)."""
270
+ self._probe_check_table(table)
271
+ cols = self._probe_check_columns(columns, "structure_duplicate_group_count")
272
+ count = self._probe_count()
273
+ group = ", ".join(self._probe_group_expr(table, c) for c in cols)
274
+ inner = f"SELECT 1 AS x FROM {self._probe_table(table)} GROUP BY {group} HAVING {count}(*) > 1"
275
+ return self._probe_scalar(f"SELECT {count}(*) AS n FROM ({inner}) d")
276
+
277
+ def structure_max_group_size(self, table: str, columns: Sequence[ProbeColumn]) -> int:
278
+ """The most rows sharing one value tuple of ``columns``; 0 for an empty table."""
279
+ self._probe_check_table(table)
280
+ cols = self._probe_check_columns(columns, "structure_max_group_size")
281
+ count = self._probe_count()
282
+ group = ", ".join(self._probe_group_expr(table, c) for c in cols)
283
+ inner = f"SELECT {count}(*) AS n FROM {self._probe_table(table)} GROUP BY {group}"
284
+ return self._probe_scalar(f"SELECT MAX(g.n) AS m FROM ({inner}) g")
285
+
286
+ def structure_duplicate_group_rows(
287
+ self,
288
+ table: str,
289
+ key_columns: Sequence[ProbeColumn],
290
+ all_columns: Sequence[ProbeColumn],
291
+ max_groups: int = 3,
292
+ max_rows: int = 40,
293
+ ) -> Tuple[List[tuple], List[str]]:
294
+ """Rows of the first ``max_groups`` duplicate groups of ``key_columns``.
295
+
296
+ Groups with a NULL key column are filtered out before the group limit,
297
+ so they cannot take its slots and then match nothing. Each row leads
298
+ with ``_g``, the SQL group ordinal (1..max_groups), so the caller groups
299
+ rows as the engine did -- under its collation, trailing-space rules and
300
+ all -- not by comparing Python tuples.
301
+
302
+ :return: ``(rows, ["_g", *all_column_names])``, ordered by ``_g``.
303
+ """
304
+ self._probe_check_table(table)
305
+ keys = self._probe_check_columns(key_columns, "structure_duplicate_group_rows")
306
+ cols = self._probe_check_columns(all_columns, "structure_duplicate_group_rows")
307
+ max_groups = self._probe_check_positive(max_groups, "max_groups")
308
+ max_rows = self._probe_check_positive(max_rows, "max_rows")
309
+ count = self._probe_count()
310
+ table_sql = self._probe_table(table)
311
+
312
+ # The derived table's columns are synthetic (k_0.., _g) so no table
313
+ # column can collide with them. The group limit orders by the same
314
+ # qualified keys as ROW_NUMBER, not by the alias ``_g``, which a table
315
+ # column of that name could make ambiguous; groups are distinct, so
316
+ # the kept groups are exactly _g = 1..max_groups.
317
+ inner_keys = [self._probe_group_expr(table, k, "s") for k in keys]
318
+ outer_keys = [self._probe_group_expr(table, k, "t") for k in keys]
319
+ group = ", ".join(inner_keys)
320
+ inner_items = ", ".join(f"{expr} AS k_{i}" for i, expr in enumerate(inner_keys))
321
+ inner = self._probe_select(
322
+ f"{inner_items}, ROW_NUMBER() OVER (ORDER BY {group}) AS _g",
323
+ f"FROM {table_sql} s WHERE {self._probe_not_null(keys, 's')} "
324
+ f"GROUP BY {group} HAVING {count}(*) > 1 ORDER BY {group}",
325
+ max_groups,
326
+ )
327
+ on = " AND ".join(f"{expr} = d.k_{i}" for i, expr in enumerate(outer_keys))
328
+ items = ", ".join(["d._g"] + [self._probe_col(c, "t") for c in cols])
329
+ query = self._probe_select(items, f"FROM {table_sql} t JOIN ({inner}) d ON {on} ORDER BY d._g", max_rows)
330
+ rows, _ = self.fetchall_with_col_names(query)
331
+ return self.normalize_sample_rows(rows), ["_g"] + [c.name for c in cols]
332
+
333
+ def structure_distinct_tuple_count(
334
+ self, table: str, columns: Sequence[ProbeColumn], non_null_only: bool = False
335
+ ) -> int:
336
+ """How many distinct value tuples ``columns`` hold. With
337
+ ``non_null_only``, rows with a NULL in any of them are left out."""
338
+ self._probe_check_table(table)
339
+ cols = self._probe_check_columns(columns, "structure_distinct_tuple_count")
340
+ group = ", ".join(self._probe_group_expr(table, c) for c in cols)
341
+ where = f" WHERE {self._probe_not_null(cols)}" if non_null_only else ""
342
+ inner = f"SELECT 1 AS x FROM {self._probe_table(table)}{where} GROUP BY {group}"
343
+ return self._probe_scalar(f"SELECT {self._probe_count()}(*) AS n FROM ({inner}) d")
344
+
345
+ def structure_non_null_row_count(self, table: str, columns: Sequence[ProbeColumn]) -> int:
346
+ """How many rows have every one of ``columns`` non-NULL."""
347
+ self._probe_check_table(table)
348
+ cols = self._probe_check_columns(columns, "structure_non_null_row_count")
349
+ return self._probe_scalar(
350
+ f"SELECT {self._probe_count()}(*) AS n FROM {self._probe_table(table)} WHERE {self._probe_not_null(cols)}"
351
+ )
352
+
353
+ def structure_orphan_count(
354
+ self,
355
+ child_table: str,
356
+ child_columns: Sequence[ProbeColumn],
357
+ parent_table: str,
358
+ parent_columns: Sequence[ProbeColumn],
359
+ compare: str = "text",
360
+ binary: bool = False,
361
+ ) -> int:
362
+ """How many distinct non-NULL child key tuples have no matching parent row.
363
+
364
+ ``compare="text"`` compares the engine's text forms of both sides, so
365
+ columns of different declared types can be matched; ``binary=True``
366
+ makes that comparison exact where the engine has collations to
367
+ override. ``compare="native"`` compares the comparable expressions
368
+ directly (no cast for an ordinary column), which keeps index use; use
369
+ it only when both sides are declared identically.
370
+
371
+ :raises StructureProbeColumnUnsupported: before any SQL, when a column
372
+ has no comparable or text form.
373
+ """
374
+ if compare not in ORPHAN_COMPARE_MODES:
375
+ raise ValueError(f"compare must be one of {ORPHAN_COMPARE_MODES}, got {compare!r}")
376
+ if binary and compare != "text":
377
+ raise ValueError("binary applies only to compare='text'")
378
+ self._probe_check_table(child_table)
379
+ self._probe_check_table(parent_table)
380
+ child = self._probe_check_columns(child_columns, "structure_orphan_count")
381
+ parent = self._probe_check_columns(parent_columns, "structure_orphan_count")
382
+ if len(child) != len(parent):
383
+ raise ValueError(f"structure_orphan_count: {len(child)} child columns but {len(parent)} parent columns")
384
+
385
+ child_group = [self._probe_group_expr(child_table, c, "ch") for c in child]
386
+ if compare == "text":
387
+ pairs = [
388
+ (
389
+ self._probe_text_expr(parent_table, p, "p", binary),
390
+ self._probe_text_expr(child_table, c, "ch", binary),
391
+ )
392
+ for c, p in zip(child, parent)
393
+ ]
394
+ else:
395
+ pairs = [(self._probe_group_expr(parent_table, p, "p"), expr) for p, expr in zip(parent, child_group)]
396
+ on = " AND ".join(f"{p_expr} = {c_expr}" for p_expr, c_expr in pairs)
397
+ inner = (
398
+ f"SELECT 1 AS x FROM {self._probe_table(child_table)} ch "
399
+ f"WHERE {self._probe_not_null(child, 'ch')} "
400
+ f"AND NOT EXISTS (SELECT 1 FROM {self._probe_table(parent_table)} p WHERE {on}) "
401
+ f"GROUP BY {', '.join(child_group)}"
402
+ )
403
+ return self._probe_scalar(f"SELECT {self._probe_count()}(*) AS n FROM ({inner}) o")
404
+
405
+ def structure_session_setup(self, statement_timeout_s: int, read_only: bool = True) -> None:
406
+ """Bound every later query on this connection by ``statement_timeout_s``
407
+ seconds (0 disables the bound, as on both engines), and make the
408
+ session read-only where the engine has such a mode."""
409
+ if isinstance(statement_timeout_s, bool) or not isinstance(statement_timeout_s, int) or statement_timeout_s < 0:
410
+ raise ValueError(f"statement_timeout_s must be a non-negative integer, got {statement_timeout_s!r}")
411
+ self._probe_session_setup(statement_timeout_s, bool(read_only))