sql - U-SQL 构建错误,equijoin 有不同的类型

标签 sql analytics azure-data-lake u-sql

我正在尝试创建一个 USQL 作业并从它们将被检索的 CSV 中定义我的列,但是我总是在 JOIN 部分遇到问题,因为我匹配的列是不同的类型。这很奇怪,因为我已经将它们定义为相同的类型。查看问题所在的屏幕截图:

enter image description here

这是完整的 USQL:

@guestCheck = 
    EXTRACT GuestCheckID int,
            POSCheckGUID Guid,
            POSCheckNumber int?,
            OwnerEmployeeID int,
            CreatedDateTime DateTime?,
            ClosedDateTime DateTime?,
            TicketReference string,
            CheckAmount decimal?,
            POSTerminalID int,
            CheckState string,
            LocationID int?,
            TableID int?,
            Covers int?,
            PostedDateTime DateTime?,
            OrderChannelID int?,
            MealPeriodID int?,
            RVCLocationID int?,
            ReopenedTerminalID int?,
            ReopenedEmployeeID int?,
            ReopenedDateTime DateTime?,
            ClosedBusDate int?,
            PostedBusDate int?,
            BusHour byte?,
            TaxExempt bool?,
            TaxExemptReference string
    FROM "/GuestCheck/GuestCheck-incomplete.csv"
    USING Extractors.Csv();

@guestCheckAncillaryAmount =
    EXTRACT CheckAncillaryAmountID int,
            GuestCheckID int,
            GuestCheckItemID int?,
            AncillaryAmountTypeID int,
            Amount decimal,
            FirstDetail int?,
            LastDetail int?,
            IsReturn bool?,
            ReturnReasonID int?,
            AncillaryReasonID int?,
            AncillaryNote string,
            ClosedBusDate int?,
            PostedBusDate int?,
            BusHour byte?,
            LocationID int?,
            RVCLocationID int?,
            IsDelisted bool?,
            Exempted bool?
    FROM "/GuestCheck/GuestCheckAncillaryAmount.csv"
    USING Extractors.Csv();

@ancillaryAmountType = 
    EXTRACT AncillaryAmountTypeID int,
            AncillaryAmountCategoryID int,
            CustomerID int,
            CheckTitle string,
            ReportTitle string,
            Percentage decimal,
            FixedAmount decimal,
            IncludeOnCheck bool,
            AutoCalculate bool,
            StoreAtCheckLevel bool?,
            DateTimeModified DateTime?,
            CheckTitleToken Guid?,
            ReportTitleToken Guid?,
            DeletedFlag bool,
            MaxUsageQty int?,
            ApplyToBasePriceOnly bool?,
            Exclusive bool,
            IsItem bool,
            MinValue decimal,
            MaxValue decimal,
            ItemGroupID int?,
            LocationID int,
            ApplicationOrder int?,
            RequiresReason bool,
            Exemptable bool?
    FROM "/GuestCheck/AncillaryAmountType.csv"
    USING Extractors.Csv();

@read =
    SELECT t.POSCheckGUID,
           t.POSCheckNumber,
           t.CheckAmount,
           aat.AncillaryAmountTypeID,
           aat.CheckTitle,
           gcd.Amount
    FROM @guestCheck AS t         
         LEFT JOIN
             @guestCheckAncillaryAmount AS gcd
         ON t.GuestCheckID == gcd.GuestCheckID
         LEFT JOIN
             @ancillaryAmountType AS aat
         ON gcd.AncillaryAmountTypeID == aat.AncillaryAmountTypeID
    WHERE aat.AncillaryAmountCategoryID IN(2, 4, 8);

OUTPUT @read
TO "/GuestCheckOutput/output.csv"
USING Outputters.Csv();

最佳答案

事实上,U-SQL 是强类型的,而且 intint?是不同的类型。您需要在中间行集中进行转换:

@ancillaryAmountType2 =
SELECT (int?) aat.AncillaryAmountTypeID AS AncillaryAmountTypeID,
       aat.AncillaryAmountCategoryID,
       aat.CheckTitle
FROM @ancillaryAmountType AS aat;

或者,更好的是,使用维度建模最佳实践,并出于 http://blog.chrisadamson.com/2013/01/avoid-null-in-dimensions.html 中所述的原因避免可空的“维度”。 .

关于sql - U-SQL 构建错误,equijoin 有不同的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40912416/

相关文章:

javascript - Firefox Quantum 私有(private)浏览器不加载由 javascript 添加的脚本

javascript - Analytics + Facebook 跟踪 Javascript 问题与 document.getElementsByTagName ('script' )[0]

sql - 如何在SQL Server 2008中创建复合主键

mysql - 需要帮助创建数据库结构

mysql - 使用 Makefile 在 Docker 容器内运行 SQL 脚本

sql - Oracle SQL : Using Variables in If Then Statement

google-analytics - 2 个用户但 0 个 session ?

azure - U-SQL 错误 - 更改标识符以使用至少一个小写字母

azure - Hive 管理的表不会掉落在 azure 数据湖存储上

azure - 从 JSON 复杂类型获取数据的 U-SQL 脚本存在语法错误