2017-09-26 74 views
1

比方说,我有一个名为MyAssembly的程序集,其类别MyClass有一个MyFunction(long timestamp)方法(它将datetime作为字符串以YYYY-MM-DD HH24:mm:ss的格式返回)。如果我创建一个脚本这样的工作:即使参数相同(连续),函数是否会被多次调用?

@outputData = 
SELECT MyAssembly.MyClass.MyFunction(t1.timestamp).Substring(0,4) AS Year 
     ,MyAssembly.MyClass.MyFunction(t1.timestamp).Substring(...) AS Month 
     ,MyAssembly.MyClass.MyFunction(t1.timestamp).Substring(...) AS Day 
     ,MyAssembly.MyClass.MyFunction(t1.timestamp).Substring(...) AS Hour 
     ,MyAssembly.MyClass.MyFunction(t1.timestamp).Substring(...) AS Minute 
     ,MyAssembly.MyClass.MyFunction(t1.timestamp).Substring(...) AS Second 
FROM @queryInput AS t1 

会在功能被多次调用或将系统是“聪明”,足以把它只有一次,使用返回值的其他列?如果不是,我有什么选择?

回答

1

我不确定ADLA是否“足够聪明”来处理您的情况,但您可以尝试使用custom processor代替。它会为每一行处理执行一次你的方法。

你的工艺方法应该是这样的:

public override IRow Process(IRow input, IUpdatableRow output) 
{ 
    string timestamp = input.Get<string>("timestamp"); 
    var myFunctionResult = MyAssembly.MyClass.MyFunction(timestamp); 

    output.Set<string>("Year", myFunctionResult.Substring(0,4)); 
    output.Set<string>("Month", myFunctionResult.Substring(...)); 
    //do this for other fields 
    return output.AsReadOnly(); 
} 

而且在USQL你的电话应该是这样的:

@outputData = 
    PROCESS @queryInput 
    PRODUCE Year string, 
     Month string, 
     ... 
    REQUIRED timestamp 
    USING new MyAssembly.MyProcessor(); 
相关问题