MCPcopy Index your code
hub / github.com/pathwaycom/pathway / write_snapshot

Function write_snapshot

python/pathway/io/postgres/__init__.py:897–1051  ·  view source on GitHub ↗

**WARNING**: This method is deprecated. Please use ``pw.io.postgres.write`` with the parameter ``output_table_type="snapshot"`` instead. Note that the new version does not create the ``time`` and ``diff`` columns and maintains a current snapshot of the table you are writing. Maintai

(
    table: Table,
    postgres_settings: dict,
    table_name: str,
    primary_key: list[str],
    *,
    max_batch_size: int | None = None,
    init_mode: Literal["default", "create_if_not_exists", "replace"] = "default",
    name: str | None = None,
    sort_by: Iterable[ColumnReference] | None = None,
    _external_diff_column: ColumnReference | None = None,
)

Source from the content-addressed store, hash-verified

895
896@check_arg_types
897def write_snapshot(
898 table: Table,
899 postgres_settings: dict,
900 table_name: str,
901 primary_key: list[str],
902 *,
903 max_batch_size: int | None = None,
904 init_mode: Literal["default", "create_if_not_exists", "replace"] = "default",
905 name: str | None = None,
906 sort_by: Iterable[ColumnReference] | None = None,
907 _external_diff_column: ColumnReference | None = None,
908) -> None:
909 """**WARNING**: This method is deprecated. Please use ``pw.io.postgres.write`` with
910 the parameter ``output_table_type="snapshot"`` instead. Note that the new version
911 does not create the ``time`` and ``diff`` columns and maintains a current snapshot
912 of the table you are writing.
913
914 Maintains a snapshot of a table within a Postgres table.
915
916 In order for write to be successful, it is required that the table contains ``time``
917 and ``diff`` columns of the integer type.
918
919 Args:
920 postgres_settings: Components of the connection string for Postgres.
921 table_name: Name of the target table.
922 primary_key: Names of the fields which serve as a primary key in the Postgres table.
923 max_batch_size: Maximum number of entries allowed to be committed within a
924 single transaction.
925 init_mode: "default": The default initialization mode;
926 "create_if_not_exists": initializes the SQL writer by creating the necessary table
927 if they do not already exist;
928 "replace": Initializes the SQL writer by replacing any existing table.
929 name: A unique name for the connector. If provided, this name will be used in
930 logs and monitoring dashboards.
931 sort_by: If specified, the output will be sorted in ascending order based on the
932 values of the given columns within each minibatch. When multiple columns are provided,
933 the corresponding value tuples will be compared lexicographically.
934
935 Returns:
936 None
937
938 Example:
939
940 Consider there is a table ``stats`` in the Pathway Live Data Framework, containing the average
941 number of requests to some
942 service or operation per user, over some period of time. The number of requests
943 can be large, so we decide not to store the whole stream of changes, but to only store
944 a snapshot of the data, which can be actualized by the Pathway Live Data Framework.
945
946 The minimum set-up would require us to have a Postgres table with two columns: the ID
947 of the user ``user_id`` and the number of requests across some period of time ``number_of_requests``.
948 In order to maintain consistency, we also need two extra columns: ``time`` and ``diff``.
949
950 The SQL for the creation of such table would look as follows:
951
952 .. code-block:: sql
953
954 CREATE TABLE user_stats (

Callers

nothing calls this directly

Calls 9

init_mode_from_strFunction · 0.90
get_column_indexFunction · 0.90
countMethod · 0.80
lowerMethod · 0.80
toMethod · 0.80
column_namesMethod · 0.45

Tested by

no test coverage detected