spark-sql-migrations 0.0.2__tar.gz → 0.0.3__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 (23) hide show
  1. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/PKG-INFO +5 -4
  2. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/setup.py +5 -4
  3. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations/__init__.py +2 -3
  4. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations/spark_sql/spark_sql.py +13 -4
  5. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations.egg-info/PKG-INFO +5 -4
  6. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations.egg-info/SOURCES.txt +0 -1
  7. spark_sql_migrations-0.0.2/spark_sql_migrations/custom_logging.py +0 -78
  8. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/LICENSE +0 -0
  9. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/MANIFEST.in +0 -0
  10. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/backend_shim.py +0 -0
  11. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/setup.cfg +0 -0
  12. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations/migration_templates/default_migration_template.sql +0 -0
  13. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations/migrations_initial/first_01_intial_create_cat_dbr_only.sql +0 -0
  14. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations/migrations_initial/first_02_intial_create_schema_all.sql +0 -0
  15. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations/migrations_initial/first_03_intial_create_state_table_all.sql +0 -0
  16. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations/py.typed +0 -0
  17. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations/spark_sql/__init__.py +0 -0
  18. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations/spark_utils.py +0 -0
  19. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations.egg-info/dependency_links.txt +0 -0
  20. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations.egg-info/entry_points.txt +0 -0
  21. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations.egg-info/namespace_packages.txt +0 -0
  22. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations.egg-info/requires.txt +0 -0
  23. {spark_sql_migrations-0.0.2 → spark_sql_migrations-0.0.3}/spark_sql_migrations.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spark_sql_migrations
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Chained, idempotent SQL migrations for Spark and Databricks.
5
5
  Home-page: https://github.com/mcjug2015/spark_sql_migrations
6
6
  Author: Victor Semenov
@@ -106,9 +106,10 @@ Choose deliberately. SQL that only Databricks understands must not live in
106
106
  spark-sql-migrations run --cat spark_catalog --schema default --migrations-dir path/to/migrations
107
107
  ```
108
108
 
109
- The command configures logging via `custom_logging.setup_logging()`, so each applied
110
- migration is logged to stdout and to `local_log.log` in the working directory (override
111
- with `SPARK_SQL_MIGRATIONS_LOG_FILE`). The command needs a Spark flavour installed; it
109
+ The command configures logging via `logging.basicConfig()`, so each applied migration is
110
+ logged to stderr at INFO. It leaves an already-configured root logger alone, and every
111
+ other entry point into this library inherits the host application's logging untouched.
112
+ The command needs a Spark flavour installed; it
112
113
  fails to import on a bare install. `python -m spark_sql_migrations.spark_sql.spark_sql`
113
114
  is equivalent.
114
115
 
@@ -110,9 +110,10 @@ spark-sql-migrations run \
110
110
  --migrations-dir path/to/migrations
111
111
  ```
112
112
 
113
- The command configures logging via `custom_logging.setup_logging()`, so each applied
114
- migration is logged to stdout and to `local_log.log` in the working directory (override
115
- with `SPARK_SQL_MIGRATIONS_LOG_FILE`). The command needs a Spark flavour installed; it
113
+ The command configures logging via `logging.basicConfig()`, so each applied migration is
114
+ logged to stderr at INFO. It leaves an already-configured root logger alone, and every
115
+ other entry point into this library inherits the host application's logging untouched.
116
+ The command needs a Spark flavour installed; it
116
117
  fails to import on a bare install. `python -m spark_sql_migrations.spark_sql.spark_sql`
117
118
  is equivalent.
118
119
 
@@ -251,5 +252,5 @@ Apache License 2.0 — see [LICENSE](LICENSE).
251
252
  },
252
253
  'python_requires': '>=3.10',
253
254
  'url': 'https://github.com/mcjug2015/spark_sql_migrations',
254
- 'version': '0.0.2',
255
+ 'version': '0.0.3',
255
256
  })
@@ -2,7 +2,6 @@ import logging
2
2
 
3
3
  # A library must not configure logging when it is imported. A NullHandler on the
4
4
  # package root keeps our records off logging.lastResort while leaving every
5
- # decision about handlers, levels and formats to the host application. An
6
- # application that wants our opinionated setup calls
7
- # spark_sql_migrations.custom_logging.setup_logging() from its own entry point.
5
+ # decision about handlers, levels and formats to the host application, which
6
+ # configures logging from its own entry point.
8
7
  logging.getLogger(__name__).addHandler(logging.NullHandler())
@@ -24,7 +24,6 @@ from dataclasses import dataclass
24
24
  from jinja2 import Environment, FileSystemLoader, PackageLoader, select_autoescape
25
25
  from pyspark.sql.functions import col
26
26
 
27
- from spark_sql_migrations import custom_logging
28
27
  from spark_sql_migrations.spark_utils import get_spark, is_dbr
29
28
 
30
29
  logger = logging.getLogger(__name__)
@@ -261,7 +260,11 @@ def record_revision(spark, cat: str, schema: str, migration_type: str, revision_
261
260
 
262
261
 
263
262
  def migrate_w_rev(spark, output_folder, migrations_root, cat: str, schema: str, migration_type: str):
264
- """apply the migrations of one client chain that VERSION_TABLE hasn't recorded yet."""
263
+ """
264
+ apply the migrations of one client chain that VERSION_TABLE hasn't recorded yet.
265
+ TODO XXX permit applying up to a revision below the head revision
266
+ TODO XXX add backwards migrations, permit migrating backwards
267
+ """
265
268
  migrations_dir = get_migrations_dir(migrations_root, migration_type)
266
269
  unapplied = get_unapplied_migrations_list(spark, migrations_dir, migration_type, cat=cat, schema=schema)
267
270
 
@@ -330,9 +333,15 @@ def cli(argv=None): # pragma: no cover
330
333
  """the `spark-sql-migrations` console command.
331
334
 
332
335
  an application entry point, so unlike the rest of this package it configures
333
- logging -- see custom_logging's module docstring.
336
+ logging. basicConfig is a no-op once the root logger has handlers, which keeps
337
+ this from clobbering a host application that got there first.
334
338
  """
335
- custom_logging.setup_logging()
339
+ logging.basicConfig(
340
+ level=logging.INFO,
341
+ format="%(levelname)s %(asctime)s %(name)s : %(message)s",
342
+ datefmt="%y/%m/%d %H:%M:%S",
343
+ )
344
+ logging.getLogger("py4j").setLevel(logging.ERROR)
336
345
  kwargs = vars(build_parser().parse_args(argv))
337
346
  func = kwargs.pop("func")
338
347
  kwargs.pop("command")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: spark_sql_migrations
3
- Version: 0.0.2
3
+ Version: 0.0.3
4
4
  Summary: Chained, idempotent SQL migrations for Spark and Databricks.
5
5
  Home-page: https://github.com/mcjug2015/spark_sql_migrations
6
6
  Author: Victor Semenov
@@ -106,9 +106,10 @@ Choose deliberately. SQL that only Databricks understands must not live in
106
106
  spark-sql-migrations run --cat spark_catalog --schema default --migrations-dir path/to/migrations
107
107
  ```
108
108
 
109
- The command configures logging via `custom_logging.setup_logging()`, so each applied
110
- migration is logged to stdout and to `local_log.log` in the working directory (override
111
- with `SPARK_SQL_MIGRATIONS_LOG_FILE`). The command needs a Spark flavour installed; it
109
+ The command configures logging via `logging.basicConfig()`, so each applied migration is
110
+ logged to stderr at INFO. It leaves an already-configured root logger alone, and every
111
+ other entry point into this library inherits the host application's logging untouched.
112
+ The command needs a Spark flavour installed; it
112
113
  fails to import on a bare install. `python -m spark_sql_migrations.spark_sql.spark_sql`
113
114
  is equivalent.
114
115
 
@@ -3,7 +3,6 @@ MANIFEST.in
3
3
  backend_shim.py
4
4
  setup.py
5
5
  spark_sql_migrations/__init__.py
6
- spark_sql_migrations/custom_logging.py
7
6
  spark_sql_migrations/py.typed
8
7
  spark_sql_migrations/spark_utils.py
9
8
  spark_sql_migrations.egg-info/PKG-INFO
@@ -1,78 +0,0 @@
1
- """Opinionated logging configuration, for *applications* to opt into.
2
-
3
- Importing spark_sql_migrations never configures logging: library modules take a plain
4
- ``logging.getLogger(__name__)`` and inherit whatever the host application set
5
- up. An application that wants this format calls :func:`setup_logging` from its
6
- own entry point -- never at import time, and never from library code, because
7
- configuring the root logger is the application's decision to make.
8
- """
9
-
10
- import logging.config
11
- import os
12
-
13
- LOG_FILE_ENV_VAR = "SPARK_SQL_MIGRATIONS_LOG_FILE"
14
- DEFAULT_LOG_FILENAME = "local_log.log"
15
-
16
- FORMAT = "%(levelname)s %(asctime)s %(filename)s->%(funcName)s->%(lineno)d : %(message)s"
17
-
18
-
19
- def get_log_file_path():
20
- """where the file handler writes.
21
-
22
- resolved against the caller's cwd for the same reason as the spark warehouse
23
- dir: a __file__-relative default would land inside site-packages once this
24
- is installed from a wheel.
25
- """
26
- return os.environ.get(LOG_FILE_ENV_VAR, os.path.join(os.getcwd(), DEFAULT_LOG_FILENAME))
27
-
28
-
29
- def build_config():
30
- """built per call, not a module constant: get_log_file_path() reads the
31
- environment, and at module-import time the consumer hasn't set it yet."""
32
- return {
33
- "version": 1,
34
- "disable_existing_loggers": False,
35
- "formatters": {
36
- "simple": {
37
- "format": FORMAT,
38
- "datefmt": "%y/%m/%d %H:%M:%S",
39
- }
40
- },
41
- "handlers": {
42
- "stdout": {
43
- "class": "logging.StreamHandler",
44
- "level": "INFO",
45
- "formatter": "simple",
46
- "stream": "ext://sys.stdout",
47
- },
48
- "stderr": {
49
- "class": "logging.StreamHandler",
50
- "level": "ERROR",
51
- "formatter": "simple",
52
- "stream": "ext://sys.stderr",
53
- },
54
- "file": {
55
- "class": "logging.FileHandler",
56
- "formatter": "simple",
57
- "filename": get_log_file_path(),
58
- "mode": "a",
59
- },
60
- },
61
- "root": {"level": "DEBUG", "handlers": ["stderr", "stdout", "file"]},
62
- }
63
-
64
-
65
- def is_logging_configured():
66
- # Check if the root logger has any handlers explicitly assigned
67
- return len(logging.getLogger().handlers) >= 3
68
-
69
-
70
- def setup_logging():
71
- """configure the root logger with our handlers; safe to call more than once.
72
-
73
- for application entry points only -- see the module docstring.
74
- """
75
- if not is_logging_configured():
76
- logging.config.dictConfig(build_config())
77
- logging.getLogger("py4j").setLevel(logging.ERROR)
78
- return logging