私は、列の幅に応じて1つ以上のスペースで区切られたテキストファイルからなるソースデータセットを持っています。データは適切に調整されます。つまり、スペースは実際のデータの前に追加されます。複数の空白を含むテキストファイルを区切り文字として扱う方法
組み込みエクストラクタの1つを使用することはできますか、カスタムエクストラクタを実装する必要がありますか?
私は、列の幅に応じて1つ以上のスペースで区切られたテキストファイルからなるソースデータセットを持っています。データは適切に調整されます。つまり、スペースは実際のデータの前に追加されます。複数の空白を含むテキストファイルを区切り文字として扱う方法
組み込みエクストラクタの1つを使用することはできますか、カスタムエクストラクタを実装する必要がありますか?
あなたは、その後、分割され、清潔で、それはSplit
とIsNullOrWhiteSpace
のようなU-SQL内で使用可能なC#のメソッドを使用して1行としてデータをインポートし、単にこのような何かカスタム抽出以上を作成することができます。
// Import the row as one column to be split later; NB use a delimiter that will NOT be in the import file
@input =
EXTRACT rawString string
FROM "/input/input.txt"
USING Extractors.Text(delimiter : '|');
// Add a row number to the line and remove white space elements
@working =
SELECT ROW_NUMBER() OVER() AS rn, new SqlArray<string>(rawString.Split(' ').Where(x => !String.IsNullOrWhiteSpace(x))) AS columns
FROM @input;
// Prepare the output, referencing the column's position in the array
@output =
SELECT rn,
columns[0] AS id,
columns[1] AS firstName,
columns[2] AS lastName
FROM @working;
OUTPUT @output
TO "/output/output.txt"
USING Outputters.Tsv(quoting : false);
マイ結果:
@ wBobのソリューションは、行が文字列(128kB)に収まる場合に機能します。それ以外の場合は、抽出で修正されたカスタム抽出を記述します。書式に関する情報に応じて、input.Split()
を使用して行に分割し、次に示すように空白ルールに基づいて行を分割することができます(抽出パターンの完全な例はhereです)。 this blog postに記載されているもの。
public override IEnumerable<IRow> Extract(IUnstructuredReader input, IUpdatableRow outputrow)
{
foreach (Stream current in input.Split(this._row_delim))
{
using (StreamReader streamReader = new StreamReader(current, this._encoding))
{
int num = 0;
string[] array = streamReader.ReadToEnd().Split(new string[]{this._col_delim}, StringSplitOptions.None).Where(x => !String.IsNullOrWhiteSpace(x)));
for (int i = 0; i < array.Length; i++)
{
// Now write your code to convert array[i] into the extract schema
}
}
yield return outputrow.AsReadOnly();
}
}
}
128KBの制限について、偉大な追加点、重要な点、感謝@MichaelRys。 – wBob