在 U-SQL 中创建一个具有预设数量的相等键的列

Create a column in U-SQL with a preset number of equal keys

我想在 U-SQL 中创建一列数字或键,return 相同数量的相等行,用作 Extension.R.Reducer 上的分区。 例如,如果我将变量用作:

DECLARE @PartitionRows int = 5;

我想获得一些东西,例如列 "Partition":

有什么想法吗?提前致谢!

您可以调整此脚本来执行您想要的操作。 这将分为 3 个分区:

@aLog = 
    SELECT * FROM         
        ( VALUES
        ("ABC", new DateTime(2017,01,01, 05, 00, 00),    new DateTime(2017,01,01, 06, 00, 00)),
        ("XYZ", new DateTime(2017,01,01, 05, 00, 00),    new DateTime(2017,01,01, 06, 00, 00)),
        ("ABC", new DateTime(2017,01,01, 08, 00, 00),    new DateTime(2017,01,01, 09, 00, 00)),
        ("ABC", new DateTime(2017,01,01, 08, 00, 00),    new DateTime(2017,01,01, 10, 00, 00)),
        ("ABC", new DateTime(2017,01,01, 10, 00, 00),    new DateTime(2017,01,01, 14, 00, 00)),
        ("ABC", new DateTime(2017,01,01, 07, 00, 00),    new DateTime(2017,01,01, 11, 00, 00)),
        ("ABC", new DateTime(2017,01,01, 09, 00, 00),    new DateTime(2017,01,01, 11, 00, 00)),
        ("ABC", new DateTime(2017,01,01, 11, 00, 00),    new DateTime(2017,01,01, 11, 30, 00)),
        ("FOO", new DateTime(2017,01,01, 23, 40, 00),    new DateTime(2017,01,01, 23, 59, 00)),
        ("FOO", new DateTime(2017,01,01, 23, 50, 00),    new DateTime(2017,01,02, 00, 40, 00))
        ) AS T(user, begin, end);

@aLog =
    SELECT (ROW_NUMBER() OVER() -1) / 3 AS Partition,
           *
    FROM @aLog;

OUTPUT 
@aLog
TO "/teste.txt"
USING Outputters.Csv();