【问题标题】:USQL create user defined table type with user defined data type columnsUSQL 使用用户定义的数据类型列创建用户定义的表类型
【发布时间】:2018-05-08 14:45:46
【问题描述】:

我将用户定义类型定义为

namespace AddOns{
[SqlUserDefinedType(typeof(JsonObjectFormatter))]
    public class JsonObject
    {
        public string Value {get;set;}
        ... // this is just a dummy representation 
    }
}

我想定义一个返回数据类型的表值函数

REFERENCE ASSEMBLY [AddOns];

CREATE TYPE Insight.dbo.JsonRow
AS TABLE
(
        [Id] Guid,
        [Value] AddOns.JsonObject
);

但是我得到一个错误

'E_CSC_USER_INVALIDCOLUMNTYPE: 'AddOns.JsonObject' cannot be used as column type.
Description:
The column type must be a supported scalar, complex or user defined type.
Resolution:
Ensure the column type is a supported type. For a user defined type, make sure the type is registered, the type name is fully qualified, and the required assembly is referenced by the script.'
*** Compile failed !

我已经在我的本地 ADLA 实例中注册了适当的 DLL,并且当我将数据保存到文件时,我能够访问过程 SELECT 语句中的类型。但不能将其作为 TVF 返回类型返回

【问题讨论】:

    标签: azure-data-lake u-sql


    【解决方案1】:

    在创建自定义类型时,您只能使用内置类型。来自the MS documentation page(我粘贴的最后一行字面说只有内置类型):

    U-SQL 可以使用 CREATE TYPE 语句命名和注册表类型。

    Create_Type_Statement :=                                                                                 
        'CREATE' 'TYPE' ['IF' 'NOT' 'EXISTS'] Type_Identifier   
        'AS' Anonymous_Table_Type.
    Type_Identifier := 
        DB_Object_Identifier.
    
    Anonymous_Table_Type :=  
        'TABLE' '(' Column_Definition_List ')'.
    

    语法元素的语义

    ...

    Column_Definition_List

    定义表模式如下:

    Column_Definition_List :=                                                                           
         Column_Definition { ',' Column_Definition }.
    

    列定义

    列定义的格式为

    Column_Definition :=    
        Quoted_or_Unquoted_Identifier Built_in_Type.
    

    【讨论】:

    • 如果您选择使用 ArrayAgg(复杂的内置类型)以基元形式存储数据,您可能会找到解决方案 here
    猜你喜欢
    • 1970-01-01
    • 2011-01-26
    • 2014-12-30
    • 2014-04-18
    • 2014-01-19
    • 1970-01-01
    • 1970-01-01
    • 2021-08-25
    • 2017-01-24
    相关资源
    最近更新 更多