You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by bu...@apache.org on 2015/10/31 00:16:32 UTC

[24/51] [partial] incubator-asterixdb git commit: SQL++ parser: 1. refactored asterix-aql to become asterix-lang-common and asterix-lang-aql, where the former is the common part for different languages; 2. added asterix-lang-sqlpp on top of asterix-lang-

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query_issue849.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query_issue849.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query_issue849.sqlpp
new file mode 100644
index 0000000..a843dad
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/query_issue849.sqlpp
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue827
+ * https://code.google.com/p/asterixdb/issues/detail?id=849
+ * Expected Res : SUCCESS
+ * Date         : 2nd Feb. 2015
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.sType as
+ closed {
+  b : int32
+}
+
+create  table s(sType) primary key b;
+
+insert into s
+select element {'b':1};
+insert into s
+select element {'b':3};
+select element {'x':x,'y':y}
+from  {{{'a':1},{'a':2}}} as x,
+      (
+    select element z.b
+    from  s as z
+    where (x.a = z.b)
+) as y
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric-desc.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric-desc.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric-desc.sqlpp
new file mode 100644
index 0000000..8cdc933
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric-desc.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ *  Description     : The hint is to use the range connector
+ *                  : This test is intended to verify that the range connector is used instead of single node merge.
+ *  Expected Result : Success
+ *  Date            : 1th May 2015
+ */
+
+drop  database TinySocial if exists;
+create  database TinySocial;
+
+use TinySocial;
+
+
+create type TinySocial.TwitterUserType as
+{
+  "screen-name" : string,
+  lang : string,
+  friends_count : int64,
+  statuses_count : int64,
+  name : string,
+  followers_count : int64
+}
+
+create  table TwitterUsers(TwitterUserType) primary key "screen-name";
+
+select element user
+from  TwitterUsers as user
+order by user.friends_count desc
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric.sqlpp
new file mode 100644
index 0000000..682d26b
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-numeric.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ *  Description     : The hint is to use the range connector
+ *                  : This test is intended to verify that the range connector is used instead of single node merge.
+ *  Expected Result : Success
+ *  Date            : 1th May 2015
+ */
+
+drop  database TinySocial if exists;
+create  database TinySocial;
+
+use TinySocial;
+
+
+create type TinySocial.TwitterUserType as
+{
+  "screen-name" : string,
+  lang : string,
+  friends_count : int64,
+  statuses_count : int64,
+  name : string,
+  followers_count : int64
+}
+
+create  table TwitterUsers(TwitterUserType) primary key "screen-name";
+
+select element user
+from  TwitterUsers as user
+order by user.friends_count
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string-desc.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string-desc.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string-desc.sqlpp
new file mode 100644
index 0000000..cd1c196
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string-desc.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ *  Description     : The hint is to use the range connector
+ *                  : This test is intended to verify that the range connector is used instead of single node merge.
+ *  Expected Result : Success
+ *  Date            : 1th May 2015
+ */
+
+drop  database TinySocial if exists;
+create  database TinySocial;
+
+use TinySocial;
+
+
+create type TinySocial.TwitterUserType as
+{
+  "screen-name" : string,
+  lang : string,
+  friends_count : int64,
+  statuses_count : int64,
+  name : string,
+  followers_count : int64
+}
+
+create  table TwitterUsers(TwitterUserType) primary key "screen-name";
+
+select element user
+from  TwitterUsers as user
+order by user."screen-name" desc
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string.sqlpp
new file mode 100644
index 0000000..a400bd3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/range-connector/sort-hint-on-closed-string.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ *  Description     : The hint is to use the range connector
+ *                  : This test is intended to verify that the range connector is used instead of single node merge.
+ *  Expected Result : Success
+ *  Date            : 1th May 2015
+ */
+
+drop  database TinySocial if exists;
+create  database TinySocial;
+
+use TinySocial;
+
+
+create type TinySocial.TwitterUserType as
+{
+  "screen-name" : string,
+  lang : string,
+  friends_count : int64,
+  statuses_count : int64,
+  name : string,
+  followers_count : int64
+}
+
+create  table TwitterUsers(TwitterUserType) primary key "screen-name";
+
+select element user
+from  TwitterUsers as user
+order by user."screen-name"
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/record_access.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/record_access.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/record_access.sqlpp
new file mode 100644
index 0000000..84602a2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/record_access.sqlpp
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+write output to nc1:"/tmp/rec_access.adm"
+{'a':2}.a;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/issue730.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/issue730.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/issue730.sqlpp
new file mode 100644
index 0000000..a9a137d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/issue730.sqlpp
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description  : Test that left-outer-join may use an available rtree index in index subtree.
+ * Issue        : 730              
+ * Expected Res : Success
+ * Date         : 8th May 2014
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+{
+  screen_name : string,
+  lang : string,
+  friends_count : int32,
+  statuses_count : int32,
+  name : string,
+  followers_count : int32
+}
+
+create type test.TweetMessageType as
+{
+  tweetid : int64,
+  user : TwitterUserType,
+  sender_location : point?,
+  send_time : datetime,
+  referred_topics : {{string}},
+  message_text : string
+}
+
+create  table TweetMessages(TweetMessageType) primary key tweetid;
+
+create  index twmSndLocIx  on TweetMessages (sender_location) type rtree;
+
+write output to nc1:"rttest/rtree-index-join_issue730.adm"
+select element {'message':t1.tweetid,'nearby-message':(
+        select element t2.tweetid
+        from  TweetMessages as t2
+        where test."spatial-intersect"(t2.sender_location,n)
+    )}
+from  TweetMessages as t1
+with  n as test."create-circle"(t1.sender_location,5.0)
+where ((t1.send_time >= test.datetime('2011-06-18T14:10:17')) and (t1.send_time < test.datetime('2011-06-18T15:10:17')))
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp
new file mode 100644
index 0000000..f936fea
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_01.sqlpp
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description  : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue        : 730, 741                 
+ * Expected Res : Success
+ * Date         : 8th May 2014
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+  "screen-name" : string,
+  lang : string,
+  "friends-count" : int32,
+  "statuses-count" : int32,
+  name : string,
+  "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+  tweetid : int64,
+  user : TwitterUserType,
+  "sender-location" : point,
+  "send-time" : datetime,
+  "referred-topics" : {{string}},
+  "message-text" : string,
+  countA : int32,
+  countB : int32
+}
+
+create  table TweetMessages(TweetMessageType) primary key tweetid;
+
+create  index twmSndLocIx  on TweetMessages ("sender-location") type rtree;
+
+create  index msgCountAIx  on TweetMessages (countA) type btree;
+
+create  index msgCountBIx  on TweetMessages (countB) type btree;
+
+create  index msgTextIx  on TweetMessages ("message-text") type keyword;
+
+write output to nc1:"rttest/rtree-index-join_leftouterjoin-probe-pidx-with-join-rtree-sidx_01.adm"
+select element {'tweetid1':t1.tweetid,'loc1':t1."sender-location",'nearby-message':(
+        select element {'tweetid2':t2.tweetid,'loc2':t2."sender-location"}
+        from  TweetMessages as t2
+        where test."spatial-intersect"(t2."sender-location",n)
+        order by t2.tweetid
+    )}
+from  TweetMessages as t1
+with  n as test."create-circle"(t1."sender-location",0.5)
+where (t1.tweetid < test.int64('10'))
+order by t1.tweetid
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp
new file mode 100644
index 0000000..160816f
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/leftouterjoin-probe-pidx-with-join-rtree-sidx_02.sqlpp
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description  : Test that left-outer-join may use two available indexes, one for primary index in prob subtree and another for secondary rtree index in index subtree.
+ * Issue        : 730, 741                 
+ * Expected Res : Success
+ * Date         : 8th May 2014
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.TwitterUserType as
+ closed {
+  "screen-name" : string,
+  lang : string,
+  "friends-count" : int32,
+  "statuses-count" : int32,
+  name : string,
+  "followers-count" : int32
+}
+
+create type test.TweetMessageType as
+ closed {
+  tweetid : int64,
+  user : TwitterUserType,
+  "sender-location" : point,
+  "send-time" : datetime,
+  "referred-topics" : {{string}},
+  "message-text" : string,
+  countA : int32,
+  countB : int32
+}
+
+create  table TweetMessages(TweetMessageType) primary key tweetid;
+
+create  index twmSndLocIx  on TweetMessages ("sender-location") type rtree;
+
+create  index msgCountAIx  on TweetMessages (countA) type btree;
+
+create  index msgCountBIx  on TweetMessages (countB) type btree;
+
+create  index msgTextIx  on TweetMessages ("message-text") type keyword;
+
+write output to nc1:"rttest/rtree-index-join_leftouterjoin-probe-pidx-with-join-rtree-sidx_02.adm"
+select element {'tweetid1':t1.tweetid,'loc1':t1."sender-location",'nearby-message':(
+        select element {'tweetid2':t2.tweetid,'loc2':t2."sender-location"}
+        from  TweetMessages as t2
+        where (test."spatial-intersect"(t2."sender-location",n) and (t1.tweetid != t2.tweetid))
+        order by t2.tweetid
+    )}
+from  TweetMessages as t1
+with  n as test."create-circle"(t1."sender-location",0.5)
+where (t1.tweetid < test.int64('10'))
+order by t1.tweetid
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/query-issue838.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/query-issue838.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/query-issue838.sqlpp
new file mode 100644
index 0000000..3a2364d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/query-issue838.sqlpp
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description  : This test case is to verify the fix for issue838
+ * https://code.google.com/p/asterixdb/issues/detail?id=838
+ * Expected Res : SUCCESS
+ * Date         : 18 Dec. 2014
+ */
+
+drop  database twitter if exists;
+create  database twitter;
+
+use twitter;
+
+
+create type twitter.TweetMessageType as
+ closed {
+  tweetid : int64,
+  "sender-location" : point,
+  text : string
+}
+
+create type twitter.TweetHistorySubscription as
+{
+  "subscription-id" : int32,
+  location : point
+}
+
+create  table TweetHistorySubscriptions(TweetHistorySubscription) primary key "subscription-id";
+
+create  index testa  on TweetHistorySubscriptions (location) type rtree;
+
+create  table TweetMessages(TweetMessageType) primary key tweetid;
+
+create  index locationIdx  on TweetMessages ("sender-location") type rtree;
+
+write output to nc1:"rttest/query-issue838.adm"
+select element {'subscription-id':sub."subscription-id",'changeSet':1,'execution-time':twitter."current-datetime"(),'message-text':text}
+from  TweetHistorySubscriptions as sub,
+      (
+    select element tweet
+    from  TweetMessages as tweet
+    with  circle as twitter."create-circle"(location,30.0)
+    where twitter."spatial-intersect"(tweet."sender-location",circle)
+) as text
+with  location as sub.location
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_01.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_01.sqlpp
new file mode 100644
index 0000000..9319186
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_01.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Joins two datasets on the intersection of their point attributes.
+ *                  The dataset 'MyData1' has an RTree index, and we expect the 
+ *                  join to be transformed into an indexed nested-loop join.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+  id : int32,
+  point : point,
+  kwds : string,
+  line1 : line,
+  line2 : line,
+  poly1 : polygon,
+  poly2 : polygon,
+  rec : rectangle
+}
+
+create  table MyData1(MyRecord) primary key id;
+
+create  table MyData2(MyRecord) primary key id;
+
+create  index rtree_index  on MyData1 (point) type rtree;
+
+write output to nc1:"rttest/index-join_rtree-spatial-intersect-point.adm"
+select element {'a':a,'b':b}
+from  MyData1 as a,
+      MyData2 as b
+where test."spatial-intersect"(a.point,b.point)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_02.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_02.sqlpp
new file mode 100644
index 0000000..94d47b6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_02.sqlpp
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Joins two datasets on the intersection of their point attributes.
+ *                  The dataset 'MyData2' has an RTree index, and we expect the 
+ *                  join to be transformed into an indexed nested-loop join.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+  id : int32,
+  point : point,
+  kwds : string,
+  line1 : line,
+  line2 : line,
+  poly1 : polygon,
+  poly2 : polygon,
+  rec : rectangle
+}
+
+create  table MyData1(MyRecord) primary key id;
+
+create  table MyData2(MyRecord) primary key id;
+
+create  index rtree_index  on MyData2 (point) type rtree;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_02.adm"
+select element {'a':a,'b':b}
+from  MyData1 as a,
+      MyData2 as b
+where test."spatial-intersect"(a.point,b.point)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_03.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_03.sqlpp
new file mode 100644
index 0000000..b57ad65
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-index-join/spatial-intersect-point_03.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Self-joins a dataset on the intersection of its point attribute.
+ *                  The dataset has an RTree index, and we expect the 
+ *                  join to be transformed into an indexed nested-loop join.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+  id : int32,
+  point : point,
+  kwds : string,
+  line1 : line,
+  line2 : line,
+  poly1 : polygon,
+  poly2 : polygon,
+  rec : rectangle
+}
+
+create  table MyData(MyRecord) primary key id;
+
+create  index rtree_index  on MyData (point) type rtree;
+
+write output to nc1:"rttest/rtree-index-join_spatial-intersect-point_03.adm"
+select element {'a':a,'b':b}
+from  MyData as a,
+      MyData as b
+where test."spatial-intersect"(a.point,b.point)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index-open.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index-open.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index-open.sqlpp
new file mode 100644
index 0000000..c7b5d36
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index-open.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.MyRecord as
+{
+  id : int32,
+  point : point,
+  kwds : string,
+  line1 : line,
+  line2 : line,
+  poly1 : polygon,
+  poly2 : polygon,
+  rec : rectangle,
+  circle : circle
+}
+
+create  nodegroup group1 if not exists  on 
+    nc1,
+    nc2
+;
+create  table MyData(MyRecord) primary key id on group1;
+
+load  table MyData using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/spatial/spatialData.json"),("format"="adm")) pre-sorted;
+
+create  index rtree_index_point  on MyData (point) type rtree;
+
+write output to nc1:"rttest/index_rtree-secondary-index-open.adm"
+select element {'id':o.id}
+from  MyData as o
+where test."spatial-intersect"(o.point,test."create-polygon"([4.0,1.0,4.0,4.0,12.0,4.0,12.0,1.0]))
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index.sqlpp
new file mode 100644
index 0000000..0fae89e
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/rtree-secondary-index.sqlpp
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+  id : int32,
+  point : point,
+  kwds : string,
+  line1 : line,
+  line2 : line,
+  poly1 : polygon,
+  poly2 : polygon,
+  rec : rectangle,
+  circle : circle
+}
+
+create  nodegroup group1 if not exists  on 
+    nc1,
+    nc2
+;
+create  table MyData(MyRecord) primary key id on group1;
+
+load  table MyData using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/spatial/spatialData.json"),("format"="adm")) pre-sorted;
+
+create  index rtree_index_point  on MyData (point) type rtree;
+
+write output to nc1:"rttest/index_rtree-secondary-index.adm"
+select element {'id':o.id}
+from  MyData as o
+where test."spatial-intersect"(o.point,test."create-polygon"([4.0,1.0,4.0,4.0,12.0,4.0,12.0,1.0]))
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-all.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-all.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-all.sqlpp
new file mode 100644
index 0000000..1a277ce
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-all.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : double,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.LineIDType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32
+}
+
+create  nodegroup group1 if not exists  on 
+    nc1,
+    nc2
+;
+create  table LineItems_q1(LineItemType) primary key l_orderkey on group1;
+
+create  table LineID(LineIDType) primary key l_orderkey on group1;
+
+delete l from LineItems_q1
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-rtree-secondary-index.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-rtree-secondary-index.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-rtree-secondary-index.sqlpp
new file mode 100644
index 0000000..6266272
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete-rtree-secondary-index.sqlpp
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.MyRecord as
+ closed {
+  id : int32,
+  point : point,
+  kwds : string,
+  line1 : line,
+  line2 : line,
+  poly1 : polygon,
+  poly2 : polygon,
+  rec : rectangle,
+  circle : circle
+}
+
+create  nodegroup group1 if not exists  on 
+    nc1,
+    nc2
+;
+create  table MyData(MyRecord) primary key id on group1;
+
+load  table MyData using "org.apache.asterix.external.dataset.adapter.NCFileSystemAdapter" (("path"="nc1://data/spatial/spatialData.json"),("format"="adm")) pre-sorted;
+
+create  index rtree_index_point  on MyData (point) type rtree;
+
+delete m from MyData
+ where (m.id > 5);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete.sqlpp
new file mode 100644
index 0000000..0185c84
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-delete.sqlpp
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : double,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.LineIDType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32
+}
+
+create  nodegroup group1 if not exists  on 
+    nc1,
+    nc2
+;
+create  table LineItems_q1(LineItemType) primary key l_orderkey on group1;
+
+create  table LineID(LineIDType) primary key l_orderkey on group1;
+
+delete l from LineItems_q1
+ where (l.l_shipdate <= '1998-09-02');

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert-secondary-index.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert-secondary-index.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert-secondary-index.sqlpp
new file mode 100644
index 0000000..020baf7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert-secondary-index.sqlpp
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : double,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.LineIDType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32
+}
+
+create  nodegroup group1 if not exists  on 
+    nc1,
+    nc2
+;
+create  table LineItems_q1(LineItemType) primary key l_orderkey on group1;
+
+create  table LineID(LineIDType) primary key l_orderkey on group1;
+
+create  index idx_LineID_partkey  on LineID (l_partkey) type btree;
+
+create  index idx_LineID_suppkey  on LineID (l_suppkey) type btree;
+
+insert into LineID
+select element {'l_orderkey':l.l_orderkey,'l_partkey':l.l_partkey,'l_suppkey':l.l_partkey}
+from  LineItems_q1 as l
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert.sqlpp
new file mode 100644
index 0000000..2de1b31
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/scan-insert.sqlpp
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+drop  database tpch if exists;
+create  database tpch;
+
+use tpch;
+
+
+create type tpch.LineItemType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32,
+  l_linenumber : int32,
+  l_quantity : double,
+  l_extendedprice : double,
+  l_discount : double,
+  l_tax : double,
+  l_returnflag : string,
+  l_linestatus : string,
+  l_shipdate : string,
+  l_commitdate : string,
+  l_receiptdate : string,
+  l_shipinstruct : string,
+  l_shipmode : string,
+  l_comment : string
+}
+
+create type tpch.LineIDType as
+ closed {
+  l_orderkey : int32,
+  l_partkey : int32,
+  l_suppkey : int32
+}
+
+create  nodegroup group1 if not exists  on 
+    nc1,
+    nc2
+;
+create  table LineItems_q1(LineItemType) primary key l_orderkey on group1;
+
+create  table LineID(LineIDType) primary key l_orderkey on group1;
+
+insert into LineID
+select element {'l_orderkey':l.l_orderkey,'l_partkey':l.l_partkey,'l_suppkey':l.l_partkey}
+from  LineItems_q1 as l
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_01.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_01.sqlpp
new file mode 100644
index 0000000..3e7ef15
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_01.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Tests that the optimizer drills through the let clause.
+ *                  Replacement should happen because of a "<=" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_01.adm"
+select element ed
+from  DBLP as o
+with  ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (ed <= 2)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_02.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_02.sqlpp
new file mode 100644
index 0000000..98506e9
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_02.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Tests that the optimizer drills through the let clause. 
+ *                  Replacement should happen because of a reverse "<=" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_02.adm"
+select element ed
+from  DBLP as o
+with  ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (2 >= ed)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_03.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_03.sqlpp
new file mode 100644
index 0000000..c5a255a
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_03.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Tests that the optimizer drills through the let clause.
+ *                  Replacement should happen because of a "<" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_03.adm"
+select element ed
+from  DBLP as o
+with  ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (ed < 3)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_04.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_04.sqlpp
new file mode 100644
index 0000000..3ad6b13
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_04.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Tests that the optimizer drills through the let clause.
+ *                  Replacement should happen because of a reverse "<" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_04.adm"
+select element ed
+from  DBLP as o
+with  ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (3 > ed)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_05.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_05.sqlpp
new file mode 100644
index 0000000..ba5ed31
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_05.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Tests that the optimizer drills through the let clause.
+ *                  Replacement should *not* happen because of a ">=" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_05.adm"
+select element ed
+from  DBLP as o
+with  ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (ed >= 2)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_06.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_06.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_06.sqlpp
new file mode 100644
index 0000000..2bc08b3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_06.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Tests that the optimizer drills through the let clause.
+ *                   Replacement should *not* happen because of a reverse ">=" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_06.adm"
+select element ed
+from  DBLP as o
+with  ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (2 <= ed)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_07.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_07.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_07.sqlpp
new file mode 100644
index 0000000..7aac82d
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_07.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Tests that the optimizer drills through the let clause.
+ *                  Replacement should *not* happen because of a ">" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_07.adm"
+select element ed
+from  DBLP as o
+with  ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (ed > 2)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_08.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_08.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_08.sqlpp
new file mode 100644
index 0000000..2758920
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-let-to-edit-distance-check_08.sqlpp
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Tests that the optimizer drills through the let clause.
+ *                  Replacement should *not* happen because of a reverse ">" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-let-to-edit-distance-check_08.adm"
+select element ed
+from  DBLP as o
+with  ed as test."edit-distance"(o.authors,'Michael J. Carey')
+where (2 < ed)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_01.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_01.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_01.sqlpp
new file mode 100644
index 0000000..12eb414
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_01.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Replacement should happen because of a "<=" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_01.adm"
+select element o
+from  DBLP as o
+where (test."edit-distance"(o.authors,'Michael J. Carey') <= 2)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_02.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_02.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_02.sqlpp
new file mode 100644
index 0000000..41893bb
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_02.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Replacement should happen because of a reverse "<=" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_02.adm"
+select element o
+from  DBLP as o
+where (2 >= test."edit-distance"(o.authors,'Michael J. Carey'))
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_03.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_03.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_03.sqlpp
new file mode 100644
index 0000000..10a0ef3
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_03.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Replacement should happen because of a "<" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_03.adm"
+select element o
+from  DBLP as o
+where (test."edit-distance"(o.authors,'Michael J. Carey') < 3)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_04.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_04.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_04.sqlpp
new file mode 100644
index 0000000..d9230b2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_04.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Replacement should happen because of a reverse "<" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_04.adm"
+select element o
+from  DBLP as o
+where (3 > test."edit-distance"(o.authors,'Michael J. Carey'))
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_05.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_05.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_05.sqlpp
new file mode 100644
index 0000000..90b3655
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_05.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Replacement should *not* happen because of a ">=" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_05.adm"
+select element o
+from  DBLP as o
+where (test."edit-distance"(o.authors,'Michael J. Carey') >= 2)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_06.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_06.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_06.sqlpp
new file mode 100644
index 0000000..2340250
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_06.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Replacement should *not* happen because of a reverse ">=" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_06.adm"
+select element o
+from  DBLP as o
+where (2 <= test."edit-distance"(o.authors,'Michael J. Carey'))
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_07.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_07.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_07.sqlpp
new file mode 100644
index 0000000..8b9f5c6
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_07.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Replacement should *not* happen because of a ">" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_07.adm"
+select element o
+from  DBLP as o
+where (test."edit-distance"(o.authors,'Michael J. Carey') > 2)
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_08.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_08.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_08.sqlpp
new file mode 100644
index 0000000..713c2b7
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/edit-distance-to-edit-distance-check_08.sqlpp
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the SimilarityCheckRule rewrites the edit-distance function with a threshold 
+ *                  into edit-distance-check if possible.
+ *                  Replacement should *not* happen because of a reverse ">" condition on the edit distance.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_edit-distance-to-edit-distance-check_08.adm"
+select element o
+from  DBLP as o
+where (2 < test."edit-distance"(o.authors,'Michael J. Carey'))
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-edit-distance-check.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-edit-distance-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-edit-distance-check.sqlpp
new file mode 100644
index 0000000..6d350d2
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-edit-distance-check.sqlpp
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the FuzzyEqRule rewrites ~= using edit distance 
+ *                  into edit-distance-check.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_fuzzyeq-to-edit-distance-check.adm"
+set "simfunction" "edit-distance";
+
+set "simthreshold" "1";
+
+select element o
+from  DBLP as o
+where (o.authors ~= 'Michael J. Carey')
+;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/391f09e5/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-jaccard-check.sqlpp
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-jaccard-check.sqlpp b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-jaccard-check.sqlpp
new file mode 100644
index 0000000..266c2fd
--- /dev/null
+++ b/asterix-app/src/test/resources/optimizerts/queries_sqlpp/similarity/fuzzyeq-to-jaccard-check.sqlpp
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description    : Tests that the FuzzyEqRule rewrites ~= using Jaccard 
+ *                  into edit-distance-check.
+ * Success        : Yes
+ */
+
+drop  database test if exists;
+create  database test;
+
+use test;
+
+
+create type test.DBLPType as
+ closed {
+  id : int32,
+  dblpid : string,
+  title : string,
+  authors : string,
+  misc : string
+}
+
+create  table DBLP(DBLPType) primary key id;
+
+write output to nc1:"rttest/similarity_fuzzyeq-to-jaccard-check.adm"
+set "simfunction" "jaccard";
+
+set "simthreshold" "0.8f";
+
+select element paper
+from  DBLP as paper
+where (test."word-tokens"(paper.title) ~= test."word-tokens"('Transactions for Cooperative Environments'))
+;