session
Spark Session wrapper for gentropy¶
gentropy.common.session.Session
¶
This class provides a Spark session and logger.
Source code in src/gentropy/common/session.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
__init__(spark_uri: str = 'local[*]', write_mode: str = 'errorifexists', app_name: str = 'gentropy', hail_home: str | None = None, start_hail: bool = False, extended_spark_conf: dict[str, str] | None = None, output_partitions: int = 200, use_enhanced_bgzip_codec: bool = False) -> None
¶
Initialises spark session and logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spark_uri
|
str
|
Spark URI. Defaults to "local[*]". |
'local[*]'
|
write_mode
|
str
|
Spark write mode. Defaults to "errorifexists". |
'errorifexists'
|
app_name
|
str
|
Spark application name. Defaults to "gentropy". |
'gentropy'
|
hail_home
|
str | None
|
Path to Hail installation. Defaults to None. |
None
|
start_hail
|
bool
|
Whether to start Hail. Defaults to False. |
False
|
extended_spark_conf
|
dict[str, str] | None
|
Extended Spark configuration. Defaults to None. |
None
|
output_partitions
|
int
|
Number of partitions for output datasets. Defaults to 200. |
200
|
use_enhanced_bgzip_codec
|
bool
|
Whether to use the BGZFEnhancedGzipCodec for reading block gzipped files. Defaults to False. |
False
|
Source code in src/gentropy/common/session.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
load_data(path: str | list[str], format: str = 'parquet', schema: StructType | str | None = None, **kwargs: bool | float | int | str | None) -> DataFrame
¶
Generic function to read a file or folder into a Spark dataframe.
The recursiveFileLookup flag when set to True will skip all partition columns, but read files from all subdirectories.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | list[str]
|
path to the dataset |
required |
format
|
str
|
file format. Defaults to parquet. |
'parquet'
|
schema
|
StructType | str | None
|
Schema to use when reading the data. |
None
|
**kwargs
|
bool | float | int | str | None
|
Additional arguments to pass to spark.read.load. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
DataFrame |
DataFrame
|
Dataframe |
Source code in src/gentropy/common/session.py
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
gentropy.common.session.Log4j
¶
Log4j logger class.
Source code in src/gentropy/common/session.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
__init__(spark: SparkSession) -> None
¶
Log4j logger class. This class provides a wrapper around the Log4j logging system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spark
|
SparkSession
|
The Spark session used to access Spark context and Log4j logging. |
required |
Source code in src/gentropy/common/session.py
218 219 220 221 222 223 224 225 226 | |
error(message: str) -> None
¶
Log an error.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Error message to write to log |
required |
Source code in src/gentropy/common/session.py
228 229 230 231 232 233 234 | |
info(message: str) -> None
¶
Log information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Information message to write to log |
required |
Source code in src/gentropy/common/session.py
244 245 246 247 248 249 250 | |
warning(message: str) -> None
¶
Log a warning.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Warning message to write to log |
required |
Source code in src/gentropy/common/session.py
236 237 238 239 240 241 242 | |