2017-09-26 7 views
1

MyFunction(long timestamp) 메서드를 사용하는 MyClass 클래스의 MyAssembly 어셈블리가 있다고 가정 해 봅시다. 날짜/시간은 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();