Class CsvUtil
Provides utility methods for reading CSV data into a DataTable
or DataFrame
.
Namespace: Workspace.XBR.Xperiflow.Etl.Tabular.Utilities
Assembly: Xperiflow.dll
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); `
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
Type | Name | Description |
---|---|---|
OneStream.Shared.Common.SessionInfo | si | |
System.Data.IDataReader | reader | The IDataReader object to read data from |
System.Boolean | headersIncluded | A boolean value indicating whether the CSV data includes headers |
System.String[] | columnNames | An optional array of column names to use for the DataTable |
System.Int32 | numRows | The number of rows to read from the IDataReader . If -1, all rows are read |
System.Int32 | guessRows | The number of rows to use for column data type inference |
System.Collections.Generic.Dictionary<System.String,Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo> | columnInferenceInfo | A 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.ColumnInferenceHandler | defaultHandler | The 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
.
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
Type | Name | Description |
---|---|---|
OneStream.Shared.Common.SessionInfo | si | |
System.IO.Stream | stream | The Stream object to read data from |
Workspace.XBR.Xperiflow.Etl.IDataFormat | dataFormat | The [Workspace.XBR.Xperiflow.Etl.IDataFormat](../Xperiflow.Etl/IDataFormat.md) object to use for reading the Stream |
System.Boolean | headersIncluded | A boolean value indicating whether the CSV data includes headers |
System.String[] | columnNames | An optional array of column names to use for the DataTable |
System.Int32 | numRows | The number of rows to read from the Stream . If -1, all rows are read |
System.Int32 | guessRows | The number of rows to use for column data type inference |
System.Collections.Generic.Dictionary<System.String,Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo> | columnInferenceInfo | A 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.ColumnInferenceHandler | defaultHandler | The 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
.
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
Type | Name | Description |
---|---|---|
OneStream.Shared.Common.SessionInfo | si | |
System.Data.IDataReader | reader | The IDataReader object to read data from |
System.Boolean | headersIncluded | A boolean value indicating whether the CSV data includes headers |
System.String[] | columnNames | An optional array of column names to use for the DataFrame |
System.Int32 | numRows | The number of rows to read from the IDataReader . If -1, all rows are read |
System.Int32 | guessRows | The number of rows to use for column data type inference |
System.Collections.Generic.Dictionary<System.String,Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo> | columnInferenceInfo | A 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.ColumnInferenceHandler | defaultHandler | The 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
.
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
Type | Name | Description |
---|---|---|
OneStream.Shared.Common.SessionInfo | si | |
System.IO.Stream | stream | The Stream object to read data from |
Workspace.XBR.Xperiflow.Etl.IDataFormat | dataFormat | |
System.Boolean | headersIncluded | A boolean value indicating whether the CSV data includes headers |
System.String[] | columnNames | An optional array of column names to use for the DataFrame |
System.Int32 | numRows | The number of rows to read from the Stream . If -1, all rows are read |
System.Int32 | guessRows | The number of rows to use for column data type inference |
System.Collections.Generic.Dictionary<System.String,Workspace.XBR.Xperiflow.Etl.Tabular.Utilities.ColumnInferenceInfo> | columnInferenceInfo | A 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.ColumnInferenceHandler | defaultHandler | The 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