亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

U-SQL 中的 int.TryParse

U-SQL 中的 int.TryParse

C#
梵蒂岡之花 2023-04-29 10:14:45
我正在嘗試驗證 U-SQL SELECT 中的字符串變量是否可以解釋為整數,因此我正在嘗試使用 int.TryParse 將“0”和“”替換為默認值 2,將 10 以上的所有內容替換為 10 . 這是代碼:DECLARE @maxAvgkWh double = 100.00;DECLARE @defaultM2 int = 90;DECLARE @defaultPersons int = 2;// Extracting installations and their information@forDecisionTree =    EXTRACT [InstallationId] string,            [PrimaryHeatingType] string,            [Persons] string,            [SquareMeters] string,            [LatestAvgDailykWh] double    FROM "adl://some text file in azure data lake"    USING Extractors.Tsv(skipFirstNRows : 1, silent : true);// Making sure that NULLS and zeroes and abnormal values are replaced with default values@forDecisionTreeHouseTypeReplNulls =    SELECT  [InstallationId],            [PrimaryHeatingType],            (                ! int.TryParse(Persons, out var _pers) || _pers <= 0 ?                      @defaultPersons :                    _pers > 10 ?                        10 :                        _pers            ).ToString() AS [Persons],            (                ! int.TryParse([SquareMeters], out var _m2) || _m2 <= 0 ?                      @defaultM2 :                    _m2 > 500 ?                        500 :                        _m2            ).ToString() AS [SquareMeters],            [LatestAvgDailykWh]    FROM @forDecisionTreeHouseType    WHERE [LatestAvgDailykWh] < @maxAvgkWh;我不斷收到以下錯誤:C# 錯誤 CS1003:語法錯誤,',' 預期在標記“_pers”處,### 附近的第 108 行:……!int.TryParse([Persons], out var ### _pers) || _pers <= 0 ? ...
查看完整描述

2 回答

?
繁華開滿天機

TA貢獻1816條經驗 獲得超4個贊

我設法寫了一些有用的東西,并根據您的輸入將空字符串和默認值替換為超出范圍的數字。這是最終代碼:


DECLARE @defaultPersons int = 2;


@forDecisionTreeHouseTypeReplNulls =

    SELECT  [InstallationId],

            [Persons],

                (   

                (Func<string, int?>)

                (inputString => // input_parameter

                    {

                        int _pers;

                        return ! int.TryParse([Persons], out _pers) || _pers <= 0 ?

                            @defaultPersons :

                            _pers > 10 ?

                                10 :

                                    _pers;

                    }

                )

             ) ([Persons]) AS [AdjPersons]


查看完整回答
反對 回復 2023-04-29
?
ibeautiful

TA貢獻1993條經驗 獲得超6個贊

TryParse不是您可以直接調用的功能之一。它必須包裝為內聯函數。一個簡單的例子:


@output =

? ? SELECT FirstName,

? ? ? ? ? ? ? ?(

? ? ? ? ? ? ? ? (Func<string, int?>)

? ? ? ? ? ? ? ? (inputString =>? // input_paramater

? ? ? ? ? ? ? ? ? ? {?

? ? ? ? ? ? ? ? ? ? ? ? int outputValue;

? ? ? ? ? ? ? ? ? ? ? ? return int.TryParse(inputString, out outputValue) ? (int?)outputValue : (int?)null;

? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ?)

? ? ? ? ? ? ) (Salary) AS someDate


? ? FROM @Employees;

查看完整回答
反對 回復 2023-04-29
  • 2 回答
  • 0 關注
  • 172 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號