【问题标题】:Encountered error "Cannot convert type System.Nullable`1[System.Int64][] to an R vector"遇到错误“无法将类型 System.Nullable`1[System.Int64][] 转换为 R 向量”
【发布时间】:2018-01-29 15:44:46
【问题描述】:

我正在尝试在 Data Lake Store 上运行作业,但出现错误。

我在u-sql 脚本中插入了一个R 脚本。

在我的 R 脚本中,我使用数据集来计算变量的百分位数,并创建一个包含计算结果的数据框作为输出。

这是我脚本的一部分:

REFERENCE ASSEMBLY [ExtR]; 
DECLARE @data string = @"/output/model/...";
DECLARE @Model_traffic_percentile_outputfile string = "/output/model/...";
DECLARE @myRScript = @"
prob <- c(0.9999995,0.9999996,0.9999997,0.9999998,0.9999999,1)
values <- quantile(inputFromUSQL$total_bytes, probs = prob, type = 6)
outputToUSQL <- data.frame(values, prob)";

@input = 
EXTRACT [Period] string,
        [H_IMSI_BK] long,
        [H_BTSCarrierExternalCode_BK] long,
        [sum_session_duration] long,
        [sum_session_bytes_in] long,
        [sum_session_bytes_out] long,
        [sum_session_count] long
FROM @data
USING Extractors.Csv(skipFirstNRows:1);

@imsi_traffic_data =
SELECT [H_IMSI_BK],
       SUM(([sum_session_bytes_in] + [sum_session_bytes_out]) * [row_count]) AS [total_bytes]
FROM @input
GROUP BY [H_IMSI_BK];

@ExtendedData =
SELECT [total_bytes] AS Par,
   *
FROM @imsi_traffic_data;

@RScriptOutput = REDUCE @ExtendedData ON Par
  PRODUCE Par, values long, prob float
  READONLY Par
  USING new Extension.R.Reducer(
    command:@myRScript,
    rReturnType:"dataframe",
    stringsAsFactors:false);

OUTPUT @RScriptOutput TO @Model_traffic_percentile_outputfile
  USING Outputters.Csv(outputHeader : true, quoting : false);

但我收到此错误:

说明

Vertex failure triggered quick job abort. Vertex failed: SV2_Aggregate[0] 
with error: Vertex user code error.

详情

Vertex SV2_Aggregate[0].v1 {669A5438-5EFD-437D-906C-F069CCD2C5B4} failed 

Error:
Vertex user code error

exitcode=CsExitCode_StillActive Errorsnippet=

内部错误

说明

Unhandled exception from user code: "Cannot convert type 
System.Nullable`1[System.Int64][] to an R vector"
The details includes more information including any inner exceptions and the stack trace where the exception was raised.

有人知道怎么解决吗?

谢谢

【问题讨论】:

    标签: r azure-data-lake u-sql data-lake


    【解决方案1】:

    问题在于 R 脚本无法处理 64 位数据类型。

    为了创建输入数据集,我使用了由命令 Create EXTRACT script 默认生成的脚本,在这种情况下,它会自动为数据集的所有字段分配数据类型 long,其中包含 64 位值.

    所以我修改了以这种方式更改数据类型的提取脚本:

    @InputData = 
        EXTRACT [Period] string,
                [H_IMSI_BK] string,
                [H_BTSCarrierExternalCode_BK] string,
                [sum_session_duration] int,
                [sum_session_bytes_in] double,
                [sum_session_bytes_out] double,
                [sum_session_count] int,
                [row_count] int
        FROM @data
        USING Extractors.Csv(skipFirstNRows:1);
    

    在处理可空类型时,我以这种方式修改了脚本:

    @imsi_traffic_data =
    SELECT [H_IMSI_BK],
           SUM(([sum_session_bytes_in] + [sum_session_bytes_out]) * [row_count]) ?? 0 AS [total_bytes]
    FROM @InputData
    GROUP BY [H_IMSI_BK];
    

    通过这些更改,脚本可以正常工作。

    【讨论】:

      【解决方案2】:

      原因是当前的 R 集成不支持可为空的类型。 SUM() 运算符返回一个可为空的类型,因此您会收到类型不匹配错误。

      您可以通过将总和的结果转换为不可为空的类型来规避此问题。例如,尝试

      @imsi_traffic_data =
      SELECT [H_IMSI_BK],
             (double) SUM(([sum_session_bytes_in] + [sum_session_bytes_out]) * [row_count]) AS [total_bytes]
      FROM @input
      GROUP BY [H_IMSI_BK];
      

      请注意,我们将在 R 扩展的未来更新中解决此问题。

      【讨论】:

      • 感谢您的回答,但您提出的解决方案不正确,返回相同的错误!我现在解决了错误,问题是列中包含的数据类型。现在我在下面发布正确的解决方案
      • 很高兴听到您找到了解决方案。请注意,您最终仍需要处理空值情况。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-05
      • 2023-04-03
      • 1970-01-01
      • 2015-09-21
      • 1970-01-01
      相关资源
      最近更新 更多