|
20 | 20 | from dbldatagen import datagen_constants |
21 | 21 | from dbldatagen._version import _get_spark_version |
22 | 22 | from dbldatagen.column_generation_spec import ColumnGenerationSpec |
| 23 | +from dbldatagen.config import OutputConfig |
23 | 24 | from dbldatagen.constraints import Constraint, SqlExpr |
24 | 25 | from dbldatagen.datarange import DataRange |
25 | 26 | from dbldatagen.distributions import DataDistribution |
|
28 | 29 | from dbldatagen.serialization import SerializableToDict |
29 | 30 | from dbldatagen.spark_singleton import SparkSingleton |
30 | 31 | from dbldatagen.text_generators import TextGenerator |
31 | | -from dbldatagen.utils import DataGenError, deprecated, ensure, split_list_matching_condition, topologicalSort |
| 32 | +from dbldatagen.utils import ( |
| 33 | + DataGenError, |
| 34 | + deprecated, |
| 35 | + ensure, |
| 36 | + split_list_matching_condition, |
| 37 | + topologicalSort, |
| 38 | + write_data_to_output, |
| 39 | +) |
32 | 40 |
|
33 | 41 |
|
34 | 42 | _OLD_MIN_OPTION: str = "min" |
@@ -1909,6 +1917,18 @@ def scriptMerge( |
1909 | 1917 |
|
1910 | 1918 | return result |
1911 | 1919 |
|
| 1920 | + def writeGeneratedData(self, config: OutputConfig, is_streaming: bool = False) -> None: |
| 1921 | + """ |
| 1922 | + Builds a `DataFrame` from the `DataGenerator` and writes the data to a target table. |
| 1923 | +
|
| 1924 | + :param config: Output configuration for writing generated data |
| 1925 | + :param is_streaming: Whether to write data with Structured Streaming (default `False`) |
| 1926 | + """ |
| 1927 | + if is_streaming: |
| 1928 | + write_data_to_output(self.build(withStreaming=True), config=config, is_streaming=is_streaming) |
| 1929 | + |
| 1930 | + write_data_to_output(self.build(), config=config) |
| 1931 | + |
1912 | 1932 | @staticmethod |
1913 | 1933 | def loadFromJson(options: str) -> "DataGenerator": |
1914 | 1934 | """ |
|
0 commit comments