sparkql 1.1.12 → 1.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +4 -0
- data/VERSION +1 -1
- data/lib/sparkql/function_resolver.rb +45 -1
- data/test/unit/function_resolver_test.rb +40 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTJhM2I5YjU5YTg1NTVhNDgyOTJjYzE5YjI4YjlkZjkzZmI3NjFmYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjAyMjAwN2VhYTNmN2Q1NjhkNGZmN2FhNGY5OTgwMjdhNDY3ZWFjMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWY5MmVmNDhmMGM0OTgzNmE2NjE4OWM5NmQ4M2QxOTJiMGFiOGQ4MDlkMmJj
|
10
|
+
NDBhNTVkZDgyMGJmYmU1Y2YwOTdiOTNmN2ZkYTcxOWM1MWNkNjJmZmJiMmI3
|
11
|
+
ODhmOGIzNWFiYTEwYTQzMThiNGNkNThlNDc0OGQzYTNmMjA4NWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzI5MWY5NDRkN2ViNGFhMzUzOTQwMWZmZTQ3ZmUwZjE3ZGY5NDJjM2UxMjYy
|
14
|
+
ZTdiMjY0NDA1OWJiNDVlM2YyM2I0NzdiOWVlN2E3M2M2YjFmNDc4NjQ4ZmJh
|
15
|
+
ZWNlYTE0ODE4ZmQ0ZGQyZjUxNTk5YTM2YWIxYTg2Y2YzMGY4Nzg=
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.13
|
@@ -14,6 +14,8 @@ class Sparkql::FunctionResolver
|
|
14
14
|
STRFTIME_DATE_FORMAT = '%Y-%m-%d'
|
15
15
|
STRFTIME_TIME_FORMAT = '%H:%M:%S.%N'
|
16
16
|
VALID_REGEX_FLAGS = ["", "i"]
|
17
|
+
MIN_DATE_TIME = Time.new(1, 1, 1, 0, 0, 0, "+00:00").iso8601
|
18
|
+
MAX_DATE_TIME = Time.new(9999, 12, 31, 23, 59, 59, "+00:00").iso8601
|
17
19
|
SUPPORTED_FUNCTIONS = {
|
18
20
|
:polygon => {
|
19
21
|
:args => [:character],
|
@@ -45,6 +47,11 @@ class Sparkql::FunctionResolver
|
|
45
47
|
:resolve_for_type => true,
|
46
48
|
:return_type => :character
|
47
49
|
},
|
50
|
+
:length => {
|
51
|
+
:args => [[:field, :character]],
|
52
|
+
:resolve_for_type => true,
|
53
|
+
:return_type => :integer
|
54
|
+
},
|
48
55
|
:indexof => {
|
49
56
|
:args => [[:field, :character], :character],
|
50
57
|
:return_type => :integer
|
@@ -77,7 +84,15 @@ class Sparkql::FunctionResolver
|
|
77
84
|
:args => [:integer],
|
78
85
|
:return_type => :datetime
|
79
86
|
},
|
80
|
-
:now => {
|
87
|
+
:now => {
|
88
|
+
:args => [],
|
89
|
+
:return_type => :datetime
|
90
|
+
},
|
91
|
+
:maxdatetime => {
|
92
|
+
:args => [],
|
93
|
+
:return_type => :datetime
|
94
|
+
},
|
95
|
+
:mindatetime => {
|
81
96
|
:args => [],
|
82
97
|
:return_type => :datetime
|
83
98
|
},
|
@@ -278,6 +293,21 @@ class Sparkql::FunctionResolver
|
|
278
293
|
}
|
279
294
|
end
|
280
295
|
|
296
|
+
def length_character(string)
|
297
|
+
{
|
298
|
+
:type => :integer,
|
299
|
+
:value => "#{string.size}"
|
300
|
+
}
|
301
|
+
end
|
302
|
+
|
303
|
+
def length_field(arg)
|
304
|
+
{
|
305
|
+
:type => :function,
|
306
|
+
:value => "length",
|
307
|
+
:args => [arg]
|
308
|
+
}
|
309
|
+
end
|
310
|
+
|
281
311
|
def startswith(string)
|
282
312
|
# Wrap this string in quotes, as we effectively translate
|
283
313
|
# City Eq startswith('far')
|
@@ -354,6 +384,20 @@ class Sparkql::FunctionResolver
|
|
354
384
|
}
|
355
385
|
end
|
356
386
|
|
387
|
+
def maxdatetime()
|
388
|
+
{
|
389
|
+
:type => :datetime,
|
390
|
+
:value => MAX_DATE_TIME
|
391
|
+
}
|
392
|
+
end
|
393
|
+
|
394
|
+
def mindatetime()
|
395
|
+
{
|
396
|
+
:type => :datetime,
|
397
|
+
:value => MIN_DATE_TIME
|
398
|
+
}
|
399
|
+
end
|
400
|
+
|
357
401
|
def indexof(arg1, arg2)
|
358
402
|
{
|
359
403
|
:type => :function,
|
@@ -52,6 +52,25 @@ class FunctionResolverTest < Test::Unit::TestCase
|
|
52
52
|
assert_equal "'STRING'", value[:value]
|
53
53
|
end
|
54
54
|
|
55
|
+
test "length(SomeField)" do
|
56
|
+
f = FunctionResolver.new('length', [{:type => :field, :value => "City"}])
|
57
|
+
f.validate
|
58
|
+
assert !f.errors?, "Errors #{f.errors.inspect}"
|
59
|
+
value = f.call
|
60
|
+
assert_equal :function, value[:type]
|
61
|
+
assert_equal 'length', value[:value]
|
62
|
+
assert_equal "City", value[:args].first
|
63
|
+
end
|
64
|
+
|
65
|
+
test "length('string')" do
|
66
|
+
f = FunctionResolver.new('length', [{:type => :character, :value => "string"}])
|
67
|
+
f.validate
|
68
|
+
assert !f.errors?, "Errors #{f.errors.inspect}"
|
69
|
+
value = f.call
|
70
|
+
assert_equal :integer, value[:type]
|
71
|
+
assert_equal '6', value[:value]
|
72
|
+
end
|
73
|
+
|
55
74
|
test "now()" do
|
56
75
|
start = Time.now
|
57
76
|
f = FunctionResolver.new('now', [])
|
@@ -62,7 +81,27 @@ class FunctionResolverTest < Test::Unit::TestCase
|
|
62
81
|
test_time = Time.parse(value[:value])
|
63
82
|
assert (-5 < test_time - start && 5 > test_time - start), "Time range off by more than five seconds #{test_time - start} '#{test_time} - #{start}'"
|
64
83
|
end
|
65
|
-
|
84
|
+
|
85
|
+
test "mindatetime()" do
|
86
|
+
f = FunctionResolver.new('mindatetime', [])
|
87
|
+
f.validate
|
88
|
+
assert !f.errors?, "Errors #{f.errors.inspect}"
|
89
|
+
value = f.call
|
90
|
+
assert_equal :datetime, value[:type]
|
91
|
+
|
92
|
+
assert_equal '0001-01-01T00:00:00+00:00', value[:value]
|
93
|
+
end
|
94
|
+
|
95
|
+
test "maxdatetime()" do
|
96
|
+
f = FunctionResolver.new('maxdatetime', [])
|
97
|
+
f.validate
|
98
|
+
assert !f.errors?, "Errors #{f.errors.inspect}"
|
99
|
+
value = f.call
|
100
|
+
assert_equal :datetime, value[:type]
|
101
|
+
|
102
|
+
assert_equal '9999-12-31T23:59:59+00:00', value[:value]
|
103
|
+
end
|
104
|
+
|
66
105
|
test "days()" do
|
67
106
|
d = Date.new(2012,10,20)
|
68
107
|
Date.expects(:today).returns(d)
|