~zorba-coders/zorba/trunk

« back to all changes in this revision

Viewing changes to test/rbkt/Queries/zorba/caching/key-match-ext-sd-01.xq

  • Committer: Zorba Jenkins
  • Author(s): Federico Cavalieri
  • Date: 2014-04-29 20:37:35 UTC
  • mfrom: (11714.2.7 feature-caching-annotations)
  • Revision ID: jenkins@lambda.nu-20140429203735-mgu2acarnn71p66l
Greatly improved function caching.

* Changed function annotations:
  - %an:deterministic: disables caching (previously %an:no-cache)
  - %an:strictlydeterministic: enables caching for deterministic and non-deterministic functions. Cache is only within the same snapshot.
  - %an:cache enables caching  for deterministic, non-deterministic and sequential functions. Caches is across snapshots. (unchanged)
  - %an:exclude-from-cache-key(n) specifies that a function argument has to be ignored when computing the cache key
  - %an:compare-with-deep-equal(n) specifies that a function argument has to be compared with deep-equal semantics
  
* Changed criteria for default annotations of internal and external functions:
  - Functions which have no %an:deterministic, %an:nondeterministic or %an:strictlydeterministic annotations and all their parameter and the return types are atomics are now automatically annotated %an:strictlydeterministic
  - All the other functions are annotated %an:deterministic
* Added snapshot id in global dynamic context
* Added dynamic context xquery module
* Added strict equality hashmap
* Reimplemented %an:cache
* Enabled caching for function that have non atomic arguments
* Whenever the eager evaluation of a function arguments raises an error, the evaluation is retried without cache. The function cache is then disabled if it was automatically detected.
Approved: Matthias Brantner, Federico Cavalieri

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import module namespace debug = "http://zorba.io/modules/util-tests";
 
2
 
 
3
declare function local:is-cached($uuids, $old-uuids)
 
4
{
 
5
  if ($uuids = $old-uuids)
 
6
  then "CACHED"
 
7
  else "NOT CACHED"
 
8
};
 
9
 
 
10
 
 
11
variable $node := <a/>;
 
12
variable $object := {"a" : 1};
 
13
variable $array := [1];
 
14
variable $array-2 := [2];
 
15
 
 
16
let $old :=
 
17
 
18
  debug:test-02-sd(()),
 
19
  debug:test-02-sd(xs:int(1)),
 
20
  debug:test-02-sd(xs:integer(1)),
 
21
  debug:test-02-sd($node),
 
22
  debug:test-02-sd($object),
 
23
  debug:test-02-sd($array),
 
24
  debug:test-02-sd($node),
 
25
  debug:test-02-sd($object),
 
26
  debug:test-02-sd($array),
 
27
  debug:test-02-sd($array-2)
 
28
)
 
29
let $old-values := (for $i in (1 to 10) return $old[$i * 2 - 1])
 
30
let $old-uuids := (for $i in (1 to 10) return $old[$i * 2]) 
 
31
let $equal := 
 
32
(
 
33
  debug:test-02-sd(()),
 
34
  debug:test-02-sd(xs:integer(1)),
 
35
  debug:test-02-sd($node),
 
36
  debug:test-02-sd($object),
 
37
  debug:test-02-sd($array),
 
38
  debug:test-02-sd($array-2)
 
39
)
 
40
let $expected-old-values := (for $i in (1 to 6) return $equal[$i * 2 -1])
 
41
let $expected-old-uuids := (for $i in (1 to 6) return $equal[$i * 2])
 
42
let $re-evaluated := 
 
43
(
 
44
  debug:test-02-sd(xs:long(1)),
 
45
  debug:test-02-sd(<a/>),
 
46
  debug:test-02-sd({"a" : 1}),
 
47
  debug:test-02-sd([1]),
 
48
  debug:test-02-sd([2])
 
49
)
 
50
let $expected-new-values := (for $i in (1 to 5) return $re-evaluated[$i * 2 - 1])
 
51
let $expected-new-uuids := (for $i in (1 to 5) return $re-evaluated[$i * 2])
 
52
return
 
53
(
 
54
  for $i in (1 to 10)
 
55
  return "Called with " || $old-values[$i] || ": NOT CACHED" || "&#10;",
 
56
  for $j in (1 to 6)
 
57
  return "Called with " || $expected-old-values[$j] || ": " || local:is-cached($expected-old-uuids[$j], $old-uuids) || "&#10;",
 
58
  for $k in (1 to 5)
 
59
  return "Called with " || $expected-new-values[$k] || ": " || local:is-cached($expected-new-uuids[$k], $old-uuids) || "&#10;" 
 
60
)
 
 
b'\\ No newline at end of file'