sparkql 0.1.8 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,108 +16,132 @@ module Sparkql
16
16
  ##### State transition tables begin ###
17
17
 
18
18
  racc_action_table = [
19
- 35, 4, 31, 5, 6, 14, 15, 16, 18, 19,
20
- 21, 23, 26, 32, 14, 15, 16, 18, 19, 21,
21
- 23, 14, 15, 16, 18, 19, 21, 23, 39, 13,
22
- 12, 4, 40, 5, 6, 4, 10, 5, 6, 13,
23
- 29, 28, 14, 15, 16 ]
19
+ 49, 14, 13, 45, 43, 29, 30, 31, 32, 33,
20
+ 34, 35, 27, 46, 29, 30, 31, 32, 33, 34,
21
+ 35, 27, 19, 38, 39, 12, 40, 41, 29, 30,
22
+ 31, 32, 33, 34, 35, 27, -26, 38, 39, 55,
23
+ 40, 41, 8, 56, 9, 44, 10, 11, 8, nil,
24
+ 9, nil, 10, 11, 27, nil, 29, 30, 31, 9,
25
+ nil, 10, 11, 9, nil, 10, 11, 9, nil, 10,
26
+ 11, 14, 13, 15, 16 ]
24
27
 
25
28
  racc_action_check = [
26
- 32, 13, 22, 13, 13, 32, 32, 32, 32, 32,
27
- 32, 32, 10, 25, 10, 10, 10, 10, 10, 10,
28
- 10, 40, 40, 40, 40, 40, 40, 40, 36, 8,
29
- 7, 4, 36, 4, 4, 0, 2, 0, 0, 11,
30
- 12, 11, 31, 31, 31 ]
29
+ 45, 18, 18, 26, 18, 45, 45, 45, 45, 45,
30
+ 45, 45, 15, 37, 15, 15, 15, 15, 15, 15,
31
+ 15, 46, 12, 46, 46, 1, 46, 46, 56, 56,
32
+ 56, 56, 56, 56, 56, 16, 24, 16, 16, 50,
33
+ 16, 16, 9, 50, 9, 25, 9, 9, 0, nil,
34
+ 0, nil, 0, 0, 44, nil, 44, 44, 44, 13,
35
+ nil, 13, 13, 8, nil, 8, 8, 14, nil, 14,
36
+ 14, 2, 2, 6, 6 ]
31
37
 
32
38
  racc_action_pointer = [
33
- 30, nil, 33, nil, 26, nil, nil, 30, 25, nil,
34
- 3, 35, 40, -4, nil, nil, nil, nil, nil, nil,
35
- nil, nil, -8, nil, nil, 8, nil, nil, nil, nil,
36
- nil, 31, -6, nil, nil, nil, 22, nil, nil, nil,
37
- 10, nil ]
39
+ 43, 25, 66, nil, nil, nil, 70, nil, 56, 37,
40
+ nil, nil, 22, 52, 60, 1, 24, nil, -4, nil,
41
+ nil, nil, nil, nil, 24, 33, -4, nil, nil, nil,
42
+ nil, nil, nil, nil, nil, nil, nil, 1, nil, nil,
43
+ nil, nil, nil, nil, 43, -8, 10, nil, nil, nil,
44
+ 31, nil, nil, nil, nil, nil, 15, nil ]
38
45
 
39
46
  racc_action_default = [
40
- -2, -4, -30, -6, -30, -9, -10, -30, -1, -3,
41
- -30, -30, -30, -30, -23, -24, -25, -5, -26, -27,
42
- -11, -28, -12, -29, -13, -30, -16, -21, -8, 42,
43
- -7, -30, -30, -22, -19, -14, -30, -17, -20, -15,
44
- -30, -18 ]
47
+ -2, -42, -1, -3, -4, -5, -42, -8, -42, -42,
48
+ -13, -14, -42, -42, -42, -42, -42, -9, -42, 58,
49
+ -10, -11, -6, -15, -16, -17, -42, -20, -25, -30,
50
+ -31, -32, -33, -34, -35, -36, -7, -42, -37, -38,
51
+ -39, -40, -41, -12, -42, -42, -42, -27, -28, -18,
52
+ -42, -21, -23, -24, -29, -19, -42, -22 ]
45
53
 
46
54
  racc_goto_table = [
47
- 27, 37, 8, 22, 20, 17, 11, 24, 25, 41,
48
- 36, 30, 7, nil, nil, nil, nil, nil, nil, nil,
49
- nil, 33 ]
55
+ 37, 51, 28, 24, 2, 17, 25, 22, 50, 23,
56
+ 20, 21, 57, 18, 36, 1, nil, nil, nil, nil,
57
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
58
+ 54, 47, 48 ]
50
59
 
51
60
  racc_goto_check = [
52
- 14, 13, 2, 9, 8, 6, 2, 10, 11, 13,
53
- 12, 3, 1, nil, nil, nil, nil, nil, nil, nil,
54
- nil, 14 ]
61
+ 17, 15, 16, 11, 2, 3, 12, 7, 14, 10,
62
+ 3, 3, 15, 2, 8, 1, nil, nil, nil, nil,
63
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
64
+ 17, 16, 11 ]
55
65
 
56
66
  racc_goto_pointer = [
57
- nil, 12, 2, -2, nil, nil, -5, nil, -6, -7,
58
- -3, -2, -22, -31, -10 ]
67
+ nil, 15, 4, -3, nil, nil, nil, -8, -2, nil,
68
+ -6, -12, -9, nil, -37, -44, -13, -16 ]
59
69
 
60
70
  racc_goto_default = [
61
- nil, nil, nil, 9, 1, 2, nil, 3, 34, nil,
62
- nil, nil, nil, nil, 38 ]
71
+ nil, nil, nil, 3, 4, 5, 6, nil, nil, 7,
72
+ 52, 42, nil, 26, nil, nil, 53, nil ]
63
73
 
64
74
  racc_reduce_table = [
65
75
  0, 0, :racc_error,
66
- 1, 19, :_reduce_none,
67
- 0, 19, :_reduce_2,
68
- 1, 20, :_reduce_none,
69
- 1, 20, :_reduce_none,
70
- 3, 21, :_reduce_5,
71
76
  1, 21, :_reduce_none,
72
- 3, 22, :_reduce_7,
73
- 3, 25, :_reduce_8,
77
+ 0, 21, :_reduce_2,
78
+ 1, 22, :_reduce_none,
79
+ 1, 22, :_reduce_none,
80
+ 1, 22, :_reduce_none,
81
+ 3, 23, :_reduce_6,
82
+ 3, 23, :_reduce_7,
74
83
  1, 23, :_reduce_none,
75
- 1, 23, :_reduce_none,
76
- 1, 24, :_reduce_none,
77
- 1, 24, :_reduce_none,
78
- 1, 24, :_reduce_none,
79
- 3, 28, :_reduce_14,
80
- 4, 28, :_reduce_15,
81
- 1, 29, :_reduce_none,
82
- 1, 30, :_reduce_none,
83
- 3, 30, :_reduce_none,
84
- 1, 31, :_reduce_none,
85
- 1, 31, :_reduce_none,
84
+ 2, 25, :_reduce_9,
85
+ 3, 24, :_reduce_10,
86
+ 3, 24, :_reduce_11,
87
+ 3, 29, :_reduce_12,
88
+ 1, 26, :_reduce_none,
89
+ 1, 26, :_reduce_none,
86
90
  1, 27, :_reduce_none,
87
- 3, 27, :_reduce_22,
88
- 1, 32, :_reduce_none,
91
+ 1, 27, :_reduce_none,
92
+ 1, 27, :_reduce_17,
93
+ 3, 31, :_reduce_18,
94
+ 4, 31, :_reduce_19,
95
+ 1, 33, :_reduce_none,
96
+ 1, 34, :_reduce_none,
97
+ 3, 34, :_reduce_22,
98
+ 1, 35, :_reduce_none,
99
+ 1, 35, :_reduce_none,
89
100
  1, 32, :_reduce_none,
90
101
  1, 32, :_reduce_none,
91
- 1, 26, :_reduce_none,
92
- 1, 26, :_reduce_none,
93
- 1, 26, :_reduce_none,
94
- 1, 26, :_reduce_none ]
102
+ 3, 32, :_reduce_27,
103
+ 3, 32, :_reduce_28,
104
+ 3, 28, :_reduce_29,
105
+ 1, 36, :_reduce_none,
106
+ 1, 36, :_reduce_none,
107
+ 1, 36, :_reduce_none,
108
+ 1, 30, :_reduce_none,
109
+ 1, 30, :_reduce_none,
110
+ 1, 30, :_reduce_none,
111
+ 1, 30, :_reduce_none,
112
+ 1, 37, :_reduce_none,
113
+ 1, 37, :_reduce_none,
114
+ 1, 37, :_reduce_none,
115
+ 1, 37, :_reduce_none,
116
+ 1, 37, :_reduce_none ]
95
117
 
96
- racc_reduce_n = 30
118
+ racc_reduce_n = 42
97
119
 
98
- racc_shift_n = 42
120
+ racc_shift_n = 58
99
121
 
100
122
  racc_token_table = {
101
123
  false => 0,
102
124
  :error => 1,
103
125
  :UMINUS => 2,
104
126
  :OPERATOR => 3,
105
- :CONJUNCTION => 4,
106
- :LPAREN => 5,
107
- :RPAREN => 6,
108
- :STANDARD_FIELD => 7,
109
- :CUSTOM_FIELD => 8,
110
- :KEYWORD => 9,
111
- :COMMA => 10,
112
- :INTEGER => 11,
113
- :DECIMAL => 12,
114
- :CHARACTER => 13,
115
- :DATE => 14,
116
- :DATETIME => 15,
117
- :BOOLEAN => 16,
118
- :NULL => 17 }
119
-
120
- racc_nt_base = 18
127
+ :RANGE_OPERATOR => 4,
128
+ :UNARY_CONJUNCTION => 5,
129
+ :CONJUNCTION => 6,
130
+ :LPAREN => 7,
131
+ :RPAREN => 8,
132
+ :STANDARD_FIELD => 9,
133
+ :CUSTOM_FIELD => 10,
134
+ :KEYWORD => 11,
135
+ :COMMA => 12,
136
+ :INTEGER => 13,
137
+ :DECIMAL => 14,
138
+ :CHARACTER => 15,
139
+ :DATE => 16,
140
+ :DATETIME => 17,
141
+ :BOOLEAN => 18,
142
+ :NULL => 19 }
143
+
144
+ racc_nt_base = 20
121
145
 
122
146
  racc_use_result_var = true
123
147
 
@@ -142,6 +166,8 @@ Racc_token_to_s_table = [
142
166
  "error",
143
167
  "UMINUS",
144
168
  "OPERATOR",
169
+ "RANGE_OPERATOR",
170
+ "UNARY_CONJUNCTION",
145
171
  "CONJUNCTION",
146
172
  "LPAREN",
147
173
  "RPAREN",
@@ -161,16 +187,19 @@ Racc_token_to_s_table = [
161
187
  "expressions",
162
188
  "expression",
163
189
  "conjunction",
190
+ "unary_conjunction",
164
191
  "field",
165
192
  "condition",
193
+ "range",
166
194
  "group",
167
195
  "literal",
168
- "literal_list",
169
196
  "function",
197
+ "literal_list",
170
198
  "function_name",
171
199
  "function_args",
172
200
  "function_arg",
173
- "literals" ]
201
+ "literals",
202
+ "rangeable" ]
174
203
 
175
204
  Racc_debug_parser = false
176
205
 
@@ -189,57 +218,69 @@ end
189
218
 
190
219
  # reduce 4 omitted
191
220
 
192
- def _reduce_5(val, _values, result)
221
+ # reduce 5 omitted
222
+
223
+ def _reduce_6(val, _values, result)
193
224
  result = tokenize_expression(val[0], val[1],val[2])
194
225
  result
195
226
  end
196
227
 
197
- # reduce 6 omitted
198
-
199
228
  def _reduce_7(val, _values, result)
229
+ result = tokenize_expression(val[0], val[1], val[2])
230
+ result
231
+ end
232
+
233
+ # reduce 8 omitted
234
+
235
+ def _reduce_9(val, _values, result)
236
+ result = tokenize_unary_conjunction(val[0], val[1])
237
+ result
238
+ end
239
+
240
+ def _reduce_10(val, _values, result)
200
241
  result = tokenize_conjunction(val[0], val[1],val[2])
201
242
  result
202
243
  end
203
244
 
204
- def _reduce_8(val, _values, result)
245
+ def _reduce_11(val, _values, result)
246
+ result = tokenize_conjunction(val[0], val[1],val[2])
247
+ result
248
+ end
249
+
250
+ def _reduce_12(val, _values, result)
205
251
  result = tokenize_group(val[1])
206
252
  result
207
253
  end
208
254
 
209
- # reduce 9 omitted
255
+ # reduce 13 omitted
210
256
 
211
- # reduce 10 omitted
257
+ # reduce 14 omitted
212
258
 
213
- # reduce 11 omitted
259
+ # reduce 15 omitted
214
260
 
215
- # reduce 12 omitted
261
+ # reduce 16 omitted
216
262
 
217
- # reduce 13 omitted
263
+ def _reduce_17(val, _values, result)
264
+ result = tokenize_list(val[0])
265
+ result
266
+ end
218
267
 
219
- def _reduce_14(val, _values, result)
268
+ def _reduce_18(val, _values, result)
220
269
  result = tokenize_function(val[0], [])
221
270
  result
222
271
  end
223
272
 
224
- def _reduce_15(val, _values, result)
273
+ def _reduce_19(val, _values, result)
225
274
  result = tokenize_function(val[0], val[2])
226
275
  result
227
276
  end
228
277
 
229
- # reduce 16 omitted
230
-
231
- # reduce 17 omitted
232
-
233
- # reduce 18 omitted
234
-
235
- # reduce 19 omitted
236
-
237
278
  # reduce 20 omitted
238
279
 
239
280
  # reduce 21 omitted
240
281
 
241
282
  def _reduce_22(val, _values, result)
242
- result = tokenize_multiple(val[0], val[2])
283
+ result = tokenize_function_args(val[0], val[2])
243
284
  result
244
285
  end
245
286
 
@@ -251,11 +292,44 @@ end
251
292
 
252
293
  # reduce 26 omitted
253
294
 
254
- # reduce 27 omitted
295
+ def _reduce_27(val, _values, result)
296
+ result = tokenize_multiple(val[0], val[2])
297
+ result
298
+ end
299
+
300
+ def _reduce_28(val, _values, result)
301
+ result = tokenize_multiple(val[0], val[2])
302
+ result
303
+ end
304
+
305
+ def _reduce_29(val, _values, result)
306
+ result = tokenize_multiple(val[0], val[2])
307
+ result
308
+ end
309
+
310
+ # reduce 30 omitted
311
+
312
+ # reduce 31 omitted
313
+
314
+ # reduce 32 omitted
315
+
316
+ # reduce 33 omitted
317
+
318
+ # reduce 34 omitted
319
+
320
+ # reduce 35 omitted
321
+
322
+ # reduce 36 omitted
323
+
324
+ # reduce 37 omitted
325
+
326
+ # reduce 38 omitted
327
+
328
+ # reduce 39 omitted
255
329
 
256
- # reduce 28 omitted
330
+ # reduce 40 omitted
257
331
 
258
- # reduce 29 omitted
332
+ # reduce 41 omitted
259
333
 
260
334
  def _reduce_none(val, _values, result)
261
335
  val[0]
data/lib/sparkql/parser.y CHANGED
@@ -3,44 +3,113 @@
3
3
  # SparkQL grammar
4
4
 
5
5
  class Sparkql::Parser
6
- prechigh
7
- nonassoc UMINUS
8
- preclow
6
+
7
+ ###############################################################################
8
+ # READ THIS!
9
+ # The grammar documentation is parsed from this file and is in a sensitive
10
+ # syntax between the START_MARKDOWN and STOP_MARKDOWN keywords. In general, all
11
+ # line comments will be treated as markdown text, and everything else is padded
12
+ # for code formatting
13
+ ###############################################################################
14
+
15
+ #START_MARKDOWN
16
+
17
+ ### SparkQL BNF Grammar
18
+ #
19
+ # This document explains the rules for the Spark API filter language syntax and
20
+ # is a living document generated from the reference implementation at
21
+ # https://github.com/sparkapi/sparkql.
22
+
23
+ #### Precedence Rules
24
+ #
25
+ # Unless otherwise specified, SparkQL follows SQL precendence conventions for
26
+ # operators and conjunctions.
27
+ #
28
+ # Unary minus is always tied to value, such as for negative numbers.
29
+ prechigh
30
+ nonassoc UMINUS
31
+ preclow
32
+
33
+
34
+ #### Grammar Rules
35
+ #
36
+ # A filter (target) is a composition of filter basic filter expressions.
9
37
  rule
10
38
  target
11
39
  : expressions
12
40
  | /* none */ { result = 0 }
13
41
  ;
14
42
 
43
+ ##### Expressions
44
+ #
45
+ # One or more expressions
15
46
  expressions
16
47
  : expression
17
48
  | conjunction
49
+ | unary_conjunction
18
50
  ;
19
-
51
+
52
+ ##### Expression
53
+ #
54
+ # The core of the filtering system, the expression requires a field, a condition
55
+ # and criteria for comparing the value of the field to the value(s) of the
56
+ # condition. The result of evaluating the expression on a resource is a true of
57
+ # false for matching the criteria.
20
58
  expression
21
59
  : field OPERATOR condition { result = tokenize_expression(val[0], val[1],val[2]) }
60
+ | field RANGE_OPERATOR range { result = tokenize_expression(val[0], val[1], val[2]) }
22
61
  | group
23
62
  ;
24
63
 
64
+ ##### Unary Conjunction
65
+ #
66
+ # Some conjunctions don't need to expression at all times (e.g. 'NOT').
67
+ unary_conjunction
68
+ : UNARY_CONJUNCTION expression { result = tokenize_unary_conjunction(val[0], val[1]) }
69
+ ;
70
+
71
+ ##### Conjunction
72
+ #
73
+ # Two expressions joined together using a supported conjunction
25
74
  conjunction
26
75
  : expressions CONJUNCTION expression { result = tokenize_conjunction(val[0], val[1],val[2]) }
76
+ | expressions UNARY_CONJUNCTION expression { result = tokenize_conjunction(val[0], val[1],val[2]) }
27
77
  ;
28
78
 
79
+ ##### Group
80
+ #
81
+ # One or more expressions encased in parenthesis. There are limitations on nesting depth at the time of this writing.
29
82
  group
30
83
  : LPAREN expressions RPAREN { result = tokenize_group(val[1]) }
31
84
  ;
32
85
 
86
+ ##### Field
87
+ #
88
+ # Keyword for searching on, these fields should be discovered using the metadata
89
+ # rules. In general, Keywords that cannot be found will be dropped from the
90
+ # filter.
33
91
  field
34
92
  : STANDARD_FIELD
35
93
  | CUSTOM_FIELD
36
94
  ;
37
95
 
96
+ ##### Condition
97
+ #
98
+ # The determinant of the filter, this is typically a value or set of values of
99
+ # a type that the field supports (review the field meta data for support).
100
+ # Functions are also supported on some field types, and provide more flexibility
101
+ # on filtering values
38
102
  condition
39
103
  : literal
40
- | literal_list
41
104
  | function
105
+ | literal_list { result = tokenize_list(val[0]) }
42
106
  ;
43
107
 
108
+ ##### Function
109
+ #
110
+ # Functions may replace static values for conditions with supported field
111
+ # types. Functions may have parameters that match types supported by
112
+ # fields.
44
113
  function
45
114
  : function_name LPAREN RPAREN { result = tokenize_function(val[0], []) }
46
115
  | function_name LPAREN function_args RPAREN { result = tokenize_function(val[0], val[2]) }
@@ -50,9 +119,12 @@ rule
50
119
  : KEYWORD
51
120
  ;
52
121
 
122
+ ##### Function Arguments
123
+ #
124
+ # Functions may optionally have a comma delimited list of parameters.
53
125
  function_args
54
126
  : function_arg
55
- | function_args COMMA function_arg
127
+ | function_args COMMA function_arg { result = tokenize_function_args(val[0], val[2]) }
56
128
  ;
57
129
 
58
130
  function_arg
@@ -60,25 +132,56 @@ rule
60
132
  | literals
61
133
  ;
62
134
 
135
+ ##### Literal List
136
+ #
137
+ # A comma delimited list of functions and values.
63
138
  literal_list
64
139
  : literals
140
+ | function
65
141
  | literal_list COMMA literals { result = tokenize_multiple(val[0], val[2]) }
142
+ | literal_list COMMA function { result = tokenize_multiple(val[0], val[2]) }
66
143
  ;
67
144
 
68
- # Literals that support multiple
145
+ ##### Range List
146
+ #
147
+ # A comma delimited list of values that support ranges for the Between operator
148
+ # (see rangeable).
149
+ range
150
+ : rangeable COMMA rangeable { result = tokenize_multiple(val[0], val[2]) }
151
+ ;
152
+
153
+ ##### Literals
154
+ #
155
+ # Literals that support multiple values in a list for a condition
69
156
  literals
70
157
  : INTEGER
71
158
  | DECIMAL
72
159
  | CHARACTER
73
160
  ;
74
161
 
75
- # Literals that support single only
162
+ ##### Literal
163
+ #
164
+ # Literals only support a single value in a condition
76
165
  literal
77
166
  : DATE
78
167
  | DATETIME
79
168
  | BOOLEAN
80
169
  | NULL
81
170
  ;
171
+
172
+ ##### Range List
173
+ #
174
+ # Functions, and literals that can be used in a range
175
+ rangeable
176
+ : INTEGER
177
+ | DECIMAL
178
+ | DATE
179
+ | DATETIME
180
+ | function
181
+ ;
182
+
183
+ #STOP_MARKDOWN
184
+
82
185
 
83
186
  end
84
187