CsvConnector¶
CSV source connector.
- class scamander.sources.csv_connector.CsvConnector(config: Config, *args, **kwargs)¶
Basisklassen:
SourceSource connector that reads one or more CSV files into a Spark DataFrame.
Can be instantiated directly with flat keyword arguments, or via the
Sourcefactory (Source(config, spark=spark)) by passing aConfigwhosesource.optionsis aCsvSourceOptions.- Parameters:
file_path (str | Config) – Path to the CSV file or a glob pattern on the platform filesystem (e.g. a DBFS path, an ABFS URI, or a local path for testing), or a validated
Configwhosesource.optionsis aCsvSourceOptions(theSourcefactory path — requiressparkas a keyword argument).header (bool) – Whether the first row of the CSV contains column names. Defaults to
True. Ignored whenfile_pathis aConfig.separator (str) – The field delimiter character. Defaults to
";"(semicolon). Ignored whenfile_pathis aConfig.encoding (str) – Character encoding of the file. Defaults to
"UTF-8". Ignored whenfile_pathis aConfig.infer_schema (bool) – When
True, Spark samples the file to infer column types. Defaults toTrue. Ignored whenfile_pathis aConfig.multiline (bool) – Allow records that span multiple lines. Defaults to
False. Ignored whenfile_pathis aConfig.date_format (str | None) –
java.text.SimpleDateFormatpattern for date columns. Ignored whenfile_pathis aConfig.spark (SparkSession) – Required keyword argument when
file_pathis aConfig; unused otherwise.
- Veroorzaakt:
ValueError – If
file_pathis aConfigwhosesource.optionsis not aCsvSourceOptionsinstance.
- connect() DataFrame¶
Reads the CSV file(s) at
self.file_pathinto a Spark DataFrame.All reader options are forwarded to Spark’s CSV data source from the constructor arguments.
- Returns:
A Spark DataFrame containing the CSV data.
- Return type:
DataFrame