-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add StreamTable Inner join functionality to the main SDF
- Loading branch information
Showing
5 changed files
with
186 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package join_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/farbodahm/streame/pkg/core" | ||
"github.com/farbodahm/streame/pkg/functions/join" | ||
"github.com/farbodahm/streame/pkg/state_store" | ||
. "github.com/farbodahm/streame/pkg/types" | ||
|
@@ -135,3 +137,77 @@ func TestInnerJoinStreamTable_WithStreamRecord_JoinSuccessfully(t *testing.T) { | |
err = ss.Close() | ||
assert.Nil(t, err) | ||
} | ||
|
||
// Integration tests | ||
func TestJoin_SimpleStreamTableJoin_ShouldJoinStreamRecordToTableRecord(t *testing.T) { | ||
// User Data | ||
user_input := make(chan Record) | ||
user_output := make(chan Record) | ||
user_errors := make(chan error) | ||
user_schema := Schema{ | ||
Columns: Fields{ | ||
"email": StringType, | ||
"first_name": StringType, | ||
"last_name": StringType, | ||
}, | ||
} | ||
user_sdf := core.NewStreamDataFrame(user_input, user_output, user_errors, user_schema, "user-stream") | ||
|
||
// Order Data | ||
order_input := make(chan Record) | ||
orders_output := make(chan Record) | ||
orders_errors := make(chan error) | ||
orders_schema := Schema{ | ||
Columns: Fields{ | ||
"user_email": StringType, | ||
"amount": IntType, | ||
}, | ||
} | ||
orders_sdf := core.NewStreamDataFrame(order_input, orders_output, orders_errors, orders_schema, "orders-stream") | ||
|
||
// Logic to test | ||
joined_sdf := orders_sdf.Join(&user_sdf, join.Inner, join.JoinCondition{LeftKey: "user_email", RightKey: "email"}, join.StreamTable).(*core.StreamDataFrame) | ||
|
||
go func() { | ||
user_input <- Record{ | ||
Key: "key1", | ||
Data: ValueMap{ | ||
"first_name": String{Val: "foo"}, | ||
"last_name": String{Val: "bar"}, | ||
"email": String{Val: "[email protected]"}, | ||
}, | ||
} | ||
order_input <- Record{ | ||
Key: "key2", | ||
Data: ValueMap{ | ||
"user_email": String{Val: "[email protected]"}, | ||
"amount": Integer{Val: 100}, | ||
}, | ||
} | ||
}() | ||
|
||
ctx, cancel := context.WithCancel(context.Background()) | ||
go joined_sdf.Execute(ctx) | ||
|
||
result := <-joined_sdf.OutputStream | ||
cancel() | ||
// Assertions | ||
expected_record := Record{ | ||
Key: "key2-key1", | ||
Data: ValueMap{ | ||
"user_email": String{Val: "[email protected]"}, | ||
"amount": Integer{Val: 100}, | ||
"first_name": String{Val: "foo"}, | ||
"last_name": String{Val: "bar"}, | ||
"email": String{Val: "[email protected]"}, | ||
}, | ||
Metadata: Metadata{ | ||
Stream: orders_sdf.Name + "-" + user_sdf.Name + join.JoinedStreamSuffix, | ||
}, | ||
} | ||
assert.Equal(t, expected_record, result) | ||
assert.Equal(t, 0, len(user_errors)) | ||
assert.Equal(t, 0, len(orders_errors)) | ||
assert.Equal(t, 0, len(joined_sdf.ErrorStream)) | ||
assert.Equal(t, 0, len(joined_sdf.OutputStream)) | ||
} |