Azure Data Lake中的U-SQL查询错误

时间:2018-03-07 17:27:58

标签: c# json azure azure-data-lake u-sql

我在U-SQL查询中遇到错误:

E_CSC_USER_SYNTAXERROR: syntax error. Expected one of: '.' ALL ANTISEMIJOIN ANY AS BROADCASTLEFT BROADCASTRIGHT CROSS DISTINCT EXCEPT FULL FULLCROSS GROUP HASH HAVING INDEXLOOKUP INNER INTERSECT JOIN LEFT LOOP MERGE ON OPTION ORDER OUTER OUTER UNION PAIR PIVOT PRESORT PRODUCE READONLY REQUIRED RIGHT SAMPLE SEMIJOIN SERIAL SORTED TO UNIFORM UNION UNIVERSE UNPIVOT USING WHERE WITH ';' '(' ')' ','
Line 19
Component
CSC
Message
syntax error. Expected one of: '.' ALL ANTISEMIJOIN ANY AS BROADCASTLEFT BROADCASTRIGHT CROSS DISTINCT EXCEPT FULL FULLCROSS GROUP HASH HAVING INDEXLOOKUP INNER INTERSECT JOIN LEFT LOOP MERGE ON OPTION ORDER OUTER OUTER UNION PAIR PIVOT PRESORT PRODUCE READONLY REQUIRED RIGHT SAMPLE SEMIJOIN SERIAL SORTED TO UNIFORM UNION UNIVERSE UNPIVOT USING WHERE WITH ';' '(' ')' ','
Resolution
Correct the script syntax, using expected token(s) as a guide.
Description
Invalid syntax found in the script.
Details
at token 'string', line 19
near the ###:
**************

    Custom string,
    ttl int
    FROM @INPUT_FILE
    USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor("$.[*]");

@jsonnodes =
    Partition  ### string, 
    SELECT JsonApp.JsonFunctions.JsonTuple(System).Values AS system_array,
    SELECT JsonApp.JsonFunctions.JsonTuple(Custom).Values AS custom_array,

这是我的u-sql查询:

@json =
    EXTRACT 
    Partition string, 
    System string,
    Custom string,
    ttl int
    FROM @INPUT_FILE
    USING new Microsoft.Analytics.Samples.Formats.Json.JsonExtractor("$.[*]");

@jsonnodes =
    Partition string, 
    SELECT JsonApp.JsonFunctions.JsonTuple(System).Values AS system_array,
    SELECT JsonApp.JsonFunctions.JsonTuple(Custom).Values AS custom_array,
    ttl
    FROM @json;

我在获取@jsonnodes查询中的值时收到错误。

此外,应该使用什么json路径来遍历JSON中的所有对象?

2 个答案:

答案 0 :(得分:2)

纠正西蒙的回答:

原始脚本使用了无效语法(SELECT或EXTRACT之外的列名/类型对,然后是单个查询中的几个SELECT子句):

@jsonnodes =
  Partition string, 
  SELECT JsonApp.JsonFunctions.JsonTuple(System).Values AS system_array,
  SELECT JsonApp.JsonFunctions.JsonTuple(Custom).Values AS custom_array,
  ttl
  FROM @json;

您可能只想选择已提取的列和各个表达式,因此您将名称(不带类型!)移到SELECT语句中,并仅使用一个 SELECT条款如下:

@jsonnodes =
SELECT 
    Partition, 
    JsonApp.JsonFunctions.JsonTuple(System).Values AS system_array,
    JsonApp.JsonFunctions.JsonTuple(Custom).Values AS custom_array,
    ttl
FROM @json;

答案 1 :(得分:1)

与在SQL中一样,您只能在语句中使用SELECT一次,就像您对EXTRACT语句所做的那样,所以您的代码应如下所示:

@jsonnodes =
SELECT 
    Partition string, 
    JsonApp.JsonFunctions.JsonTuple(System).Values AS system_array,
    JsonApp.JsonFunctions.JsonTuple(Custom).Values AS custom_array,
    ttl
FROM @json;

当您查看JSON路径示例here时,您可以看到可以使用$ .. *路径来获取所有对象,或仅使用$ [*]作为第一级对象。