2017-09-26 28 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(); 
相關問題