U-SQL - 顶点失败:尝试转换列数据时无效字符

时间:2016-12-15 14:10:08

标签: sql casting analytics azure-data-lake u-sql

对于我的所有CSV来源,我将提取器设置为:

USING Extractors.Csv(silent:true,skipFirstNRows:1);  
- silent is set to true to ignore bad rows
- skipFirstNRows is set to 1 to skip the header row

奇怪的是,我仍然遇到这个错误:

HEX: "223122" Invalid character when converting input record.
Position: line 2, column index: 7, column name: "IncludeOnCheck".
Invalid character when attempting to convert column data.

数据(样本行和有问题的行)

29,1,10,DC Tax,DC Tax,0.100000,0.00,1,1,1,2014-07-12 21:34:52.4200000 +00:00,NULL,NULL,0,-1,0,0,0,NULL,NULL,NULL,1031,NULL,0,0
33,4,10,Amenities,Amenities,1.000000,0.00,1,0,1,2014-07-12 21:34:54.1330000 +00:00,NULL,NULL,0,-1,0,0,0,NULL,NULL,NULL,1031,NULL,0,0

列定义

EXTRACT AncillaryAmountTypeID int,
        AncillaryAmountCategoryID int,
        CustomerID int,
        CheckTitle string,
        ReportTitle string,
        Percentage decimal,
        FixedAmount decimal,
        IncludeOnCheck bool,
        AutoCalculate bool,
        StoreAtCheckLevel bool?,
        DateTimeModified DateTime?,
        CheckTitleToken Guid?,
        ReportTitleToken Guid?,
        DeletedFlag bool,
        MaxUsageQty int?,
        ApplyToBasePriceOnly bool?,
        Exclusive bool,
        IsItem bool,
        MinValue decimal,
        MaxValue decimal,
        ItemGroupID int?,
        LocationID int,
        ApplicationOrder int?,
        RequiresReason bool,
        Exemptable bool?

问题

  1. 当我指定silent为true时,为什么会出现转换错误, 哪个应该忽略任何坏行,对吗?
  2. 它试图转换的字符是“1”,并且是一个布尔值。 U-SQL或ADLA无法理解或将1和0转换为布尔值吗?

2 个答案:

答案 0 :(得分:1)

是的,我也观察到了这种行为,它没有自动将0或1转换为bool。如果你想这样做,那么将它提取为int,然后使用Convert.ToBoolean方法将其转换为bool。

我认为静默开关仅在提供的架构与实际数据的架构不匹配时才有效。

答案 1 :(得分:0)

Heresilent参数的文档:如果您的目标类型可以为空,它只会忽略转换错误。否则它仍然是错误。

此外,我们按照here所描述的那样在转换时遵循C#语义。