Taewoo Kim has submitted this change and it was merged. Change subject: ASTERIXDB-1231, ASTERIXDB-636: fixed Self-join ......................................................................
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 <[email protected]> Reviewed-by: Yingyi Bu <[email protected]> --- M asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java A asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.1.ddl.aql A asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.2.update.aql A asterix-app/src/test/resources/metadata/queries/basic/metadata_selfjoin/metadata_selfjoin.3.query.aql A asterix-app/src/test/resources/metadata/results/basic/metadata_selfjoin/metadata_selfjoin.1.adm M asterix-app/src/test/resources/metadata/testsuite.xml A asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.1.ddl.aql A asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.2.update.aql A asterix-app/src/test/resources/runtimets/queries/orderby_limit/orderby_limit_02/orderby_limit_02.3.query.aql A asterix-app/src/test/resources/runtimets/results/orderby_limit/orderby_limit_02/orderby_limit_02.1.adm M asterix-app/src/test/resources/runtimets/testsuite.xml 11 files changed, 266 insertions(+), 10 deletions(-) Approvals: Yingyi Bu: Looks good to me, approved Jenkins: Verified 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 @@ // 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; @@ -184,7 +184,6 @@ } return result; } - /** * Removes irrelevant access methods candidates, based on whether the @@ -574,16 +573,33 @@ // 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. 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; 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 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 } 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" } 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> 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); 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 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} 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" } 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> -- To view, visit https://asterix-gerrit.ics.uci.edu/635 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I8d5d9cb0cb54473fbe7a5e43934e9608548c1dbb Gerrit-PatchSet: 7 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Taewoo Kim <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Taewoo Kim <[email protected]> Gerrit-Reviewer: Yingyi Bu <[email protected]>
