我正在尝试验证U-SQL SELECT中的字符串变量是否可以解释为整数,所以我正在尝试使用int.TryParse将默认值2以及以上所有内容替换为“ 0”和“” 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吗? ...
答案 0 :(得分:1)
感谢wBob的输入。我设法写了一些可行的方法,并根据您的输入将空字符串和默认值替换为超出范围的数字。这是最终代码:
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]
答案 1 :(得分:0)