在SSIS中,我尝试从平面文件加载数据。 平面文件具有固定宽度的列,但某些列不存在于一行中(列可以具有CRLF,必须是新行),如下所示
@Override
protected User doInBackground(List<Pair<String, String>>... params) {
randomAPI api = randomAPI
.getInstance(context);
try {
**thing that will generate error**
}
} catch (RandomException e) {
Log.e(TAG, "Error", e);
}
return somethingThatIsUsableInOnPostExecute;
}
@Override
protected void onPostExecute(User result) {
}
如何在输出中获得完全相同数量的行和精确数据?
我设置了一个平面文件连接,右边是粗糙的。
在此示例中,第1行正确检索,但对于第2行,它无法识别CRLF,并且在第3行中放入b列...
提前致谢
此致
济
答案 0 :(得分:1)
DT_STR
制表符分隔列
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
If Not Row.Column0_IsNull AndAlso
Not String.IsNullOrEmpty(Row.Column0.Trim) Then
Dim str() As String = Row.Column0.Split(CChar(vbTab))
If str.Length >= 3 Then
Row.a = str(0)
Row.b = str(1)
Row.c = str(2)
ElseIf str.Length = 2 Then
Row.a = str(0)
Row.b = str(1)
Row.c_IsNull = True
ElseIf str.Length = 1 Then
Row.a = str(0)
Row.b_IsNull = True
Row.c_IsNull = True
Else
Row.a_IsNull = True
Row.b_IsNull = True
Row.c_IsNull = True
End If
Else
Row.a_IsNull = True
Row.b_IsNull = True
Row.c_IsNull = True
End If
End Sub
固定宽度列
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
If Not Row.Column0_IsNull AndAlso
Not String.IsNullOrEmpty(Row.Column0.Trim) Then
'Assuming that
'Col a => 0-5
'Col b => 5-15
'Col c => 15-
Dim intlength As Integer = Row.Column0.Length
If intlength <= 5 Then
Row.a = Row.Column0
Row.b_IsNull = True
Row.c_IsNull = True
ElseIf intlength > 5 AndAlso intlength <= 15 Then
Row.a = Row.Column0.Substring(0, 5)
Row.b = Row.Column0.Substring(5, 10)
Row.c_IsNull = True
ElseIf intlength > 15 Then
Row.a = Row.Column0.Substring(0, 5)
Row.b = Row.Column0.Substring(5, 10)
Row.c = Row.Column0.Substring(15)
End If
Else
Row.a_IsNull = True
Row.b_IsNull = True
Row.c_IsNull = True
End If
End Sub
您也可以使用派生列转换
来实现此目的