Azure Stream Analytics 쿼리에서 LEN 함수 사용 고려사항
Azure Stream Analytics Query 에서 LEN 함수를 사용할 때, NVARCHAR(MAX)를 사용하지 않고 Input Stream을 통해 다른 종류의 DATA TYPE이 들어올 경우 아래와 같은 오류와 함께 JOB 이 실패하게 됩니다.
LEN (string_expression)
"error": "- First parameter of function 'LEN' in expression 'LEN ( 컬럼명 )' has invalid type 'bigint'. 'nvarchar(max)' is expected.\r\n",
"message": "Runtime exception occurred while processing events, - First parameter of function 'LEN' in expression 'LEN ( 컬럼명 )' has invalid type 'bigint'. 'nvarchar(max)' is expected.\r\n, : OutputSourceAlias:sqldb;",
LEN 함수로 처리될 컬럼이 Input Stream을 통해 문자열 DATA TYPE을 보장할 수 없다면 CAST, TRY_CAST로 강제 형변환을 적용해 볼 수 있습니다. 또는 GetType 함수를 사용하여 Data Type을 미리 체크하는 로직을 사용해 볼 수도 있습니다. 다음은 CAST 함수를 사용하여 Bigint 형을 NVARCHAR(MAX)로 변환하여 LEN 함수를 사용한 예제입니다.
OUTPUT DB에 저장된 결과입니다.
[참고자료]
LEN (Azure Stream Analytics)
https://msdn.microsoft.com/en-us/library/azure/dn835034.aspx
Conversion Functions (Azure Stream Analytics)
https://msdn.microsoft.com/en-us/library/azure/dn931792.aspx
작성자: Lai Go / 작성일자: 2017.02.07