asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wangs...@apache.org
Subject incubator-asterixdb git commit: ASTERIXDB-1231, ASTERIXDB-636: fixed Self-join
Date Tue, 16 Feb 2016 21:04:30 GMT
Repository: incubator-asterixdb
Updated Branches:
  refs/heads/master d33d3d1a6 -> 0c8e22d4d


ASTERIXDB-1231, ASTERIXDB-636: fixed Self-join

 - Fixed self-join with index-out-of-boud exception during the compilation
 - Added a test case for ASTERIXDB-636

Change-Id: I8d5d9cb0cb54473fbe7a5e43934e9608548c1dbb
Reviewed-on: https://asterix-gerrit.ics.uci.edu/635
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/commit/0c8e22d4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/tree/0c8e22d4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/diff/0c8e22d4

Branch: refs/heads/master
Commit: 0c8e22d4d2b2f98310250d7a90d108d18cb662a7
Parents: d33d3d1
Author: Taewoo Kim <wangsaeu@yahoo.com>
Authored: Tue Feb 16 12:29:02 2016 -0800
Committer: Taewoo Kim <wangsaeu@yahoo.com>
Committed: Tue Feb 16 12:59:23 2016 -0800

----------------------------------------------------------------------
 .../am/AbstractIntroduceAccessMethodRule.java   | 36 ++++++++----
 .../metadata_selfjoin.1.ddl.aql                 | 27 +++++++++
 .../metadata_selfjoin.2.update.aql              | 24 ++++++++
 .../metadata_selfjoin.3.query.aql               | 32 +++++++++++
 .../metadata_selfjoin/metadata_selfjoin.1.adm   | 13 +++++
 .../src/test/resources/metadata/testsuite.xml   |  5 ++
 .../orderby_limit_02/orderby_limit_02.1.ddl.aql | 36 ++++++++++++
 .../orderby_limit_02.2.update.aql               | 60 ++++++++++++++++++++
 .../orderby_limit_02.3.query.aql                | 33 +++++++++++
 .../orderby_limit_02/orderby_limit_02.1.adm     |  5 ++
 .../src/test/resources/runtimets/testsuite.xml  |  5 ++
 11 files changed, 266 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0c8e22d4/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
----------------------------------------------------------------------
diff --git a/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
b/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
index 1531b8a..cabc1e3 100644
--- a/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
+++ b/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java
@@ -168,8 +168,8 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
                 //                           LENGTH_PARTITIONED_NGRAM_INVIX]
                 IAccessMethod chosenAccessMethod = amEntry.getKey();
                 Index chosenIndex = indexEntry.getKey();
-                boolean isKeywordOrNgramIndexChosen =
-                        chosenIndex.getIndexType() == IndexType.LENGTH_PARTITIONED_WORD_INVIX
+                boolean isKeywordOrNgramIndexChosen = chosenIndex
+                        .getIndexType() == IndexType.LENGTH_PARTITIONED_WORD_INVIX
                         || chosenIndex.getIndexType() == IndexType.LENGTH_PARTITIONED_NGRAM_INVIX
                         || chosenIndex.getIndexType() == IndexType.SINGLE_PARTITION_WORD_INVIX
                         || chosenIndex.getIndexType() == IndexType.SINGLE_PARTITION_NGRAM_INVIX;
@@ -185,7 +185,6 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
         return result;
     }
 
-
     /**
      * Removes irrelevant access methods candidates, based on whether the
      * expressions in the query match those in the index. For example, some
@@ -574,16 +573,33 @@ public abstract class AbstractIntroduceAccessMethodRule implements IAlgebraicRew
             // The variable value is one of the partitioning fields.
             List<String> fieldName = null;
             IAType fieldType = null;
+            List<List<String>> subTreePKs = null;
 
             if (!fromAdditionalDataSource) {
-                fieldName = DatasetUtils.getPartitioningKeys(subTree.dataset).get(varIndex);
-                fieldType = (IAType) context.getOutputTypeEnvironment(subTree.dataSourceRef.getValue()).getVarType(var);
+                subTreePKs = DatasetUtils.getPartitioningKeys(subTree.dataset);
+                // Check whether this variable is PK, not a record variable.
+                if (varIndex <= subTreePKs.size() - 1) {
+                    fieldName = subTreePKs.get(varIndex);
+                    fieldType = (IAType) context.getOutputTypeEnvironment(subTree.dataSourceRef.getValue())
+                            .getVarType(var);
+                }
             } else {
-                fieldName = DatasetUtils.getPartitioningKeys(subTree.ixJoinOuterAdditionalDatasets.get(varIndex))
-                        .get(varIndex);
-                fieldType = (IAType) context
-                        .getOutputTypeEnvironment(subTree.ixJoinOuterAdditionalDataSourceRefs.get(varIndex).getValue())
-                        .getVarType(var);
+                // Need to check additional dataset one by one
+                for (int i = 0; i < subTree.ixJoinOuterAdditionalDatasets.size(); i++)
{
+                    if (subTree.ixJoinOuterAdditionalDatasets.get(i) != null) {
+                        subTreePKs = DatasetUtils.getPartitioningKeys(subTree.ixJoinOuterAdditionalDatasets.get(i));
+
+                        // Check whether this variable is PK, not a record variable.
+                        if (subTreePKs.contains(var) && varIndex <= subTreePKs.size()
- 1) {
+                            fieldName = subTreePKs.get(varIndex);
+                            fieldType = (IAType) context
+                                    .getOutputTypeEnvironment(
+                                            subTree.ixJoinOuterAdditionalDataSourceRefs.get(i).getValue())
+                                    .getVarType(var);
+                            break;
+                        }
+                    }
+                }
             }
             // Set the fieldName in the corresponding matched function
             // expression, and remember matching subtree.

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0c8e22d4/asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.1.ddl.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.1.ddl.aql
b/asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.1.ddl.aql
new file mode 100644
index 0000000..1a690a1
--- /dev/null
+++ b/asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.1.ddl.aql
@@ -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.
+ */
+
+/*
+ * Description  : Checks whether a meta-data self-join query works or not.
+ * Expected Res : Success
+ * Issue        : ASTERIXDB-1231
+ */
+
+drop dataverse testdv if exists;
+drop dataverse test if exists;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0c8e22d4/asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.2.update.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.2.update.aql
b/asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.2.update.aql
new file mode 100644
index 0000000..15bf59a
--- /dev/null
+++ b/asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.2.update.aql
@@ -0,0 +1,24 @@
+/*
+ * 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  : Checks whether a meta-data self-join query works or not.
+ * Expected Res : Success
+ * Issue        : ASTERIXDB-1231
+ */
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0c8e22d4/asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.3.query.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.3.query.aql
b/asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.3.query.aql
new file mode 100644
index 0000000..569d3d1
--- /dev/null
+++ b/asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.3.query.aql
@@ -0,0 +1,32 @@
+/*
+ * 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  : Checks whether a meta-data self-join query works or not.
+ * Expected Res : Success
+ * Issue        : ASTERIXDB-1231
+ */
+
+use dataverse Metadata;
+
+for $m in dataset Metadata.Dataset
+for $n in dataset Metadata.Dataset
+where $m=$n
+return
+{ "dv1": $m.DataverseName, "dv2": $n.DataverseName }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0c8e22d4/asterix-app/src/test/resources/metadata/results/basic/metadata_selfjoin/metadata_selfjoin.1.adm
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/metadata/results/basic/metadata_selfjoin/metadata_selfjoin.1.adm
b/asterix-app/src/test/resources/metadata/results/basic/metadata_selfjoin/metadata_selfjoin.1.adm
new file mode 100644
index 0000000..da05a15
--- /dev/null
+++ b/asterix-app/src/test/resources/metadata/results/basic/metadata_selfjoin/metadata_selfjoin.1.adm
@@ -0,0 +1,13 @@
+{ "dv1": "Metadata", "dv2": "Metadata" }
+{ "dv1": "Metadata", "dv2": "Metadata" }
+{ "dv1": "Metadata", "dv2": "Metadata" }
+{ "dv1": "Metadata", "dv2": "Metadata" }
+{ "dv1": "Metadata", "dv2": "Metadata" }
+{ "dv1": "Metadata", "dv2": "Metadata" }
+{ "dv1": "Metadata", "dv2": "Metadata" }
+{ "dv1": "Metadata", "dv2": "Metadata" }
+{ "dv1": "Metadata", "dv2": "Metadata" }
+{ "dv1": "Metadata", "dv2": "Metadata" }
+{ "dv1": "Metadata", "dv2": "Metadata" }
+{ "dv1": "Metadata", "dv2": "Metadata" }
+{ "dv1": "Metadata", "dv2": "Metadata" }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0c8e22d4/asterix-app/src/test/resources/metadata/testsuite.xml
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/metadata/testsuite.xml b/asterix-app/src/test/resources/metadata/testsuite.xml
index 0b8c26a..bba2ab0 100644
--- a/asterix-app/src/test/resources/metadata/testsuite.xml
+++ b/asterix-app/src/test/resources/metadata/testsuite.xml
@@ -274,6 +274,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="basic">
+      <compilation-unit name="metadata_selfjoin">
+        <output-dir compare="Text">metadata_selfjoin</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="basic">
       <compilation-unit name="temp_dataset">
         <output-dir compare="Text">temp_dataset</output-dir>
       </compilation-unit>

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0c8e22d4/asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.1.ddl.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.1.ddl.aql
b/asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.1.ddl.aql
new file mode 100644
index 0000000..33722e7
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.1.ddl.aql
@@ -0,0 +1,36 @@
+/*
+ * 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     : Range search query with LIMIT (and ORDER BY) should work fine.
+ *  Issue           : ASTERIXDB-636
+ *  Expected Result : Success
+ *
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use dataverse test;
+
+create type Emp as open
+{ id : int32, name: string, salary: int32 }
+
+create dataset Employee(Emp) primary key id;
+
+create index idx-02 on Employee(name);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0c8e22d4/asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.2.update.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.2.update.aql
b/asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.2.update.aql
new file mode 100644
index 0000000..d0b363f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.2.update.aql
@@ -0,0 +1,60 @@
+/*
+ * 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     : Range search query with LIMIT (and ORDER BY) should work fine.
+ *  Issue           : ASTERIXDB-636
+ *  Expected Result : Success
+ *
+ */
+
+
+use dataverse test;
+
+insert into dataset Employee (
+    {"id":123,"name":"Kevin","salary":10000}
+);
+
+insert into dataset Employee (
+    {"id":13,"name":"John","salary":5000}
+);
+
+insert into dataset Employee (
+    {"id":23,"name":"Susan","salary":7500}
+);
+
+insert into dataset Employee (
+    {"id":12,"name":"Smith","salary":4000}
+);
+
+insert into dataset Employee (
+    {"id":113,"name":"Roger","salary":8000}
+);
+
+insert into dataset Employee (
+    {"id":143,"name":"Raj","salary":6000}
+);
+
+insert into dataset Employee (
+    {"id":149,"name":"Ramesh","salary":5000}
+);
+
+insert into dataset Employee (
+    {"id":240,"name":"Ravi","salary":6500}
+);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0c8e22d4/asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.3.query.aql
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.3.query.aql
b/asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.3.query.aql
new file mode 100644
index 0000000..93288aa
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.3.query.aql
@@ -0,0 +1,33 @@
+/*
+ * 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     : Range search query with LIMIT (and ORDER BY) should work fine.
+ *  Issue           : ASTERIXDB-636
+ *  Expected Result : Success
+ *
+ */
+
+use dataverse test;
+
+for $l in dataset Employee
+where $l.name >= "A" and $l.name <= "Z"
+limit 5
+order by $l.name desc
+return {"name": $l.name}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0c8e22d4/asterix-app/src/test/resources/runtimets/results/orderby_limit/orderby_limit_02/orderby_limit_02.1.adm
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/results/orderby_limit/orderby_limit_02/orderby_limit_02.1.adm
b/asterix-app/src/test/resources/runtimets/results/orderby_limit/orderby_limit_02/orderby_limit_02.1.adm
new file mode 100644
index 0000000..e027c88
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/orderby_limit/orderby_limit_02/orderby_limit_02.1.adm
@@ -0,0 +1,5 @@
+{ "name": "Susan" }
+{ "name": "Smith" }
+{ "name": "Roger" }
+{ "name": "Kevin" }
+{ "name": "John" }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/0c8e22d4/asterix-app/src/test/resources/runtimets/testsuite.xml
----------------------------------------------------------------------
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index 48dcbb4..bcc80ad 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -4306,6 +4306,11 @@
             </compilation-unit>
         </test-case>
         <test-case FilePath="orderby_limit">
+            <compilation-unit name="orderby_limit_02">
+                <output-dir compare="Text">orderby_limit_02</output-dir>
+            </compilation-unit>
+        </test-case>
+        <test-case FilePath="orderby_limit">
             <compilation-unit name="orderby_limit_offset_01">
                 <output-dir compare="Text">orderby_limit_offset_01</output-dir>
             </compilation-unit>


Mime
View raw message