summaryrefslogtreecommitdiff
path: root/tests/examplefiles/gsql/test.gsql
blob: 9b8477bf10eb01963df8894709566a6aac304a69 (plain)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
CREATE QUERY Member_Likeness(VERTEX <motionMember> m1, STRING inDate) FOR GRAPH motionData {
	# TYPEDEF TUPLE <x FLOAT, y FLOAT> XYPair;
	MapAccum<VERTEX<motionMember>, MapAccum<STRING, FLOAT>> @@likenessAccum;
	MapAccum<VERTEX<motionMember>, FLOAT> @@BirthYearAccum;
	MapAccum<VERTEX<motionMember>, FLOAT> @@HeightAccum;
	MapAccum<VERTEX<motionMember>, FLOAT> @@WeightAccum;
	ListAccum<VERTEX<location>> @@MemLocAccum;
	MapAccum<VERTEX<motionMember>, FLOAT> @@LocAccum;
	MapAccum<VERTEX<motionMember>, BagAccum<VERTEX<incentive>>> @@DayIncentives;
	MapAccum<VERTEX<motionMember>, MapAccum<STRING, FLOAT>> @@MemberStats;
	BagAccum<VERTEX<incentive>> @MemberIncentives;
	AvgAccum @@StepsAccum;
	AvgAccum @@BoutsAccum;
	AvgAccum @@MilesAccum;

	# Universal Vars
	INT lastMax = 0;
	INT lastMin = 1000;
	FLOAT mult;

	# Age Vars
	INT ageRange;
	INT birthYear;

	# Height Vars
	INT heightRange;
	INT height;

	# Height Vars
	INT weightRange;
	INT weight;

	# Location Vars
	FLOAT locRange;
	VERTEX memLoc;

	# Activity Vars
	DATETIME lastRecording;

	# lastRecording = to_datetime("2018-05-19");
	lastRecording = to_datetime(inDate);

    /*

    test comment block

    */


	members = {motionMember.*};

	birthYear = Get_Birth_Year(m1);
	height = m1.Height;
	weight = m1.Weight;
	temp = SELECT loc FROM members:member -(:e) - location: loc
	  WHERE member == m1
	    ACCUM
	      @@MemLocAccum += loc;
	FOREACH loc in @@MemLocAccum DO
	  memLoc = loc;
	  END;

	PRINT memLoc;
	PRINT birthYear;
	PRINT height;
	PRINT weight;

	results = SELECT member FROM members:member
	  ACCUM
	    @@BirthYearAccum += (member -> abs(Get_Birth_Year(member) - birthYear));

	FOREACH (member,bys) in @@BirthYearAccum DO
	  IF bys > lastMax THEN
	    lastMax = bys;
	    END;
	  IF bys < lastMin THEN
	    lastMin = bys;
	    END;
	  END;

	ageRange = lastMax - lastMin;
	print ageRange;
	mult = 1.0/ageRange;


	FOREACH (member,bys) in @@BirthYearAccum DO
	  bys = 1 - bys * mult;
	  @@likenessAccum += (member -> ("age" -> bys));
	  END;

	lastMax = 0;
	lastMin = 1000;
	mult = 0;

	results = SELECT member FROM members:member
	  ACCUM
	    @@HeightAccum += (member -> abs(member.Height - height));

	FOREACH (member,heights) in @@HeightAccum DO
	  IF heights < height THEN
	    IF heights > lastMax THEN
	      lastMax = heights;
	      END;
	    IF heights < lastMin THEN
	      lastMin = heights;
	      END;
	    END;
	  END;

	heightRange = lastMax - lastMin;
	print heightRange;
	mult = 1.0/heightRange;


	FOREACH (member,heights) in @@HeightAccum DO
	  IF heights < height THEN
	    heights = 1 - heights * mult;
	  ELSE
	    heights = 0;
	    END;
	  @@likenessAccum += (member -> ("height" -> heights));
	  END;

	lastMax = 0;
	lastMin = 1000;
	mult = 0;

	results = SELECT member FROM members:member
	  ACCUM
	    @@WeightAccum += (member -> abs(member.Weight - weight));

	FOREACH (member,weights) in @@WeightAccum DO
	  IF weights < weight THEN
	    IF weights > lastMax THEN
	      lastMax = weights;
	      END;
	    IF weights < lastMin THEN
	      lastMin = weights;
	      END;
	    END;
	  END;

	weightRange = lastMax - lastMin;
	print weightRange;
	mult = 1.0/weightRange;


	FOREACH (member,weights) in @@WeightAccum DO
	  IF weights < weight THEN
	    weights = 1 - weights * mult;
	  ELSE
	    weights = 0;
	    END;
	  @@likenessAccum += (member -> ("weight" -> weights));
	  END;

	lastMax = 0;
	lastMin = 1000;
	mult = 0;

	resultsLoc = SELECT loc FROM members:member -(:e) - location: loc
	  ACCUM
	    @@LocAccum += (member -> Check_Distance(loc,memLoc));
	FOREACH (member,loc) in @@LocAccum DO
	  IF loc < 5800 THEN
	    IF loc > lastMax THEN
	      lastMax = ceil(loc);
	      END;
	    IF loc < lastMin THEN
	      lastMin = floor(loc);
	      END;
	    END;
	  END;

	PRINT lastMax;
	PRINT lastMin;

	locRange = lastMax - lastMin;
	print locRange;
	mult = 1.0/locRange;

	FOREACH (member,loc) in @@LocAccum DO
	  IF loc > 5800 THEN
	    loc = -1;
	  ELSE
	    loc = 1 - loc * mult;
	    END;
	  @@likenessAccum += (member -> ("distance" -> loc));
	  END;

	lastMax = 0;
	lastMin = 1000;
	mult = 0;

	incentives = {incentive.*};

	incentives = SELECT incent FROM incentives:incent - (:e) - lookupRule:rule WHERE
	  rule.RuleName == "Tenacity" AND incent.IncentiveDate > datetime_sub(lastRecording, INTERVAL 1 MONTH) AND incent.IncentiveDate < lastRecording;

	members = SELECT member FROM incentives:incent - (:e) - motionMember:member
	  ACCUM
	    @@DayIncentives += (member -> (incent));

	FOREACH (member, incent) IN @@DayIncentives DO
	  @@StepsAccum = 0;
	  FOREACH Incentive IN incent DO
	      @@StepsAccum += Incentive.TotalSteps;
	      @@BoutsAccum += Incentive.TotalBouts;
	      @@MilesAccum += Incentive.Miles;
	    END;
	  @@MemberStats += (member -> ("stepsAvg" -> @@StepsAccum));
	  @@MemberStats += (member -> ("stepsSlope" -> Linear_Regression(incent, 1)));
	  # @@MemberStats += (member -> ("boutsAvg" -> @@BoutsAccum));
	  # @@MemberStats += (member -> ("boutsSlope" -> Linear_Regression(incent, 2)));
	  @@MemberStats += (member -> ("milesAvg" -> @@MilesAccum));
	  @@MemberStats += (member -> ("milesSlope" -> Linear_Regression(incent, 3)));
	  END;


	PRINT @@MemberStats;
	PRINT @@likenessAccum;

}

# Test end-of-line comments and multiline comments for PR#2002
USE GLOBAL # end of line comment
DROP GRAPH Patents
CREATE GRAPH Patents()

CREATE SCHEMA_CHANGE JOB do_schema_change FOR GRAPH Patents { # add vertex and edge types
       /*
       We add vertex and edge types to our empty graph
       The job will be run then we will drop the job
       */
  ADD VERTEX Address(PRIMARY_ID id STRING, line1 STRING, line2 STRING, line3 STRING) WITH PRIMARY_ID_AS_ATTRIBUTE="true"; # ID will be concatenation of several fields

}
RUN SCHEMA_CHANGE JOB do_schema_change
DROP JOB do_schema_change

# Tests for PR#2006
# Test lexer hang with params following SET<STRING> param
CREATE QUERY tg_astar (VERTEX source_vertex, VERTEX target_vertex, SET<STRING> e_type, STRING wt_type, STRING latitude, STRING longitude,
STRING wt_attr, BOOL display = False) {
       # empty body for testing
}

# Test $(0), $"field", and empty positional parameter _
CREATE LOADING JOB load_job_supplychain FOR GRAPH SupplyChain {
  DEFINE FILENAME Inventory="m1:/home/tigergraph/mydata/supplychain/Inventory.csv";
  LOAD Inventory TO EDGE in_warehouse_inventory VALUES($"warehouse", $1, $2) USING SEPARATOR=",", HEADER="true", EOL="\n";
}