public async Task JoinHash() { var source = Helpers.CreateSortedTestData(); var transformJoin = new TransformJoin(source, Helpers.CreateUnSortedJoinData(), new List <JoinPair>() { new JoinPair(new TableColumn("StringColumn"), new TableColumn("StringColumn")) }, null, Transform.EDuplicateStrategy.Abend, null, "Join"); Assert.Equal(8, transformJoin.FieldCount); await transformJoin.Open(1, null, CancellationToken.None); Assert.True(transformJoin.JoinAlgorithm == TransformJoin.EJoinAlgorithm.Hash); var pos = 0; while (await transformJoin.ReadAsync()) { pos++; if (pos < 10) { Assert.Equal("lookup" + pos, transformJoin["LookupValue"]); } else { Assert.Null(transformJoin["LookupValue"]); //test the last join which is not found. } } Assert.Equal(10, pos); }
public async Task JoinPreSortFirstFilter() { var source = Helpers.CreateSortedTestData(); var sortedJoinData = new TransformSort(Helpers.CreateDuplicatesJoinData(), new List <Sort>() { new Sort("StringColumn") }); var transformJoin = new TransformJoin(source, sortedJoinData, new List <JoinPair>() { new JoinPair(new TableColumn("StringColumn"), new TableColumn("StringColumn")) }, null, Transform.EDuplicateStrategy.First, new TableColumn("LookupValue", ETypeCode.String, "Join"), "Join"); Assert.Equal(9, transformJoin.FieldCount); await transformJoin.Open(1, null, CancellationToken.None); Assert.True(transformJoin.JoinAlgorithm == TransformJoin.EJoinAlgorithm.Sorted); var pos = 0; while (await transformJoin.ReadAsync()) { pos++; if (pos < 10) { Assert.Equal("lookup" + pos, transformJoin["LookupValue"]); } else { Assert.Null(transformJoin["LookupValue"]); //test the last join which is not found. } } Assert.Equal(10, pos); }
public async Task JoinSortedMissingJoinRow() { var source = Helpers.CreateSortedTestData(); var transformJoin = new TransformJoin(source, Helpers.CreateSortedJoinDataMissingRows(), new List <JoinPair>() { new JoinPair(new TableColumn("StringColumn"), new TableColumn("StringColumn")) }, null, Transform.EDuplicateStrategy.Abend, null, "Join"); Assert.Equal(8, transformJoin.FieldCount); await transformJoin.Open(1, null, CancellationToken.None); Assert.True(transformJoin.JoinAlgorithm == TransformJoin.EJoinAlgorithm.Sorted); var pos = 0; while (await transformJoin.ReadAsync()) { pos++; //Missing rows should be null if (pos == 1 || pos == 5 || pos == 10) { Assert.Null(transformJoin["LookupValue"]); } else { // Other rows should join ok Assert.Equal("lookup" + pos, transformJoin["LookupValue"]); } } Assert.Equal(10, pos); }
public async Task JoinHashDuplicate() { var source = Helpers.CreateSortedTestData(); var transformJoin = new TransformJoin(source, Helpers.CreateDuplicatesJoinData(), new List <JoinPair>() { new JoinPair(new TableColumn("StringColumn"), new TableColumn("StringColumn")) }, null, Transform.EDuplicateStrategy.Abend, null, "Join"); Assert.Equal(9, transformJoin.FieldCount); await transformJoin.Open(1, null, CancellationToken.None); await Assert.ThrowsAsync <TransformException>(async() => { while (await transformJoin.ReadAsync()) { ; } }); }
public async Task JoinSortedPreFilter() { var source = Helpers.CreateSortedTestData(); var sortedJoinData = new TransformSort(Helpers.CreateDuplicatesJoinData(), new List <Sort>() { new Sort("StringColumn") }); var conditions = new List <TransformFunction> { //create a condition to filter only when IsValid == true; new TransformFunction( new Func <bool, bool>((isValid) => isValid), new TableColumn[] { new TableColumn("IsValid", ETypeCode.Boolean, "Join") }, null, null) }; var transformJoin = new TransformJoin(source, sortedJoinData, new List <JoinPair>() { new JoinPair(new TableColumn("StringColumn"), new TableColumn("StringColumn")) }, conditions, Transform.EDuplicateStrategy.Abend, null, "Join"); Assert.Equal(9, transformJoin.FieldCount); await transformJoin.Open(1, null, CancellationToken.None); Assert.True(transformJoin.JoinAlgorithm == TransformJoin.EJoinAlgorithm.Sorted); var pos = 0; while (await transformJoin.ReadAsync()) { pos++; if (pos < 10) { Assert.Equal("lookup" + pos, transformJoin["LookupValue"]); } else { Assert.Null(transformJoin["LookupValue"]); //test the last join which is not found. } } Assert.Equal(10, pos); }
public async Task JoinHashFunctionFilter() { var source = Helpers.CreateSortedTestData(); //create a condition to join the source to the join columns + 1 var conditions = new List <TransformFunction> { new TransformFunction( new Func <int, int, bool>((source1, join) => source1 == (join - 1)), new TableColumn[] { new TableColumn("IntColumn", ETypeCode.Int32), new TableColumn("IntColumn", ETypeCode.Int32, "Join") }, null, null) }; var transformJoin = new TransformJoin(source, Helpers.CreateUnSortedJoinData(), null, conditions, Transform.EDuplicateStrategy.Abend, null, "Join"); Assert.Equal(8, transformJoin.FieldCount); await transformJoin.Open(1, null, CancellationToken.None); Assert.True(transformJoin.JoinAlgorithm == TransformJoin.EJoinAlgorithm.Hash); var pos = 0; while (await transformJoin.ReadAsync()) { pos++; if (pos < 9) { Assert.Equal("lookup" + (pos + 1), transformJoin["LookupValue"]); } else { Assert.Null(transformJoin["LookupValue"]); //test the last join which is not found. } } Assert.Equal(10, pos); }