soda-postgres 4.28.0__tar.gz → 4.30.0__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.
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/PKG-INFO +2 -2
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/pyproject.toml +2 -2
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/src/soda_postgres/common/data_sources/postgres_data_source.py +114 -0
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/src/soda_postgres/statements/postgres_metadata_tables_query.py +1 -0
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/src/soda_postgres.egg-info/PKG-INFO +2 -2
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/src/soda_postgres.egg-info/requires.txt +1 -1
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/setup.cfg +0 -0
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/src/soda_postgres/common/data_sources/postgres_data_source_connection.py +0 -0
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/src/soda_postgres/statements/postgres_metadata_primary_keys_query.py +0 -0
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/src/soda_postgres/test_helpers/postgres_data_source_test_helper.py +0 -0
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/src/soda_postgres.egg-info/SOURCES.txt +0 -0
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/src/soda_postgres.egg-info/dependency_links.txt +0 -0
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/src/soda_postgres.egg-info/entry_points.txt +0 -0
- {soda_postgres-4.28.0 → soda_postgres-4.30.0}/src/soda_postgres.egg-info/top_level.txt +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: soda-postgres
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.30.0
|
|
4
4
|
Summary: Soda Postgres V4
|
|
5
5
|
Author-email: "Soda Data N.V." <info@soda.io>
|
|
6
6
|
License: Proprietary
|
|
7
7
|
Requires-Python: >=3.10
|
|
8
|
-
Requires-Dist: soda-core==4.
|
|
8
|
+
Requires-Dist: soda-core==4.30.0
|
|
9
9
|
Requires-Dist: psycopg[binary]>=3.2
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "soda-postgres"
|
|
3
|
-
version = "4.
|
|
3
|
+
version = "4.30.0"
|
|
4
4
|
description = "Soda Postgres V4"
|
|
5
5
|
requires-python = ">=3.10"
|
|
6
6
|
license = {text = "Proprietary"}
|
|
@@ -8,7 +8,7 @@ authors = [
|
|
|
8
8
|
{name = "Soda Data N.V.", email = "info@soda.io"}
|
|
9
9
|
]
|
|
10
10
|
dependencies = [
|
|
11
|
-
"soda-core==4.
|
|
11
|
+
"soda-core==4.30.0",
|
|
12
12
|
"psycopg[binary]>=3.2",
|
|
13
13
|
]
|
|
14
14
|
|
|
@@ -7,21 +7,36 @@ from soda_core.common.data_source_impl import DataSourceImpl
|
|
|
7
7
|
from soda_core.common.logging_constants import soda_logger
|
|
8
8
|
from soda_core.common.metadata_types import DataSourceNamespace, SamplerType, SodaDataTypeName, SqlDataType
|
|
9
9
|
from soda_core.common.sql_ast import (
|
|
10
|
+
ANALYZE_TABLE,
|
|
10
11
|
AND,
|
|
12
|
+
ASSIGNMENT,
|
|
11
13
|
CAST,
|
|
12
14
|
COLUMN,
|
|
15
|
+
CREATE_INDEX_IF_NOT_EXISTS,
|
|
16
|
+
CREATE_TABLE,
|
|
13
17
|
CREATE_TABLE_COLUMN,
|
|
18
|
+
CREATE_TABLE_IF_NOT_EXISTS,
|
|
19
|
+
DATE_ISO_TEXT,
|
|
20
|
+
DATE_TRUNC,
|
|
21
|
+
EPOCH_SECONDS,
|
|
14
22
|
EQ,
|
|
15
23
|
FROM,
|
|
16
24
|
GT,
|
|
17
25
|
IN,
|
|
18
26
|
JOIN,
|
|
27
|
+
JSON_MERGE,
|
|
19
28
|
LEFT_INNER_JOIN,
|
|
20
29
|
LITERAL,
|
|
21
30
|
LOWER,
|
|
22
31
|
ORDER_BY_ASC,
|
|
23
32
|
RAW_SQL,
|
|
33
|
+
REGEXP_REPLACE,
|
|
24
34
|
SELECT,
|
|
35
|
+
SOURCE_COLUMN,
|
|
36
|
+
TIMESTAMP_ISO_TEXT,
|
|
37
|
+
TO_TIMEZONE,
|
|
38
|
+
UPSERT,
|
|
39
|
+
UPSERT_VIA_SELECT,
|
|
25
40
|
WHERE,
|
|
26
41
|
)
|
|
27
42
|
from soda_core.common.sql_dialect import SqlDialect
|
|
@@ -81,6 +96,7 @@ class PostgresSqlDialect(SqlDialect, sqlglot_dialect="postgres"):
|
|
|
81
96
|
(SodaDataTypeName.NUMERIC, SodaDataTypeName.DECIMAL),
|
|
82
97
|
(SodaDataTypeName.DOUBLE, SodaDataTypeName.FLOAT),
|
|
83
98
|
)
|
|
99
|
+
SUPPORTS_DATA_PLANE_STATEMENTS = True
|
|
84
100
|
|
|
85
101
|
def supports_materialized_views(self) -> bool:
|
|
86
102
|
return True
|
|
@@ -216,6 +232,90 @@ class PostgresSqlDialect(SqlDialect, sqlglot_dialect="postgres"):
|
|
|
216
232
|
|
|
217
233
|
return super().is_same_soda_data_type_with_synonyms(expected, actual)
|
|
218
234
|
|
|
235
|
+
###
|
|
236
|
+
# Data plane statements
|
|
237
|
+
###
|
|
238
|
+
def _build_create_table_storage_sql(self, create_table: CREATE_TABLE | CREATE_TABLE_IF_NOT_EXISTS) -> str:
|
|
239
|
+
# Free space on each page lets an update that changes no indexed column put the new row
|
|
240
|
+
# version on the same page (a HOT update), so it adds no index entries.
|
|
241
|
+
return "WITH (fillfactor = 70)" if create_table.update_heavy else ""
|
|
242
|
+
|
|
243
|
+
def _build_upsert_sql(self, upsert: UPSERT) -> str:
|
|
244
|
+
target_sql: str = self._build_statement_target_sql(upsert.fully_qualified_table_name, upsert.alias)
|
|
245
|
+
insert_sql: str = f"INSERT INTO {target_sql}"
|
|
246
|
+
insert_sql += self._build_insert_into_columns_sql(upsert)
|
|
247
|
+
insert_sql += self._build_insert_into_values_sql(upsert)
|
|
248
|
+
return f"{insert_sql}\n{self._build_on_conflict_sql(upsert.key_columns, upsert.update_assignments)}"
|
|
249
|
+
|
|
250
|
+
def _build_upsert_via_select_sql(self, upsert_via_select: UPSERT_VIA_SELECT) -> str:
|
|
251
|
+
target_sql: str = self._build_statement_target_sql(
|
|
252
|
+
upsert_via_select.fully_qualified_table_name, upsert_via_select.alias
|
|
253
|
+
)
|
|
254
|
+
insert_sql: str = f"INSERT INTO {target_sql}\n"
|
|
255
|
+
insert_sql += self._build_insert_into_columns_sql(upsert_via_select) + "\n"
|
|
256
|
+
insert_sql += "(\n" + self.build_select_sql(upsert_via_select.select_elements, add_semicolon=False) + "\n)"
|
|
257
|
+
on_conflict_sql: str = self._build_on_conflict_sql(
|
|
258
|
+
upsert_via_select.key_columns, upsert_via_select.update_assignments
|
|
259
|
+
)
|
|
260
|
+
return f"{insert_sql}\n{on_conflict_sql}"
|
|
261
|
+
|
|
262
|
+
def _build_on_conflict_sql(self, key_columns: list[COLUMN], update_assignments: Optional[list[ASSIGNMENT]]) -> str:
|
|
263
|
+
# The key columns must carry a unique index or constraint: it is the conflict arbiter. The
|
|
264
|
+
# conflict target takes bare column names, so a table alias is dropped.
|
|
265
|
+
key_columns_sql: str = ", ".join(
|
|
266
|
+
self.quote_default(column.name) if isinstance(column.name, str) else self.build_expression_sql(column.name)
|
|
267
|
+
for column in key_columns
|
|
268
|
+
)
|
|
269
|
+
if not update_assignments:
|
|
270
|
+
return f"ON CONFLICT ({key_columns_sql}) DO NOTHING"
|
|
271
|
+
return f"ON CONFLICT ({key_columns_sql}) DO UPDATE SET {self._build_assignments_sql(update_assignments)}"
|
|
272
|
+
|
|
273
|
+
def _build_source_column_sql(self, source_column: SOURCE_COLUMN) -> str:
|
|
274
|
+
return f"EXCLUDED.{self.quote_default(source_column.name)}"
|
|
275
|
+
|
|
276
|
+
def _build_create_index_sql(self, create_index: CREATE_INDEX_IF_NOT_EXISTS) -> Optional[str]:
|
|
277
|
+
index_name: str = self.quote_for_ddl(create_index.index_name)
|
|
278
|
+
table_name: str = self._convert_fqn_for_ddl(create_index.fully_qualified_table_name)
|
|
279
|
+
columns_sql: str = self._build_index_columns_sql(create_index.columns)
|
|
280
|
+
return f"CREATE INDEX IF NOT EXISTS {index_name} ON {table_name} {columns_sql}"
|
|
281
|
+
|
|
282
|
+
def _build_analyze_table_sql(self, analyze_table: ANALYZE_TABLE) -> Optional[str]:
|
|
283
|
+
return f"ANALYZE {self._convert_fqn_for_ddl(analyze_table.fully_qualified_table_name)}"
|
|
284
|
+
|
|
285
|
+
def _build_regexp_replace_sql(self, regexp_replace: REGEXP_REPLACE) -> str:
|
|
286
|
+
# Without the "g" flag Postgres replaces only the first match.
|
|
287
|
+
expression_sql: str = self.build_expression_sql(regexp_replace.expression)
|
|
288
|
+
pattern_sql: str = self.literal_string(regexp_replace.pattern)
|
|
289
|
+
replacement_sql: str = self.literal_string(regexp_replace.replacement)
|
|
290
|
+
return f"regexp_replace({expression_sql}, {pattern_sql}, {replacement_sql}, 'g')"
|
|
291
|
+
|
|
292
|
+
def _build_date_trunc_sql(self, date_trunc: DATE_TRUNC) -> str:
|
|
293
|
+
return f"date_trunc({self.literal_string(date_trunc.unit)}, {self.build_expression_sql(date_trunc.expression)})"
|
|
294
|
+
|
|
295
|
+
def _build_to_timezone_sql(self, to_timezone: TO_TIMEZONE) -> str:
|
|
296
|
+
expression_sql: str = self.build_expression_sql(to_timezone.expression)
|
|
297
|
+
return f"({expression_sql} AT TIME ZONE {self.literal_string(to_timezone.timezone)})"
|
|
298
|
+
|
|
299
|
+
def _build_epoch_seconds_sql(self, epoch_seconds: EPOCH_SECONDS) -> str:
|
|
300
|
+
return f"EXTRACT(EPOCH FROM {self.build_expression_sql(epoch_seconds.expression)})"
|
|
301
|
+
|
|
302
|
+
def _build_timestamp_iso_text_sql(self, timestamp_iso_text: TIMESTAMP_ISO_TEXT) -> str:
|
|
303
|
+
# Double-quoted text in a to_char format is output literally.
|
|
304
|
+
iso_format: str = 'YYYY-MM-DD"T"HH24:MI:SS'
|
|
305
|
+
if timestamp_iso_text.fractional_seconds:
|
|
306
|
+
iso_format += ".US"
|
|
307
|
+
if timestamp_iso_text.utc_suffix:
|
|
308
|
+
iso_format += '"+00:00"'
|
|
309
|
+
expression_sql: str = self.build_expression_sql(timestamp_iso_text.expression)
|
|
310
|
+
return f"to_char({expression_sql}, {self.literal_string(iso_format)})"
|
|
311
|
+
|
|
312
|
+
def _build_date_iso_text_sql(self, date_iso_text: DATE_ISO_TEXT) -> str:
|
|
313
|
+
return f"to_char({self.build_expression_sql(date_iso_text.expression)}, 'YYYY-MM-DD')"
|
|
314
|
+
|
|
315
|
+
def _build_json_merge_sql(self, json_merge: JSON_MERGE) -> str:
|
|
316
|
+
# jsonb ||: the union of both objects' keys, the right one's value winning on a duplicate.
|
|
317
|
+
return f"({self.build_expression_sql(json_merge.left)} || {self.build_expression_sql(json_merge.right)})"
|
|
318
|
+
|
|
219
319
|
###
|
|
220
320
|
# Tables and columns metadata queries
|
|
221
321
|
###
|
|
@@ -231,6 +331,18 @@ class PostgresSqlDialect(SqlDialect, sqlglot_dialect="postgres"):
|
|
|
231
331
|
def _current_database(self) -> str:
|
|
232
332
|
return "current_database()"
|
|
233
333
|
|
|
334
|
+
def readable_relation_sql_condition(self) -> str:
|
|
335
|
+
# pg_catalog shows every role all names, so keep only what this role can SELECT * from, as scans do: a table
|
|
336
|
+
# grant, or a grant on every column. has_any_column_privilege hides a table with no columns and no grant, and
|
|
337
|
+
# NOT x.attisdropped skips dropped columns. Expects pg_class aliased as c and pg_namespace as n.
|
|
338
|
+
return """(has_schema_privilege(n.oid, 'USAGE')
|
|
339
|
+
AND (has_table_privilege(c.oid, 'SELECT')
|
|
340
|
+
OR (has_any_column_privilege(c.oid, 'SELECT')
|
|
341
|
+
AND NOT EXISTS (
|
|
342
|
+
SELECT 1 FROM pg_catalog.pg_attribute x
|
|
343
|
+
WHERE x.attrelid = c.oid AND x.attnum > 0 AND NOT x.attisdropped
|
|
344
|
+
AND NOT has_column_privilege(c.oid, x.attnum, 'SELECT')))))"""
|
|
345
|
+
|
|
234
346
|
def relkind_table_type_sql_expression(self, table_alias: str = "c", column_alias: str = "table_type") -> str:
|
|
235
347
|
return f"""CASE {table_alias}.relkind
|
|
236
348
|
WHEN 'r' THEN
|
|
@@ -364,6 +476,8 @@ class PostgresSqlDialect(SqlDialect, sqlglot_dialect="postgres"):
|
|
|
364
476
|
[LITERAL("r"), LITERAL("p"), LITERAL("v"), LITERAL("m"), LITERAL("f")],
|
|
365
477
|
),
|
|
366
478
|
GT(COLUMN("attnum", "a"), LITERAL(0)),
|
|
479
|
+
# A table's columns show in full or not at all, same as the tables it is discovered with.
|
|
480
|
+
RAW_SQL(self.readable_relation_sql_condition()),
|
|
367
481
|
]
|
|
368
482
|
if table_name:
|
|
369
483
|
where_conditions.append(EQ(COLUMN("relname", "c"), LITERAL(self.metadata_casify(table_name))))
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: soda-postgres
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.30.0
|
|
4
4
|
Summary: Soda Postgres V4
|
|
5
5
|
Author-email: "Soda Data N.V." <info@soda.io>
|
|
6
6
|
License: Proprietary
|
|
7
7
|
Requires-Python: >=3.10
|
|
8
|
-
Requires-Dist: soda-core==4.
|
|
8
|
+
Requires-Dist: soda-core==4.30.0
|
|
9
9
|
Requires-Dist: psycopg[binary]>=3.2
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
soda-core==4.
|
|
1
|
+
soda-core==4.30.0
|
|
2
2
|
psycopg[binary]>=3.2
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{soda_postgres-4.28.0 → soda_postgres-4.30.0}/src/soda_postgres.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|