sparkql 1.2.5 → 1.3.0
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.
- checksums.yaml +5 -13
- data/.rubocop.yml +111 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +16 -0
- data/Gemfile +1 -2
- data/Rakefile +2 -3
- data/VERSION +1 -1
- data/lib/sparkql/errors.rb +68 -71
- data/lib/sparkql/evaluator.rb +13 -9
- data/lib/sparkql/expression_resolver.rb +2 -3
- data/lib/sparkql/expression_state.rb +7 -9
- data/lib/sparkql/function_resolver.rb +777 -676
- data/lib/sparkql/geo/record_circle.rb +1 -1
- data/lib/sparkql/lexer.rb +54 -56
- data/lib/sparkql/parser.rb +35 -35
- data/lib/sparkql/parser_compatibility.rb +98 -77
- data/lib/sparkql/parser_tools.rb +159 -139
- data/lib/sparkql/token.rb +25 -25
- data/lib/sparkql/version.rb +1 -1
- data/sparkql.gemspec +20 -18
- data/test/unit/errors_test.rb +4 -5
- data/test/unit/evaluator_test.rb +15 -16
- data/test/unit/expression_state_test.rb +14 -15
- data/test/unit/function_resolver_test.rb +445 -203
- data/test/unit/geo/record_circle_test.rb +2 -2
- data/test/unit/lexer_test.rb +15 -16
- data/test/unit/parser_compatability_test.rb +177 -151
- data/test/unit/parser_test.rb +133 -99
- metadata +36 -35
data/test/unit/evaluator_test.rb
CHANGED
@@ -46,7 +46,7 @@ class EvaluatorTest < Test::Unit::TestCase
|
|
46
46
|
assert !sample(filter), "Filter: #{filter}"
|
47
47
|
end
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
# One failing Not expression in a set should always fail. Here we ensure every
|
51
51
|
# permutation of one failing
|
52
52
|
def test_nots_stay_bad
|
@@ -56,7 +56,7 @@ class EvaluatorTest < Test::Unit::TestCase
|
|
56
56
|
expressions << "Test Eq #{i == j}"
|
57
57
|
end
|
58
58
|
# Add the unary not to the front!
|
59
|
-
filter = "Not
|
59
|
+
filter = "Not #{expressions.join(' Not ')}"
|
60
60
|
assert !sample(filter), "Filter: #{filter}"
|
61
61
|
end
|
62
62
|
end
|
@@ -97,24 +97,23 @@ class EvaluatorTest < Test::Unit::TestCase
|
|
97
97
|
assert !sample("Test Eq true Not (Not Test Eq false)")
|
98
98
|
assert sample("Not (Not Test Eq true)")
|
99
99
|
assert sample("Not (Not(Not Test Eq true))")
|
100
|
-
assert !sample("Test Eq false And Test Eq true Not Test Eq false")
|
100
|
+
assert !sample("Test Eq false And Test Eq true Not Test Eq false")
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
def test_examples
|
104
104
|
# This one is based on a real life example that had problems.
|
105
105
|
#
|
106
|
-
# CurrentPrice Bt 130000.00,180000.00 And PropertySubType Eq 'Single Family Residence' And
|
107
|
-
# SchoolDistrict Eq 'Byron Center','Grandville','Jenison' And MlsStatus Eq 'Active' And
|
108
|
-
# BathsTotal Bt 1.50,9999.00 And BedsTotal Bt 3,99 And PropertyType Eq 'A'
|
109
|
-
# Not "Garage"."Garage2" Eq 'No' And "Pool"."OutdoorAbove" Eq true
|
106
|
+
# CurrentPrice Bt 130000.00,180000.00 And PropertySubType Eq 'Single Family Residence' And
|
107
|
+
# SchoolDistrict Eq 'Byron Center','Grandville','Jenison' And MlsStatus Eq 'Active' And
|
108
|
+
# BathsTotal Bt 1.50,9999.00 And BedsTotal Bt 3,99 And PropertyType Eq 'A'
|
109
|
+
# Not "Garage"."Garage2" Eq 'No' And "Pool"."OutdoorAbove" Eq true
|
110
110
|
# And "Pool"."OutdoorInground" Eq true Not "Substructure"."Michigan Basement" Eq true
|
111
111
|
|
112
|
-
assert !sample("Test Eq false And Test Eq true And "
|
113
|
-
"Test Eq false And Test Eq true And "
|
114
|
-
"Test Eq true And Test Eq true And Test Eq true "
|
115
|
-
"Not Test Eq false And Test Eq false "
|
116
|
-
"And Test Eq false Not Test Eq false"
|
117
|
-
)
|
112
|
+
assert !sample("Test Eq false And Test Eq true And " \
|
113
|
+
"Test Eq false And Test Eq true And " \
|
114
|
+
"Test Eq true And Test Eq true And Test Eq true " \
|
115
|
+
"Not Test Eq false And Test Eq false " \
|
116
|
+
"And Test Eq false Not Test Eq false")
|
118
117
|
end
|
119
118
|
|
120
119
|
def test_optimizations
|
@@ -133,10 +132,10 @@ class EvaluatorTest < Test::Unit::TestCase
|
|
133
132
|
assert !sample("MlsStatus Eq false And PropertyType Eq true And (City Eq true Or City Eq false)")
|
134
133
|
end
|
135
134
|
|
136
|
-
def sample
|
135
|
+
def sample(filter)
|
137
136
|
@parser = Parser.new
|
138
137
|
@expressions = @parser.parse(filter)
|
139
|
-
@evaluator = Evaluator.new(BooleanOrBustExpressionResolver.new
|
138
|
+
@evaluator = Evaluator.new(BooleanOrBustExpressionResolver.new)
|
140
139
|
@evaluator.evaluate(@expressions)
|
141
140
|
end
|
142
141
|
end
|
@@ -7,17 +7,17 @@ class ExpressionStateTest < Test::Unit::TestCase
|
|
7
7
|
@subject = ExpressionState.new
|
8
8
|
@parser = Parser.new
|
9
9
|
end
|
10
|
-
|
10
|
+
|
11
11
|
def test_needs_join
|
12
12
|
filter = '"General Property Description"."Taxes" Lt 500.0'
|
13
13
|
process(filter)
|
14
14
|
assert @subject.needs_join?
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
def test_or
|
18
18
|
filter = '"General Property Description"."Taxes" Lt 500.0 Or "General Property Description"."Taxes" Gt 400.0'
|
19
19
|
process(filter)
|
20
|
-
assert !@subject.needs_join?, "#{@subject.inspect} Expressions:#{
|
20
|
+
assert !@subject.needs_join?, "#{@subject.inspect} Expressions:#{@expressions.inspect}"
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_not
|
@@ -33,31 +33,31 @@ class ExpressionStateTest < Test::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_and_or
|
36
|
-
filter = '"General Property Description"."Taxes" Lt 500.0 And "General Property Description"."Taxes2" '
|
37
|
-
|
36
|
+
filter = '"General Property Description"."Taxes" Lt 500.0 And "General Property Description"."Taxes2" ' \
|
37
|
+
'Eq 1.0 Or "General Property Description"."Taxes" Gt 400.0'
|
38
38
|
process(filter)
|
39
39
|
assert !@subject.needs_join?
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_or_and
|
43
|
-
filter = '"General Property Description"."Taxes" Lt 500.0 Or "General Property Description"."Taxes" '
|
44
|
-
|
43
|
+
filter = '"General Property Description"."Taxes" Lt 500.0 Or "General Property Description"."Taxes" ' \
|
44
|
+
'Gt 400.0 And "General Property Description"."Taxes2" Eq 1.0'
|
45
45
|
process(filter)
|
46
46
|
assert @subject.needs_join?
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def test_or_with_standard_field
|
50
50
|
filter = 'Test Eq 0.0 Or "General Property Description"."Taxes" Lt 500.0'
|
51
51
|
process(filter)
|
52
52
|
assert @subject.needs_join?
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
# Nesting
|
56
56
|
def test_nested_or
|
57
57
|
parse '"General Property Description"."Taxes" Lt 5.0 Or ("General Property Description"."Taxes" Gt 4.0)'
|
58
58
|
@expressions.each do |ex|
|
59
59
|
@subject.push(ex)
|
60
|
-
assert @subject.needs_join?, "#{@subject.inspect} Expression:#{
|
60
|
+
assert @subject.needs_join?, "#{@subject.inspect} Expression:#{ex.inspect}"
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
@@ -70,20 +70,20 @@ class ExpressionStateTest < Test::Unit::TestCase
|
|
70
70
|
@subject.push(@expressions[2])
|
71
71
|
assert !@subject.needs_join?
|
72
72
|
end
|
73
|
-
|
73
|
+
|
74
74
|
# Nesting
|
75
75
|
def test_nested_and
|
76
76
|
parse '"Tax"."Taxes" Lt 5.0 Or ("Tax"."Taxes" Gt 4.0 And "Tax"."Taxes" Gt 2.0)'
|
77
77
|
@expressions.each do |ex|
|
78
78
|
@subject.push(ex)
|
79
|
-
assert @subject.needs_join?, "#{@subject.inspect} Expression:#{
|
79
|
+
assert @subject.needs_join?, "#{@subject.inspect} Expression:#{ex.inspect}"
|
80
80
|
end
|
81
81
|
end
|
82
|
-
|
82
|
+
|
83
83
|
def parse(filter)
|
84
84
|
@expressions = @parser.parse(filter)
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
def process(filter)
|
88
88
|
@expressions = @parser.parse(filter)
|
89
89
|
@expressions.each do |ex|
|
@@ -91,5 +91,4 @@ class ExpressionStateTest < Test::Unit::TestCase
|
|
91
91
|
end
|
92
92
|
@expressions
|
93
93
|
end
|
94
|
-
|
95
94
|
end
|