-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
57 lines (53 loc) · 2.44 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
CXX = g++-4.8
CXXFLAGS = -O3 -D HAVE_LONG_INT_64 -std=c++11 -Wall -shared -Wno-unused-value -fPIC
INCPATH = -I /opt/vertica/sdk/include
VERPATH = /opt/vertica/sdk/include/Vertica.cpp
UDXLIBNAME = lmad
UDXLIB = /tmp/$(UDXLIBNAME).so
UDXSRC = $(UDXLIBNAME).cpp
compile: $(UDXSRC)
$(CXX) $(CXXFLAGS) $(INCPATH) -o $(UDXLIB) $(UDXSRC) $(VERPATH)
deploy: $(UDXLIB)
@echo " \
CREATE OR REPLACE LIBRARY $(UDXLIBNAME) AS '$(UDXLIB)' LANGUAGE 'C++'; \
CREATE OR REPLACE TRANSFORM FUNCTION mad AS LANGUAGE 'C++' NAME 'MadFactory' LIBRARY $(UDXLIBNAME) ; \
GRANT EXECUTE ON TRANSFORM FUNCTION mad(x FLOAT) TO PUBLIC ; \
" | vsql -U dbadmin -X -f - -e
test:
@echo " \
WITH test_mad(ts, val) AS ( \
SELECT '2019-10-11 09:12:00'::TIMESTAMP, 3.0 UNION ALL \
SELECT '2019-10-11 09:12:01'::TIMESTAMP, 4.0 UNION ALL \
SELECT '2019-10-11 09:12:02'::TIMESTAMP, 5.0 UNION ALL \
SELECT '2019-10-11 09:12:03'::TIMESTAMP, 6.0 UNION ALL \
SELECT '2019-10-11 09:12:04'::TIMESTAMP, 7.0 UNION ALL \
SELECT '2019-10-11 09:12:05'::TIMESTAMP, 21.0 UNION ALL \
SELECT '2019-10-11 09:12:06'::TIMESTAMP, 10.0 UNION ALL \
SELECT '2019-10-11 09:12:07'::TIMESTAMP, 9.0 UNION ALL \
SELECT '2019-10-11 09:12:08'::TIMESTAMP, 24.0 UNION ALL \
SELECT '2019-10-11 09:12:09'::TIMESTAMP, 3.0 UNION ALL \
SELECT '2019-10-11 09:12:10'::TIMESTAMP, 3.0 UNION ALL \
SELECT '2019-10-11 09:12:11'::TIMESTAMP, 5.0 UNION ALL \
SELECT '2019-10-11 09:12:12'::TIMESTAMP, 8.0 UNION ALL \
SELECT '2019-10-11 09:12:13'::TIMESTAMP, 31.0 UNION ALL \
SELECT '2019-10-11 09:12:14'::TIMESTAMP, 8.0 UNION ALL \
SELECT '2019-10-11 09:12:15'::TIMESTAMP, 23.0 UNION ALL \
SELECT '2019-10-11 09:12:16'::TIMESTAMP, 9.0 UNION ALL \
SELECT '2019-10-11 09:12:17'::TIMESTAMP, 4.0 UNION ALL \
SELECT '2019-10-11 09:12:18'::TIMESTAMP, 3.0 UNION ALL \
SELECT '2019-10-11 09:12:19'::TIMESTAMP, 2.0 UNION ALL \
SELECT '2019-10-11 09:12:20'::TIMESTAMP, 1.0 \
) \
SELECT a.ts, a.val, b.median::NUMERIC(7,4), b.mad::NUMERIC(7,4), b.cutoff::NUMERIC(7,4), \
CASE WHEN (b.cutoff > 2) THEN '*' ELSE '' END AS outlier \
FROM (\
( SELECT ts, val, ROW_NUMBER() OVER(ORDER BY ts) AS rownum FROM test_mad ) a\
INNER JOIN \
( SELECT mad(val USING PARAMETERS setsize=5) OVER(ORDER BY ts) FROM test_mad ) b \
USING ( rownum ) \
) \
" | vsql -U dbadmin -X -f -
clean:
@echo " \
DROP LIBRARY $(UDXLIBNAME) CASCADE ; \
" | vsql -U dbadmin -X -f - -e