|
28 | 28 | from apache_beam.examples.snippets.transforms.elementwise.enrichment import enrichment_with_bigtable, \ |
29 | 29 | enrichment_with_vertex_ai_legacy |
30 | 30 | from apache_beam.examples.snippets.transforms.elementwise.enrichment import enrichment_with_vertex_ai |
| 31 | + from apache_beam.examples.snippets.transforms.elementwise.enrichment import enrichment_with_tecton |
31 | 32 | from apache_beam.io.requestresponse import RequestResponseIO |
32 | 33 | except ImportError: |
33 | 34 | raise unittest.SkipTest('RequestResponseIO dependencies are not installed') |
@@ -60,6 +61,15 @@ def validate_enrichment_with_vertex_ai_legacy(): |
60 | 61 | return expected |
61 | 62 |
|
62 | 63 |
|
| 64 | +def validate_enrichment_with_tecton(): |
| 65 | + expected = '''[START enrichment_with_tecton] |
| 66 | +Row(user_id='user_9979340926', user_transaction_metrics.amount_count_1d_1d=1, user_transaction_metrics.amount_count_3d_1d=3, user_transaction_metrics.amount_count_7d_1d=7, user_transaction_metrics.amount_mean_1d_1d=65.05, user_transaction_metrics.amount_mean_3d_1d=42.72333333333333, user_transaction_metrics.amount_mean_7d_1d=32.955714285714286) |
| 67 | +Row(user_id='user_1990251765', user_transaction_metrics.amount_count_1d_1d=None, user_transaction_metrics.amount_count_3d_1d=2, user_transaction_metrics.amount_count_7d_1d=3, user_transaction_metrics.amount_mean_1d_1d=None, user_transaction_metrics.amount_mean_3d_1d=25.880000000000003, user_transaction_metrics.amount_mean_7d_1d=27.796666666666667) |
| 68 | +Row(user_id='user_1284832379', user_transaction_metrics.amount_count_1d_1d=2, user_transaction_metrics.amount_count_3d_1d=6, user_transaction_metrics.amount_count_7d_1d=12, user_transaction_metrics.amount_mean_1d_1d=111.465, user_transaction_metrics.amount_mean_3d_1d=61.961666666666666, user_transaction_metrics.amount_mean_7d_1d=171.5625) |
| 69 | + [END enrichment_with_tecton]'''.splitlines()[1:-1] |
| 70 | + return expected |
| 71 | + |
| 72 | + |
63 | 73 | def std_out_to_dict(stdout_lines, row_key): |
64 | 74 | output_dict = {} |
65 | 75 | for stdout_line in stdout_lines: |
@@ -107,6 +117,16 @@ def test_enrichment_with_vertex_ai_legacy(self, mock_stdout): |
107 | 117 | std_out_to_dict(output, 'entity_id'), |
108 | 118 | std_out_to_dict(expected, 'entity_id')) |
109 | 119 |
|
| 120 | + def test_enrichment_with_tecton(self, mock_stdout): |
| 121 | + enrichment_with_tecton() |
| 122 | + output = mock_stdout.getvalue().splitlines() |
| 123 | + expected = validate_enrichment_with_tecton() |
| 124 | + |
| 125 | + self.assertEqual(len(output), len(expected)) |
| 126 | + self.assertEqual( |
| 127 | + std_out_to_dict(output, 'user_id'), |
| 128 | + std_out_to_dict(expected, 'user_id')) |
| 129 | + |
110 | 130 |
|
111 | 131 | if __name__ == '__main__': |
112 | 132 | unittest.main() |
0 commit comments