Loops 如何使用U-SQL迭代SELECT查询的结果以查找行模式
我在变量中有一个SELECT查询的结果,现在我想逐行遍历查询结果以进行一些处理,比如查找特定模式。例如,模式可以如下所示:Loops 如何使用U-SQL迭代SELECT查询的结果以查找行模式,loops,u-sql,Loops,U Sql,我在变量中有一个SELECT查询的结果,现在我想逐行遍历查询结果以进行一些处理,比如查找特定模式。例如,模式可以如下所示: a, b, c, d, e b, c, d, e, f c, d, e, f, g CSV中SELECT查询的结果可能是: 1, 2, 3, 4, 5 3, 4, 5, 6, 7 a, b, c, d, e b, c, d, e, f c, d, e, f, g 5, 6, 7, 8, 9 我见过一些关于使用自定义提取器的流程语句的情况,但这是实现它的方法吗?我不确定这
a, b, c, d, e
b, c, d, e, f
c, d, e, f, g
CSV中SELECT查询的结果可能是:
1, 2, 3, 4, 5
3, 4, 5, 6, 7
a, b, c, d, e
b, c, d, e, f
c, d, e, f, g
5, 6, 7, 8, 9
我见过一些关于使用自定义提取器的流程语句的情况,但这是实现它的方法吗?我不确定这个过程和提取器是如何工作的
谢谢您的帮助。我认为您不需要重复。一个更加基于集合的方法对你有用吗?试试我创建的这个示例U-SQL脚本。基本上,如果有匹配,结果将在文件中,如果没有匹配,文件将为空
// Set the search pattern
@pattern =
SELECT *
FROM ( VALUES
( "a", "b", "c", "d", "e" ),
( "b", "c", "d", "e", "f" ),
( "c", "d", "e", "f", "g" )
) AS t (col1, col2, col3, col4, col5 );
// Get the file to search
@input =
EXTRACT col1 string,
col2 string,
col3 string,
col4 string,
col5 string
FROM "/input/input.csv"
USING Extractors.Csv();
// Add rowIds
@pattern =
SELECT ROW_NUMBER() OVER() AS rowId, *
FROM @pattern;
@input =
SELECT ROW_NUMBER() OVER() AS rowId, *
FROM @input;
// Check the same rows appear in the same order
@temp =
SELECT i.rowId,
p.rowId == null ? 0 : ROW_NUMBER() OVER( ORDER BY p.rowId ) AS rowId2 // Restarts the row numbering when there is a match
FROM @input AS i
LEFT OUTER JOIN
@pattern AS p
ON i.col1 == p.col1
AND i.col2 == p.col2
AND i.col3 == p.col3
AND i.col4 == p.col4
AND i.col5 == p.col5;
@output =
SELECT p.*
FROM @pattern AS p
INNER JOIN
@temp AS t
ON p.rowId == t.rowId2;
@pattenRecords =
SELECT COUNT( * ) AS records
FROM @pattern;
@records =
SELECT COUNT( * ) AS records
FROM @output;
// Join criteria mean output file will be empty if there has not been a match
@output =
SELECT o.*
FROM @output AS o
CROSS JOIN @records AS r
INNER JOIN
(
SELECT *
FROM @pattenRecords
INTERSECT
SELECT *
FROM @records
) AS t ON r.records == t.records;
// Output results
OUTPUT @output
TO "/output/output.csv"
USING Outputters.Csv();
也许有一个更简单的方法。不太清楚如何从第一个结果集到第二个结果集?逻辑是什么?也许你可以做一个相当传统的集合操作,再加上一些.net字符串操作来获得结果,而不必编写一个完整的自定义提取器。嗨@wBob,我想从第二个集合中提取第一个集合中的模式。将第二个集合视为数据集或来自SELECT查询的结果。我需要按顺序找到那个特殊的图案。我知道我可以在WHERE子句中使用OR,但这可能会给出不在该模式内的其他条目。关于这一条的任何反馈@MichaelRys。最好知道是否有一种更简单的方法。这种声明式方法肯定是一种好方法。替代方案包括编写自定义组合器,或将模式移动到资源文件或复杂类型(映射数组)中,并将其传递给缩减器。不过,后面两种方法的规模可能都不如上面的声明式方法。