salesforce-data-customcode 6.1.0.dev7__tar.gz → 7.0.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.
Files changed (137) hide show
  1. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/PKG-INFO +59 -3
  2. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/README.md +58 -2
  3. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/pyproject.toml +1 -1
  4. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/__init__.py +15 -0
  5. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/client.py +28 -7
  6. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/config.yaml +2 -0
  7. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/deploy.py +11 -16
  8. salesforce_data_customcode-7.0.0/src/datacustomcode/io/cdf.py +34 -0
  9. salesforce_data_customcode-7.0.0/src/datacustomcode/io/reader/local_deltas.py +164 -0
  10. salesforce_data_customcode-7.0.0/src/datacustomcode/io/reader/streaming_seeder.py +114 -0
  11. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/io/writer/base.py +33 -1
  12. salesforce_data_customcode-7.0.0/src/datacustomcode/io/writer/local_deltas.py +133 -0
  13. salesforce_data_customcode-7.0.0/src/datacustomcode/lineage/__init__.py +137 -0
  14. salesforce_data_customcode-7.0.0/src/datacustomcode/lineage/_worker.py +97 -0
  15. salesforce_data_customcode-7.0.0/src/datacustomcode/lineage/capture.py +289 -0
  16. salesforce_data_customcode-7.0.0/src/datacustomcode/lineage/tracer.py +566 -0
  17. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/run.py +85 -1
  18. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/scan.py +26 -6
  19. salesforce_data_customcode-7.0.0/src/datacustomcode/spark/column_hints.py +194 -0
  20. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/template.py +20 -0
  21. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/examples/external_callout/README.md +31 -2
  22. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/LICENSE.txt +0 -0
  23. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/auth.py +0 -0
  24. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/cli.py +0 -0
  25. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/cmd.py +0 -0
  26. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/common_config.py +0 -0
  27. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/config.py +0 -0
  28. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/constants.py +0 -0
  29. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/credentials.py +0 -0
  30. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/einstein_platform_client.py +0 -0
  31. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/einstein_platform_config.py +0 -0
  32. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/einstein_predictions/__init__.py +0 -0
  33. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/einstein_predictions/base.py +0 -0
  34. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/einstein_predictions/errors.py +0 -0
  35. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/einstein_predictions/impl/default.py +0 -0
  36. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/einstein_predictions/spark_base.py +0 -0
  37. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/einstein_predictions/spark_default.py +0 -0
  38. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/einstein_predictions/types.py +0 -0
  39. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/einstein_predictions_config.py +0 -0
  40. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/file/__init__.py +0 -0
  41. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/file/base.py +0 -0
  42. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/file/path/__init__.py +0 -0
  43. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/file/path/default.py +0 -0
  44. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/function/__init__.py +0 -0
  45. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/function/base.py +0 -0
  46. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/function/feature_types/__init__.py +0 -0
  47. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/function/feature_types/chunking.py +0 -0
  48. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/function/runtime.py +0 -0
  49. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/function_utils.py +0 -0
  50. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/io/__init__.py +0 -0
  51. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/io/base.py +0 -0
  52. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/io/reader/__init__.py +0 -0
  53. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/io/reader/base.py +0 -0
  54. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/io/reader/query_api.py +0 -0
  55. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/io/reader/sf_cli.py +0 -0
  56. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/io/reader/utils.py +0 -0
  57. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/io/writer/__init__.py +0 -0
  58. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/io/writer/csv.py +0 -0
  59. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/io/writer/print.py +0 -0
  60. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/llm_gateway/__init__.py +0 -0
  61. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/llm_gateway/base.py +0 -0
  62. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/llm_gateway/default.py +0 -0
  63. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/llm_gateway/errors.py +0 -0
  64. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/llm_gateway/spark_base.py +0 -0
  65. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/llm_gateway/spark_default.py +0 -0
  66. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/llm_gateway/types/__init__.py +0 -0
  67. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/llm_gateway/types/generate_text_request.py +0 -0
  68. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/llm_gateway/types/generate_text_request_builder.py +0 -0
  69. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/llm_gateway/types/generate_text_response.py +0 -0
  70. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/llm_gateway/types/generate_text_response_builder.py +0 -0
  71. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/llm_gateway_config.py +0 -0
  72. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/mixin.py +0 -0
  73. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/__init__.py +0 -0
  74. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/base.py +0 -0
  75. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/default.py +0 -0
  76. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/direct/__init__.py +0 -0
  77. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/direct/auth.py +0 -0
  78. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/direct/credentials.py +0 -0
  79. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/direct/transport.py +0 -0
  80. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/direct/url_resolver.py +0 -0
  81. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/errors.py +0 -0
  82. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/spark_base.py +0 -0
  83. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/spark_default.py +0 -0
  84. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/types/__init__.py +0 -0
  85. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/types/http_method.py +0 -0
  86. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/types/http_request.py +0 -0
  87. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/types/http_request_builder.py +0 -0
  88. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/types/http_response.py +0 -0
  89. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential/types/http_response_builder.py +0 -0
  90. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/named_credential_config.py +0 -0
  91. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/py.typed +0 -0
  92. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/spark/__init__.py +0 -0
  93. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/spark/base.py +0 -0
  94. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/spark/default.py +0 -0
  95. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/__init__.py +0 -0
  96. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/.devcontainer/devcontainer.json +0 -0
  97. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/Dockerfile.dependencies +0 -0
  98. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/README.md +0 -0
  99. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/build_native_dependencies.sh +0 -0
  100. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/chunking/payload/config.json +0 -0
  101. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/chunking/payload/entrypoint.py +0 -0
  102. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/chunking/requirements.txt +0 -0
  103. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/example/chunking_with_external_callout/README.md +0 -0
  104. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/example/chunking_with_external_callout/config.json +0 -0
  105. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/example/chunking_with_external_callout/entrypoint.py +0 -0
  106. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/example/chunking_with_external_callout/external_callout_config.json +0 -0
  107. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/example/chunking_with_external_callout/tests/test.json +0 -0
  108. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/example/chunking_with_llm/config.json +0 -0
  109. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/example/chunking_with_llm/entrypoint.py +0 -0
  110. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/example/chunking_with_llm/files/chunking_prompt.txt +0 -0
  111. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/example/chunking_with_llm/tests/test.json +0 -0
  112. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/example/chunking_with_prediction/config.json +0 -0
  113. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/example/chunking_with_prediction/entrypoint.py +0 -0
  114. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/example/chunking_with_prediction/tests/test.json +0 -0
  115. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/payload/config.json +0 -0
  116. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/payload/entrypoint.py +0 -0
  117. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/payload/utility.py +0 -0
  118. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/requirements-dev.txt +0 -0
  119. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/function/requirements.txt +0 -0
  120. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/.devcontainer/devcontainer.json +0 -0
  121. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/Dockerfile +0 -0
  122. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/Dockerfile.dependencies +0 -0
  123. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/README.md +0 -0
  124. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/account.ipynb +0 -0
  125. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/build_native_dependencies.sh +0 -0
  126. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/examples/employee_hierarchy/employee_data.csv +0 -0
  127. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/examples/employee_hierarchy/entrypoint.py +0 -0
  128. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/examples/external_callout/entrypoint.py +0 -0
  129. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/examples/external_callout/external_callout_config.json +0 -0
  130. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/examples/streaming_deltas/entrypoint.py +0 -0
  131. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/jupyterlab.sh +0 -0
  132. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/payload/config.json +0 -0
  133. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/payload/entrypoint.py +0 -0
  134. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/requirements-dev.txt +0 -0
  135. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/templates/script/requirements.txt +0 -0
  136. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/token_provider.py +0 -0
  137. {salesforce_data_customcode-6.1.0.dev7 → salesforce_data_customcode-7.0.0}/src/datacustomcode/version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: salesforce-data-customcode
3
- Version: 6.1.0.dev7
3
+ Version: 7.0.0
4
4
  Summary: Data Cloud Custom Code SDK
5
5
  License-Expression: Apache-2.0
6
6
  License-File: LICENSE.txt
@@ -176,13 +176,14 @@ For a batch transform, use `Client`. You should only need the following methods:
176
176
  * `find_file_path(file_name)` – Resolve a bundled file (placed under `payload/files/`) to a `pathlib.Path` that exists. Works the same locally and inside Data Cloud — see [Bundled file resolution](#bundled-file-resolution) below for the full lookup order. Raises `FileNotFoundError` if the file isn't found.
177
177
  * `read_dlo(name)` – Read from a Data Lake Object by name
178
178
  * `read_dmo(name)` – Read from a Data Model Object by name
179
- * `write_to_dlo(name, spark_dataframe, write_mode)` – Write to a Data Model Object by name with a Spark dataframe
180
- * `write_to_dmo(name, spark_dataframe, write_mode)` – Write to a Data Lake Object by name with a Spark dataframe
179
+ * `write_to_dlo(name, spark_dataframe, write_mode)` – Write to a Data Lake Object by name with a Spark dataframe
180
+ * `write_to_dmo(name, spark_dataframe, write_mode)` – Write to a Data Model Object by name with a Spark dataframe
181
181
 
182
182
  For a streaming (delta) transform, use `StreamingClient`, which exposes the streaming counterparts:
183
183
  * `read_dlo_deltas()` – Read the streaming change feed (deltas) of a Data Lake Object as a streaming DataFrame.
184
184
  * `read_dmo_deltas()` – Read the streaming change feed (deltas) of a Data Model Object as a streaming DataFrame.
185
185
  * `write_dlo_deltas(name, spark_dataframe)` – Write a streaming DataFrame of deltas to a Data Lake Object; returns the started `StreamingQuery`
186
+ * `write_dmo_deltas(name, spark_dataframe)` – Write a streaming DataFrame of deltas to a Data Model Object; returns the started `StreamingQuery`
186
187
 
187
188
  `find_file_path`, `llm_gateway_generate_text`, and `einstein_predict` are available on both clients.
188
189
 
@@ -201,6 +202,27 @@ client.write_to_dlo('output_DLO')
201
202
  > [!WARNING]
202
203
  > Currently we only support reading from DMOs and writing to DMOs or reading from DLOs and writing to DLOs, but they cannot mix.
203
204
 
205
+ ### Writing Currency fields
206
+
207
+ A DLO or DMO with a Currency field has a system field, `cdp_sys_record_currency__c`, that holds each record's ISO currency code. Data Explorer UI uses it to display currency values, and shows a blank value if it's null (Query Editor still shows it).
208
+
209
+ Code Extensions don't set `cdp_sys_record_currency__c` for you, since only your script knows what currency its amounts are in. When writing to an object with Currency fields, set it yourself:
210
+
211
+ ```python
212
+ from pyspark.sql.functions import lit
213
+
214
+ # Either source has Currency fields: keep its cdp_sys_record_currency__c in your output
215
+ df = source.select("id__c", "amount__c", "cdp_sys_record_currency__c")
216
+
217
+ # OR amounts are in a known currency
218
+ df = df.withColumn("cdp_sys_record_currency__c", lit("EUR"))
219
+ ```
220
+
221
+ - Use an ISO code that exists in your org's configured currency rates.
222
+ - When aggregating, group by the currency code so amounts in different currencies aren't summed together.
223
+
224
+ See [`docs/examples/script/currency_totals`](docs/examples/script/currency_totals) for a complete example.
225
+
204
226
  ### Streaming (delta) transforms
205
227
 
206
228
  Streaming BYOC transforms process a Data Lake Object's Change Data Feed continuously instead of reading a bounded snapshot. Use a `StreamingClient` and its `*_deltas` methods in place of the batch `Client` read/write methods:
@@ -226,6 +248,15 @@ query = client.write_dlo_deltas("Output__dll", transformed)
226
248
  query.awaitTermination()
227
249
  ```
228
250
 
251
+ A streaming transform can also read and write Data Model Objects with `read_dmo_deltas()` and `write_dmo_deltas()`:
252
+
253
+ ```python
254
+ deltas = client.read_dmo_deltas()
255
+ transformed = deltas.withColumn("description__c", upper(col("description__c")))
256
+ query = client.write_dmo_deltas("Output__dlm", transformed)
257
+ query.awaitTermination()
258
+ ```
259
+
229
260
  Notes:
230
261
 
231
262
  - These methods only run inside the Data Cloud streaming (`DELTA_SYNC`) runtime. Locally (`datacustomcode run`) they raise `NotImplementedError`, since there is no change feed to stream.
@@ -249,6 +280,29 @@ If none of these exist, `find_file_path` raises `FileNotFoundError` with the lis
249
280
 
250
281
  `$LIBRARY_PATH` is set automatically to the root of the package at runtime inside Data Cloud.
251
282
 
283
+ ### Generating lineage
284
+
285
+ `generate_lineage` runs a script entry point locally and derives the field-level `dataLineage` section of `config.json` from the Spark plans of the DataFrames it writes:
286
+
287
+ ```python
288
+ from datacustomcode.lineage import generate_lineage
289
+
290
+ result = generate_lineage("payload/entrypoint.py", sf_cli_org="my-org")
291
+ print(result.to_dict()["dataLineage"])
292
+ # [{"targetField": "Output__dll.name__c",
293
+ # "sourceFields": ["Input__dll.first__c", "Input__dll.last__c"]}, ...]
294
+ ```
295
+
296
+ The entry point runs exactly as it would locally (same config, reader, and credentials), except that writes are traced and validated against the target DLO instead of being performed. It runs in a separate Python process, which inherits your working directory, environment, and `sys.path`; errors raised by the script are re-raised from `generate_lineage`. Reads use the reader's `default_row_limit` (1000 by default; set it in your `config.yaml`).
297
+
298
+ > **Review the output before you use it.** The generated lineage is a starting point for review, not a guarantee. It reflects only the code paths and data your local run exercised, and it can't see inside UDFs. Accurate and complete `dataLineage` in your package is your responsibility as the package author.
299
+
300
+ - A target field's sources are the fields its *value* is computed from. Fields that only decide which rows, groups or branch are used aren't sources, however the logic is written: filter conditions, join keys, `groupBy` keys, sort keys, window `partitionBy`/`orderBy` keys, `when()`/`if()` conditions, and aggregate `FILTER (WHERE …)` clauses. For example, `groupBy("region").agg(sum("amount"))` and `sum("amount").over(Window.partitionBy("region"))` both trace to `amount` only.
301
+ - Fields computed only from literals are listed in `noSources`. So are fields whose value doesn't come from any input field's value, such as `row_number()`, `rank()`, `count("*")`, or `sum(when(cond, 1))`.
302
+ - Fields that can't be traced are listed in `unresolved` with a reason and get no lineage. This covers data that didn't come from `read_dlo`/`read_dmo` (for example a `toPandas()` → `createDataFrame` round trip), `mapInPandas`, and subqueries.
303
+ - `pairCount` is the total number of (target, source) field pairs.
304
+ - Only batch script packages are supported.
305
+
252
306
 
253
307
  ## CLI
254
308
 
@@ -364,6 +418,8 @@ Options:
364
418
  #### `datacustomcode zip`
365
419
  Zip a transformation job in preparation to upload to Data Cloud. Make sure to change directory into your code package folder (e.g., `my_package`) before running this command.
366
420
 
421
+ Symlinks inside the payload folder are not followed or packaged. Each symlinked file that is skipped is reported with a warning, and symlinked directories are not included. `datacustomcode deploy` zips the same way.
422
+
367
423
  Arguments:
368
424
  - `PATH`: Path to the code directory i.e. the payload folder (default: "payload")
369
425
 
@@ -151,13 +151,14 @@ For a batch transform, use `Client`. You should only need the following methods:
151
151
  * `find_file_path(file_name)` – Resolve a bundled file (placed under `payload/files/`) to a `pathlib.Path` that exists. Works the same locally and inside Data Cloud — see [Bundled file resolution](#bundled-file-resolution) below for the full lookup order. Raises `FileNotFoundError` if the file isn't found.
152
152
  * `read_dlo(name)` – Read from a Data Lake Object by name
153
153
  * `read_dmo(name)` – Read from a Data Model Object by name
154
- * `write_to_dlo(name, spark_dataframe, write_mode)` – Write to a Data Model Object by name with a Spark dataframe
155
- * `write_to_dmo(name, spark_dataframe, write_mode)` – Write to a Data Lake Object by name with a Spark dataframe
154
+ * `write_to_dlo(name, spark_dataframe, write_mode)` – Write to a Data Lake Object by name with a Spark dataframe
155
+ * `write_to_dmo(name, spark_dataframe, write_mode)` – Write to a Data Model Object by name with a Spark dataframe
156
156
 
157
157
  For a streaming (delta) transform, use `StreamingClient`, which exposes the streaming counterparts:
158
158
  * `read_dlo_deltas()` – Read the streaming change feed (deltas) of a Data Lake Object as a streaming DataFrame.
159
159
  * `read_dmo_deltas()` – Read the streaming change feed (deltas) of a Data Model Object as a streaming DataFrame.
160
160
  * `write_dlo_deltas(name, spark_dataframe)` – Write a streaming DataFrame of deltas to a Data Lake Object; returns the started `StreamingQuery`
161
+ * `write_dmo_deltas(name, spark_dataframe)` – Write a streaming DataFrame of deltas to a Data Model Object; returns the started `StreamingQuery`
161
162
 
162
163
  `find_file_path`, `llm_gateway_generate_text`, and `einstein_predict` are available on both clients.
163
164
 
@@ -176,6 +177,27 @@ client.write_to_dlo('output_DLO')
176
177
  > [!WARNING]
177
178
  > Currently we only support reading from DMOs and writing to DMOs or reading from DLOs and writing to DLOs, but they cannot mix.
178
179
 
180
+ ### Writing Currency fields
181
+
182
+ A DLO or DMO with a Currency field has a system field, `cdp_sys_record_currency__c`, that holds each record's ISO currency code. Data Explorer UI uses it to display currency values, and shows a blank value if it's null (Query Editor still shows it).
183
+
184
+ Code Extensions don't set `cdp_sys_record_currency__c` for you, since only your script knows what currency its amounts are in. When writing to an object with Currency fields, set it yourself:
185
+
186
+ ```python
187
+ from pyspark.sql.functions import lit
188
+
189
+ # Either source has Currency fields: keep its cdp_sys_record_currency__c in your output
190
+ df = source.select("id__c", "amount__c", "cdp_sys_record_currency__c")
191
+
192
+ # OR amounts are in a known currency
193
+ df = df.withColumn("cdp_sys_record_currency__c", lit("EUR"))
194
+ ```
195
+
196
+ - Use an ISO code that exists in your org's configured currency rates.
197
+ - When aggregating, group by the currency code so amounts in different currencies aren't summed together.
198
+
199
+ See [`docs/examples/script/currency_totals`](docs/examples/script/currency_totals) for a complete example.
200
+
179
201
  ### Streaming (delta) transforms
180
202
 
181
203
  Streaming BYOC transforms process a Data Lake Object's Change Data Feed continuously instead of reading a bounded snapshot. Use a `StreamingClient` and its `*_deltas` methods in place of the batch `Client` read/write methods:
@@ -201,6 +223,15 @@ query = client.write_dlo_deltas("Output__dll", transformed)
201
223
  query.awaitTermination()
202
224
  ```
203
225
 
226
+ A streaming transform can also read and write Data Model Objects with `read_dmo_deltas()` and `write_dmo_deltas()`:
227
+
228
+ ```python
229
+ deltas = client.read_dmo_deltas()
230
+ transformed = deltas.withColumn("description__c", upper(col("description__c")))
231
+ query = client.write_dmo_deltas("Output__dlm", transformed)
232
+ query.awaitTermination()
233
+ ```
234
+
204
235
  Notes:
205
236
 
206
237
  - These methods only run inside the Data Cloud streaming (`DELTA_SYNC`) runtime. Locally (`datacustomcode run`) they raise `NotImplementedError`, since there is no change feed to stream.
@@ -224,6 +255,29 @@ If none of these exist, `find_file_path` raises `FileNotFoundError` with the lis
224
255
 
225
256
  `$LIBRARY_PATH` is set automatically to the root of the package at runtime inside Data Cloud.
226
257
 
258
+ ### Generating lineage
259
+
260
+ `generate_lineage` runs a script entry point locally and derives the field-level `dataLineage` section of `config.json` from the Spark plans of the DataFrames it writes:
261
+
262
+ ```python
263
+ from datacustomcode.lineage import generate_lineage
264
+
265
+ result = generate_lineage("payload/entrypoint.py", sf_cli_org="my-org")
266
+ print(result.to_dict()["dataLineage"])
267
+ # [{"targetField": "Output__dll.name__c",
268
+ # "sourceFields": ["Input__dll.first__c", "Input__dll.last__c"]}, ...]
269
+ ```
270
+
271
+ The entry point runs exactly as it would locally (same config, reader, and credentials), except that writes are traced and validated against the target DLO instead of being performed. It runs in a separate Python process, which inherits your working directory, environment, and `sys.path`; errors raised by the script are re-raised from `generate_lineage`. Reads use the reader's `default_row_limit` (1000 by default; set it in your `config.yaml`).
272
+
273
+ > **Review the output before you use it.** The generated lineage is a starting point for review, not a guarantee. It reflects only the code paths and data your local run exercised, and it can't see inside UDFs. Accurate and complete `dataLineage` in your package is your responsibility as the package author.
274
+
275
+ - A target field's sources are the fields its *value* is computed from. Fields that only decide which rows, groups or branch are used aren't sources, however the logic is written: filter conditions, join keys, `groupBy` keys, sort keys, window `partitionBy`/`orderBy` keys, `when()`/`if()` conditions, and aggregate `FILTER (WHERE …)` clauses. For example, `groupBy("region").agg(sum("amount"))` and `sum("amount").over(Window.partitionBy("region"))` both trace to `amount` only.
276
+ - Fields computed only from literals are listed in `noSources`. So are fields whose value doesn't come from any input field's value, such as `row_number()`, `rank()`, `count("*")`, or `sum(when(cond, 1))`.
277
+ - Fields that can't be traced are listed in `unresolved` with a reason and get no lineage. This covers data that didn't come from `read_dlo`/`read_dmo` (for example a `toPandas()` → `createDataFrame` round trip), `mapInPandas`, and subqueries.
278
+ - `pairCount` is the total number of (target, source) field pairs.
279
+ - Only batch script packages are supported.
280
+
227
281
 
228
282
  ## CLI
229
283
 
@@ -339,6 +393,8 @@ Options:
339
393
  #### `datacustomcode zip`
340
394
  Zip a transformation job in preparation to upload to Data Cloud. Make sure to change directory into your code package folder (e.g., `my_package`) before running this command.
341
395
 
396
+ Symlinks inside the payload folder are not followed or packaged. Each symlinked file that is skipped is reported with a warning, and symlinked directories are not included. `datacustomcode deploy` zips the same way.
397
+
342
398
  Arguments:
343
399
  - `PATH`: Path to the code directory i.e. the payload folder (default: "payload")
344
400
 
@@ -18,7 +18,7 @@ license = "Apache-2.0"
18
18
  name = "salesforce-data-customcode"
19
19
  readme = "README.md"
20
20
  requires-python = ">=3.10,<3.12"
21
- version = "6.1.0.dev7"
21
+ version = "7.0.0"
22
22
 
23
23
  [tool.black]
24
24
  exclude = '''
@@ -13,12 +13,19 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
+ from datacustomcode.spark.column_hints import install_column_casing_hints
17
+
18
+ # Friendlier errors for wrong-case column references. Idempotent.
19
+ install_column_casing_hints()
20
+
16
21
  __all__ = [
17
22
  "AuthType",
18
23
  "Client",
19
24
  "Credentials",
20
25
  "DefaultSparkEinsteinPredictions",
21
26
  "DefaultSparkLLMGateway",
27
+ "LocalDeltasReader",
28
+ "LocalDeltasWriter",
22
29
  "PrintDataCloudWriter",
23
30
  "QueryAPIDataCloudReader",
24
31
  "SparkEinsteinPredictions",
@@ -55,6 +62,14 @@ def __getattr__(name: str):
55
62
  from datacustomcode.io.reader.query_api import QueryAPIDataCloudReader
56
63
 
57
64
  return QueryAPIDataCloudReader
65
+ elif name == "LocalDeltasReader":
66
+ from datacustomcode.io.reader.local_deltas import LocalDeltasReader
67
+
68
+ return LocalDeltasReader
69
+ elif name == "LocalDeltasWriter":
70
+ from datacustomcode.io.writer.local_deltas import LocalDeltasWriter
71
+
72
+ return LocalDeltasWriter
58
73
  elif name == "SparkLLMGateway":
59
74
  from datacustomcode.llm_gateway import SparkLLMGateway
60
75
 
@@ -368,7 +368,13 @@ class _BaseClient:
368
368
  instance._spark_named_credential = spark_named_credential
369
369
  # Initialize Readers and Writers from config
370
370
  # and/or provided reader and writer
371
- if reader is None or writer is None:
371
+ reader_forced = (
372
+ config.reader_config is not None and config.reader_config.force
373
+ )
374
+ writer_forced = (
375
+ config.writer_config is not None and config.writer_config.force
376
+ )
377
+ if reader is None or writer is None or reader_forced or writer_forced:
372
378
  # We need a spark because we will initialize readers and writers.
373
379
  # Reuse the process-wide session if one client already built it,
374
380
  # so a Client and a StreamingClient share a single connection.
@@ -396,9 +402,7 @@ class _BaseClient:
396
402
  raise ValueError(
397
403
  "Reader config is required when reader is not provided"
398
404
  )
399
- elif reader is None or (
400
- config.reader_config is not None and config.reader_config.force
401
- ):
405
+ elif reader is None or reader_forced:
402
406
  reader_init = config.reader_config.to_object(spark) # type: ignore
403
407
  else:
404
408
  reader_init = reader
@@ -406,9 +410,7 @@ class _BaseClient:
406
410
  raise ValueError(
407
411
  "Writer config is required when writer is not provided"
408
412
  )
409
- elif writer is None or (
410
- config.writer_config is not None and config.writer_config.force
411
- ):
413
+ elif writer is None or writer_forced:
412
414
  writer_init = config.writer_config.to_object(spark) # type: ignore
413
415
  else:
414
416
  writer_init = writer
@@ -716,6 +718,25 @@ class StreamingClient(_BaseClient):
716
718
  self._validate_data_layer_history_does_not_contain(DataCloudObjectType.DMO)
717
719
  return self._writer.write_dlo_deltas(name, dataframe, **kwargs) # type: ignore[no-any-return]
718
720
 
721
+ def write_dmo_deltas(
722
+ self, name: str, dataframe: PySparkDataFrame, **kwargs
723
+ ) -> StreamingQuery:
724
+ """Write a streaming DataFrame of deltas to a DMO in Data Cloud.
725
+
726
+ Starts a streaming query that writes each micro-batch to the
727
+ target DMO and returns the ``StreamingQuery`` handle; the caller
728
+ typically calls ``query.awaitTermination()``.
729
+
730
+ Args:
731
+ name: The name of the DMO to write to.
732
+ dataframe: The streaming PySpark DataFrame to write.
733
+
734
+ Returns:
735
+ The started ``StreamingQuery``.
736
+ """
737
+ self._validate_data_layer_history_does_not_contain(DataCloudObjectType.DLO)
738
+ return self._writer.write_dmo_deltas(name, dataframe, **kwargs) # type: ignore[no-any-return]
739
+
719
740
  def auto_write_to_dlo(self, name: str, dataframe: PySparkDataFrame) -> None:
720
741
  """Write a PySpark DataFrame to a DLO in Data Cloud automatically picking
721
742
  the WriteMode.
@@ -18,6 +18,8 @@ spark_config:
18
18
  spark.submit.deployMode: client
19
19
  spark.sql.execution.arrow.pyspark.enabled: 'true'
20
20
  spark.driver.extraJavaOptions: -Djava.security.manager=allow
21
+ # Resolve columns case-sensitively so wrong-case refs fail locally too.
22
+ spark.sql.caseSensitive: 'true'
21
23
 
22
24
  einstein_predictions_config:
23
25
  type_config_name: DefaultEinsteinPredictions
@@ -415,13 +415,7 @@ class DataTransformConfig(BaseConfig):
415
415
  def _validate_layers(self) -> "DataTransformConfig":
416
416
  read_is_dlo = isinstance(self.permissions.read, DloPermission)
417
417
  write_is_dlo = isinstance(self.permissions.write, DloPermission)
418
- if self.is_streaming:
419
- if not write_is_dlo:
420
- raise ValueError(
421
- "A streaming transform must write to a DLO "
422
- "(permissions.write must be a 'dlo' entry)."
423
- )
424
- elif read_is_dlo != write_is_dlo:
418
+ if read_is_dlo != write_is_dlo:
425
419
  raise ValueError(
426
420
  "permissions.read and permissions.write must both reference "
427
421
  "DLOs or both reference DMOs (got "
@@ -551,15 +545,13 @@ def create_data_transform(
551
545
  "version": "56.0",
552
546
  }
553
547
 
554
- # outputDataObjects is only set for DMO-backed transforms. The server requires
555
- # the schema of any DMO created/updated by the transform; DLO transforms use
556
- # an existing materialized table and must not include this field.
557
- if isinstance(data_transform_config.permissions.write, DmoPermission):
558
- if not data_transform_config.dataObjects:
548
+ if not data_transform_config.dataObjects:
549
+ if isinstance(data_transform_config.permissions.write, DmoPermission):
559
550
  raise ValueError(
560
551
  "DMO transforms require 'dataObjects' in config.json describing "
561
552
  "the schema of each output DMO."
562
553
  )
554
+ else:
563
555
  definition["outputDataObjects"] = [
564
556
  _data_object_to_output(obj) for obj in data_transform_config.dataObjects
565
557
  ]
@@ -632,12 +624,15 @@ def zip(
632
624
  logger.debug(f"Zipping directory... {directory}")
633
625
 
634
626
  with zipfile.ZipFile(ZIP_FILE_NAME, "w", zipfile.ZIP_DEFLATED) as zipf:
635
- for root, dirs, files in os.walk(directory):
636
- # Skip .DS_Store and local credentials.
627
+ for root, dirs, files in os.walk(directory, followlinks=False):
628
+ # Skip symlinks, .DS_Store and local credentials.
637
629
  for file in files:
630
+ abs_path = os.path.join(root, file)
631
+ arcname = os.path.relpath(abs_path, directory)
632
+ if os.path.islink(abs_path):
633
+ logger.warning(f"Skipping symlink file {arcname}")
634
+ continue
638
635
  if file not in EXCLUDED_FILES:
639
- abs_path = os.path.join(root, file)
640
- arcname = os.path.relpath(abs_path, directory)
641
636
  zipf.write(abs_path, arcname)
642
637
 
643
638
  logger.debug(f"Created zip file: {ZIP_FILE_NAME}")
@@ -0,0 +1,34 @@
1
+ # Copyright (c) 2025, Salesforce, Inc.
2
+ # SPDX-License-Identifier: Apache-2
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from __future__ import annotations
17
+
18
+ from typing import Final
19
+
20
+ from datacustomcode.io.writer.base import MERGE_RECORD_TYPE_COLUMN, MergeRecordType
21
+
22
+ COMMIT_VERSION: Final = "_commit_version"
23
+ COMMIT_TIMESTAMP: Final = "_commit_timestamp"
24
+ MERGE_RECORD_TYPE: Final = MERGE_RECORD_TYPE_COLUMN
25
+
26
+ CDF_METADATA_COLUMNS: Final = (COMMIT_VERSION, COMMIT_TIMESTAMP, MERGE_RECORD_TYPE)
27
+
28
+ __all__ = [
29
+ "COMMIT_VERSION",
30
+ "COMMIT_TIMESTAMP",
31
+ "MERGE_RECORD_TYPE",
32
+ "CDF_METADATA_COLUMNS",
33
+ "MergeRecordType",
34
+ ]
@@ -0,0 +1,164 @@
1
+ # Copyright (c) 2025, Salesforce, Inc.
2
+ # SPDX-License-Identifier: Apache-2
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from __future__ import annotations
17
+
18
+ import json
19
+ import logging
20
+ from pathlib import Path
21
+ import sys
22
+ from typing import (
23
+ TYPE_CHECKING,
24
+ Optional,
25
+ Union,
26
+ )
27
+
28
+ from datacustomcode.config import config
29
+ from datacustomcode.io import cdf
30
+ from datacustomcode.io.reader.base import BaseDataCloudReader
31
+ from datacustomcode.io.reader.query_api import QueryAPIDataCloudReader
32
+
33
+ if TYPE_CHECKING:
34
+ from pyspark.sql import DataFrame as PySparkDataFrame, SparkSession
35
+ from pyspark.sql.types import AtomicType, StructType
36
+
37
+ logger = logging.getLogger(__name__)
38
+
39
+
40
+ class LocalDeltasReader(BaseDataCloudReader):
41
+ """Local reader for streaming transforms"""
42
+
43
+ CONFIG_NAME = "LocalDeltasReader"
44
+
45
+ def __init__(
46
+ self,
47
+ spark: SparkSession,
48
+ credentials_profile: str = "default",
49
+ dataspace: Optional[str] = None,
50
+ sf_cli_org: Optional[str] = None,
51
+ default_row_limit: Optional[int] = None,
52
+ fixtures_root: str = "payload/streaming_fixtures",
53
+ ) -> None:
54
+ super().__init__(spark)
55
+ self._fixtures_root = Path(fixtures_root)
56
+ self._credentials_profile = credentials_profile
57
+ self._dataspace = dataspace
58
+ self._sf_cli_org = sf_cli_org
59
+ # Reuse the batch reader for INITIAL_SYNC / REBUILD reads.
60
+ self._batch = QueryAPIDataCloudReader(
61
+ spark=spark,
62
+ credentials_profile=credentials_profile,
63
+ dataspace=dataspace,
64
+ sf_cli_org=sf_cli_org,
65
+ default_row_limit=default_row_limit,
66
+ )
67
+ self._current_layer = "dlo"
68
+
69
+ def read_dlo(
70
+ self,
71
+ name: str,
72
+ schema: Union[AtomicType, StructType, str, None] = None,
73
+ ) -> PySparkDataFrame:
74
+ return self._batch.read_dlo(name, schema)
75
+
76
+ def read_dmo(
77
+ self,
78
+ name: str,
79
+ schema: Union[AtomicType, StructType, str, None] = None,
80
+ ) -> PySparkDataFrame:
81
+ return self._batch.read_dmo(name, schema)
82
+
83
+ def read_dlo_deltas(self) -> PySparkDataFrame:
84
+ self._current_layer = "dlo"
85
+ return self._open_stream(self._streaming_source())
86
+
87
+ def read_dmo_deltas(self) -> PySparkDataFrame:
88
+ self._current_layer = "dmo"
89
+ return self._open_stream(self._streaming_source())
90
+
91
+ def _streaming_source(self) -> str:
92
+ source = config.streaming_source
93
+ if not source:
94
+ raise RuntimeError(
95
+ "No streaming source configured. Set streamingSource.name in "
96
+ "config.json."
97
+ )
98
+ return source
99
+
100
+ def _open_stream(self, name: str) -> PySparkDataFrame:
101
+ drop_dir = self._fixtures_root / name
102
+
103
+ if not (drop_dir / "_schema.json").exists():
104
+ seeded = self._try_seed(name)
105
+ if not seeded:
106
+ print(
107
+ f"\nStreaming source {self._current_layer}='{name}' is "
108
+ f"empty.\n"
109
+ f" Populate the stream source with at least one row in "
110
+ f"Data Cloud, then re-run `datacustomcode run`.\n"
111
+ )
112
+ sys.exit(0)
113
+
114
+ print(
115
+ f"\nWrote sample streaming fixture in: {drop_dir} "
116
+ f"based on the contents of the streaming source {name}.\n"
117
+ f" You may add more JSON files alongside it to simulate "
118
+ f"additional changes.\n"
119
+ )
120
+
121
+ schema = self._build_stream_schema(name)
122
+ return (
123
+ self.spark.readStream.format("json")
124
+ .schema(schema)
125
+ .option("maxFilesPerTrigger", 1) # one file = one batch
126
+ .option("latestFirst", "false") # oldest mtime first
127
+ .load(str(drop_dir))
128
+ )
129
+
130
+ def _build_stream_schema(self, name: str) -> "StructType":
131
+ """Compose (source schema + CDF metadata columns) for readStream."""
132
+ from pyspark.sql.types import (
133
+ LongType,
134
+ StringType,
135
+ StructField,
136
+ StructType,
137
+ TimestampType,
138
+ )
139
+
140
+ source_schema = self._resolve_source_schema(name)
141
+ cdf_fields = [
142
+ StructField(cdf.COMMIT_VERSION, LongType(), True),
143
+ StructField(cdf.COMMIT_TIMESTAMP, TimestampType(), True),
144
+ StructField(cdf.MERGE_RECORD_TYPE, StringType(), True),
145
+ ]
146
+ return StructType(list(source_schema.fields) + cdf_fields)
147
+
148
+ def _resolve_source_schema(self, name: str) -> "StructType":
149
+ from pyspark.sql.types import StructType
150
+
151
+ schema_file = self._fixtures_root / name / "_schema.json"
152
+ return StructType.fromJson(json.loads(schema_file.read_text()))
153
+
154
+ def _try_seed(self, name: str) -> bool:
155
+ """Creates source schema and sample change file."""
156
+ from datacustomcode.io.reader.streaming_seeder import StreamingSourceSeeder
157
+
158
+ seeder = StreamingSourceSeeder(
159
+ spark=self.spark,
160
+ credentials_profile=self._credentials_profile,
161
+ dataspace=self._dataspace,
162
+ sf_cli_org=self._sf_cli_org,
163
+ )
164
+ return seeder.seed_source(name, self._current_layer, str(self._fixtures_root))