Skip to main content

Class CsvUtil

Provides utility methods for reading CSV data into a DataTable or DataFrame.

Namespace: Workspace.XBR.Xperiflow.Etl.Tabular.Utilities

Assembly: Xperiflow.dll

Declaration
public static class CsvUtil

Methods

ReadCsvToDataTable(SessionInfo, IDataReader, bool, string[]?, int, int, Dictionary<string, ColumnInferenceInfo>?, ColumnInferenceHandler)

Reads CSV data from an IDataReader into a DataTable.

To most simply read Csv data into a DataTable with this function and infer the column data types, use the following:

Example:

` var dataTable = CsvUtil.ReadCsvToDataTable(reader); `
Declaration
public static DataTable ReadCsvToDataTable(SessionInfo si, IDataReader reader, bool headersIncluded = false, string[]? columnNames = null, int numRows = -1, int guessRows = 10000, Dictionary<string, ColumnInferenceInfo>? columnInferenceInfo = null, ColumnInferenceHandler defaultHandler = ColumnInferenceHandler.InferDataType)
Returns

System.Data.DataTable

A DataTable object containing the CSV data

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosi
System.Data.IDataReaderreaderThe IDataReader object to read data from
System.BooleanheadersIncludedA boolean value indicating whether the CSV data includes headers
System.String[]columnNamesAn optional array of column names to use for the DataTable
System.Int32numRowsThe number of rows to read from the IDataReader. If -1, all rows are read
System.Int32guessRowsThe number of rows to use for column data type inference
System.Collections.Generic.Dictionary<System.String,Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo>columnInferenceInfoA Dictionary of string to [Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo](../Xperiflow.Etl.Tabular.Utilities/ColumnInferenceInfo.md) objects to use for column inference
Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceHandlerdefaultHandlerThe default [Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceHandler](../Xperiflow.Etl.Tabular.Utilities/ColumnInferenceHandler.md) to use for columns if a
[Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo](../Xperiflow.Etl.Tabular.Utilities/ColumnInferenceInfo.md) object does not exist for a column

ReadCsvToDataTable(SessionInfo, Stream, IDataFormat, bool, string[]?, int, int, Dictionary<string, ColumnInferenceInfo>?, ColumnInferenceHandler)

Reads Csv data from a Stream into a DataTable.

Declaration
public static DataTable ReadCsvToDataTable(SessionInfo si, Stream stream, IDataFormat dataFormat, bool headersIncluded = false, string[]? columnNames = null, int numRows = -1, int guessRows = 10000, Dictionary<string, ColumnInferenceInfo>? columnInferenceInfo = null, ColumnInferenceHandler defaultHandler = ColumnInferenceHandler.InferDataType)
Returns

System.Data.DataTable

A DataTable object containing the CSV data

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosi
System.IO.StreamstreamThe Stream object to read data from
Workspace.XBR.Xperiflow.Etl.IDataFormatdataFormatThe [Workspace.XBR.Xperiflow.Etl.IDataFormat](../Xperiflow.Etl/IDataFormat.md) object to use for reading the Stream
System.BooleanheadersIncludedA boolean value indicating whether the CSV data includes headers
System.String[]columnNamesAn optional array of column names to use for the DataTable
System.Int32numRowsThe number of rows to read from the Stream. If -1, all rows are read
System.Int32guessRowsThe number of rows to use for column data type inference
System.Collections.Generic.Dictionary<System.String,Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo>columnInferenceInfoA Dictionary of string to [Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo](../Xperiflow.Etl.Tabular.Utilities/ColumnInferenceInfo.md) objects to use for column inference
Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceHandlerdefaultHandlerThe default [Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceHandler](../Xperiflow.Etl.Tabular.Utilities/ColumnInferenceHandler.md) to use for columns if a
[Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo](../Xperiflow.Etl.Tabular.Utilities/ColumnInferenceInfo.md) object does not exist for a column

ReadCsvToDataFrame(SessionInfo, IDataReader, bool, string[]?, int, int, Dictionary<string, ColumnInferenceInfo>?, ColumnInferenceHandler)

Reads CSV data from an IDataReader into a DataFrame.

Declaration
public static DataFrame ReadCsvToDataFrame(SessionInfo si, IDataReader reader, bool headersIncluded = false, string[]? columnNames = null, int numRows = -1, int guessRows = 10000, Dictionary<string, ColumnInferenceInfo>? columnInferenceInfo = null, ColumnInferenceHandler defaultHandler = ColumnInferenceHandler.InferDataType)
Returns

Microsoft.Data.Analysis.DataFrame

A DataFrame object containing the CSV data

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosi
System.Data.IDataReaderreaderThe IDataReader object to read data from
System.BooleanheadersIncludedA boolean value indicating whether the CSV data includes headers
System.String[]columnNamesAn optional array of column names to use for the DataFrame
System.Int32numRowsThe number of rows to read from the IDataReader. If -1, all rows are read
System.Int32guessRowsThe number of rows to use for column data type inference
System.Collections.Generic.Dictionary<System.String,Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo>columnInferenceInfoA Dictionary of string to [Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo](../Xperiflow.Etl.Tabular.Utilities/ColumnInferenceInfo.md) objects to use for column inference
Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceHandlerdefaultHandlerThe default [Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceHandler](../Xperiflow.Etl.Tabular.Utilities/ColumnInferenceHandler.md) to use for columns if a
[Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo](../Xperiflow.Etl.Tabular.Utilities/ColumnInferenceInfo.md) object does not exist for a column

ReadCsvToDataFrame(SessionInfo, Stream, IDataFormat, bool, string[]?, int, int, Dictionary<string, ColumnInferenceInfo>?, ColumnInferenceHandler)

Reads CSV data from a Stream into a DataFrame.

Declaration
public static DataFrame ReadCsvToDataFrame(SessionInfo si, Stream stream, IDataFormat dataFormat, bool headersIncluded = false, string[]? columnNames = null, int numRows = -1, int guessRows = 10000, Dictionary<string, ColumnInferenceInfo>? columnInferenceInfo = null, ColumnInferenceHandler defaultHandler = ColumnInferenceHandler.InferDataType)
Returns

Microsoft.Data.Analysis.DataFrame

A DataFrame object containing the CSV data

Parameters
TypeNameDescription
OneStream.Shared.Common.SessionInfosi
System.IO.StreamstreamThe Stream object to read data from
Workspace.XBR.Xperiflow.Etl.IDataFormatdataFormat
System.BooleanheadersIncludedA boolean value indicating whether the CSV data includes headers
System.String[]columnNamesAn optional array of column names to use for the DataFrame
System.Int32numRowsThe number of rows to read from the Stream. If -1, all rows are read
System.Int32guessRowsThe number of rows to use for column data type inference
System.Collections.Generic.Dictionary<System.String,Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo>columnInferenceInfoA Dictionary of string to [Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo](../Xperiflow.Etl.Tabular.Utilities/ColumnInferenceInfo.md) objects to use for column inference
Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceHandlerdefaultHandlerThe default [Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceHandler](../Xperiflow.Etl.Tabular.Utilities/ColumnInferenceHandler.md) to use for columns if a
[Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo](../Xperiflow.Etl.Tabular.Utilities/ColumnInferenceInfo.md) object does not exist for a column

Inherited Members

  • System.Object.Equals(System.Object)
  • System.Object.Equals(System.Object,System.Object)
  • System.Object.GetHashCode
  • System.Object.GetType
  • System.Object.MemberwiseClone
  • System.Object.ReferenceEquals(System.Object,System.Object)
  • System.Object.ToString

Was this page helpful?