1
+ load " $LIB_BATS_ASSERT /load.bash"
2
+ load " $LIB_BATS_SUPPORT /load.bash"
3
+
4
+ @test " verify column transforms" {
5
+ cat << EOF > $TAILPIPE_INSTALL_DIR /config/format_delimited.tpc
6
+ format "delimited" "transform_test" {
7
+ delimiter = ","
8
+ }
9
+ EOF
10
+
11
+ cat << EOF > $TAILPIPE_INSTALL_DIR /config/table_transform.tpc
12
+ table "transform_test" {
13
+ format = format.delimited.transform_test
14
+
15
+ column "tp_timestamp" {
16
+ source = "timestamp"
17
+ type = "datetime"
18
+ }
19
+
20
+ column "tp_date" {
21
+ source = "timestamp"
22
+ type = "date"
23
+ }
24
+
25
+ column "value_doubled" {
26
+ type = "integer"
27
+ transform = "raw_value * 2"
28
+ }
29
+
30
+ column "status_category" {
31
+ type = "varchar"
32
+ transform = "CASE WHEN status_code < 300 THEN 'success' WHEN status_code < 400 THEN 'redirect' WHEN status_code < 500 THEN 'client_error' ELSE 'server_error' END"
33
+ }
34
+
35
+ column "browser" {
36
+ type = "varchar"
37
+ transform = "CASE WHEN user_agent LIKE '%Windows%' THEN 'Windows' WHEN user_agent LIKE '%Macintosh%' THEN 'Mac' ELSE 'Other' END"
38
+ }
39
+
40
+ column "is_internal" {
41
+ type = "boolean"
42
+ transform = "ip_address LIKE '192.168.%' OR ip_address LIKE '10.%' OR ip_address LIKE '172.16.%'"
43
+ }
44
+
45
+ column "parsed_time" {
46
+ type = "datetime"
47
+ transform = "strptime(CAST(custom_time AS VARCHAR), '%Y-%m-%d %H:%M:%S')"
48
+ }
49
+ }
50
+
51
+ partition "transform_test" "local" {
52
+ source "file" {
53
+ format = format.delimited.transform_test
54
+ paths = ["$SOURCE_FILES_DIR /custom_logs/"]
55
+ file_layout = "transform_data.csv"
56
+ }
57
+ }
58
+ EOF
59
+
60
+ # Run collection and verify
61
+ tailpipe collect transform_test --progress=false --from=2024-05-01
62
+
63
+ # Verify transformations
64
+ run tailpipe query " select value_doubled, status_category, browser, is_internal, parsed_time from transform_test order by tp_timestamp" --output csv
65
+ echo $output
66
+
67
+ assert_equal " $output " " value_doubled,status_category,browser,is_internal,parsed_time
68
+ 84,success,Windows,true,2024-05-01 10:00:00
69
+ 198,client_error,Mac,true,2024-05-01 10:01:00
70
+ 300,server_error,Other,true,2024-05-01 10:02:00"
71
+
72
+ # Cleanup
73
+ rm -rf $TAILPIPE_INSTALL_DIR /config/format_delimited.tpc
74
+ rm -rf $TAILPIPE_INSTALL_DIR /config/table_transform.tpc
75
+ }
76
+
77
+ @test " verify null_if in column blocks" {
78
+ cat << EOF > $TAILPIPE_INSTALL_DIR /config/format_delimited_null.tpc
79
+ format "delimited" "null_if_test" {
80
+ delimiter = ","
81
+ }
82
+ EOF
83
+
84
+ cat << EOF > $TAILPIPE_INSTALL_DIR /config/table_null_if.tpc
85
+ table "null_if_test" {
86
+ format = format.delimited.null_if_test
87
+
88
+ column "tp_timestamp" {
89
+ type = "datetime"
90
+ transform = "now()"
91
+ }
92
+
93
+ column "tp_date" {
94
+ type = "date"
95
+ transform = "current_date"
96
+ }
97
+
98
+ column "id" {
99
+ type = "integer"
100
+ source = "id"
101
+ }
102
+
103
+ column "status" {
104
+ type = "varchar"
105
+ source = "status"
106
+ null_if = "inactive"
107
+ }
108
+
109
+ column "value" {
110
+ type = "integer"
111
+ source = "value"
112
+ null_if = "0"
113
+ }
114
+
115
+ column "description" {
116
+ type = "varchar"
117
+ source = "description"
118
+ }
119
+ }
120
+
121
+ partition "null_if_test" "local" {
122
+ source "file" {
123
+ format = format.delimited.null_if_test
124
+ paths = ["$SOURCE_FILES_DIR /custom_logs/"]
125
+ file_layout = "null_if_data.csv"
126
+ }
127
+ }
128
+ EOF
129
+
130
+ # Run collection and verify
131
+ tailpipe collect null_if_test --progress=false --from=2024-05-01
132
+
133
+ # Verify null_if transformations
134
+ run tailpipe query " select id, status, value, description from null_if_test order by id" --output csv
135
+ echo $output
136
+
137
+ assert_equal " $output " " id,status,value,description
138
+ 1,active,42,normal value
139
+ 2,<null>,<null>,zero value
140
+ 3,active,-1,negative value
141
+ 4,active,2,empty value
142
+ 5,active,999,special value"
143
+
144
+ # Cleanup
145
+ rm -rf $TAILPIPE_INSTALL_DIR /config/format_delimited_null.tpc
146
+ rm -rf $TAILPIPE_INSTALL_DIR /config/table_null_if.tpc
147
+ }
148
+
149
+ function teardown() {
150
+ rm -rf $TAILPIPE_INSTALL_DIR /data
151
+ }
0 commit comments