Till Westmann has submitted this change and it was merged. ( https://asterix-gerrit.ics.uci.edu/3431 )
Change subject: [NO ISSUE][COMP] Better error messages for dump_index ...................................................................... [NO ISSUE][COMP] Better error messages for dump_index - user model changes: no - storage format changes: no - interface changes: no Change-Id: I87d75f7264c1eecf178300a1b0a67b351cce0216 Reviewed-on: https://asterix-gerrit.ics.uci.edu/3431 Contrib: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Sonar-Qube: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Till Westmann <ti...@apache.org> Reviewed-by: Murtadha Hubail <mhub...@apache.org> --- M asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DatasetResourcesRewriter.java M asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexRewriter.java M asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/FunctionRewriter.java M asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/StorageComponentsRewriter.java A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.4.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.5.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.6.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.7.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.8.query.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.9.query.sqlpp M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml M asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java M asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties 13 files changed, 160 insertions(+), 21 deletions(-) Approvals: Jenkins: Verified; No violations found; ; Verified Till Westmann: Looks good to me, but someone else must approve Murtadha Hubail: Looks good to me, approved Anon. E. Moose (1000171): diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DatasetResourcesRewriter.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DatasetResourcesRewriter.java index 47c1045..f1687b5 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DatasetResourcesRewriter.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DatasetResourcesRewriter.java @@ -27,6 +27,7 @@ import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext; import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression; import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.api.exceptions.SourceLocation; public class DatasetResourcesRewriter extends FunctionRewriter { @@ -42,13 +43,13 @@ @Override public DatasetResourcesDatasource toDatasource(IOptimizationContext context, AbstractFunctionCallExpression f) throws AlgebricksException { - String dataverseName = getString(f.getArguments(), 0); - String datasetName = getString(f.getArguments(), 1); + final SourceLocation loc = f.getSourceLocation(); + String dataverseName = getString(loc, f.getArguments(), 0); + String datasetName = getString(loc, f.getArguments(), 1); MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider(); Dataset dataset = metadataProvider.findDataset(dataverseName, datasetName); if (dataset == null) { - throw new CompilationException(ErrorCode.UNKNOWN_DATASET_IN_DATAVERSE, f.getSourceLocation(), datasetName, - dataverseName); + throw new CompilationException(ErrorCode.UNKNOWN_DATASET_IN_DATAVERSE, loc, datasetName, dataverseName); } return new DatasetResourcesDatasource(context.getComputationNodeDomain(), dataset.getDatasetId()); } diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexRewriter.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexRewriter.java index c91e9b0..08e5d51 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexRewriter.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/DumpIndexRewriter.java @@ -29,6 +29,7 @@ import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext; import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression; import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.api.exceptions.SourceLocation; import org.apache.hyracks.storage.am.common.dataflow.IndexDataflowHelperFactory; public class DumpIndexRewriter extends FunctionRewriter { @@ -44,24 +45,24 @@ @Override public DumpIndexDatasource toDatasource(IOptimizationContext context, AbstractFunctionCallExpression f) throws AlgebricksException { - String dataverseName = getString(f.getArguments(), 0); - String datasetName = getString(f.getArguments(), 1); - String indexName = getString(f.getArguments(), 2); + final SourceLocation loc = f.getSourceLocation(); + String dataverseName = getString(loc, f.getArguments(), 0); + String datasetName = getString(loc, f.getArguments(), 1); + String indexName = getString(loc, f.getArguments(), 2); MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider(); final Dataset dataset = metadataProvider.findDataset(dataverseName, datasetName); if (dataset == null) { - throw new CompilationException(ErrorCode.UNKNOWN_DATASET_IN_DATAVERSE, f.getSourceLocation(), datasetName, - dataverseName); + throw new CompilationException(ErrorCode.UNKNOWN_DATASET_IN_DATAVERSE, loc, datasetName, dataverseName); } Index index = metadataProvider.getIndex(dataverseName, datasetName, indexName); if (index == null) { - throw new CompilationException(ErrorCode.UNKNOWN_INDEX, f.getSourceLocation(), index); + throw new CompilationException(ErrorCode.UNKNOWN_INDEX, loc, indexName); } if (index.isPrimaryIndex()) { - throw new IllegalStateException("primary indexes are not supported"); + throw new CompilationException(ErrorCode.OPERATION_NOT_SUPPORTED_ON_PRIMARY_INDEX, loc, indexName); } - SecondaryIndexOperationsHelper secondaryIndexHelper = SecondaryIndexOperationsHelper - .createIndexOperationsHelper(dataset, index, metadataProvider, f.getSourceLocation()); + SecondaryIndexOperationsHelper secondaryIndexHelper = + SecondaryIndexOperationsHelper.createIndexOperationsHelper(dataset, index, metadataProvider, loc); IndexDataflowHelperFactory indexDataflowHelperFactory = new IndexDataflowHelperFactory(metadataProvider.getStorageComponentProvider().getStorageManager(), secondaryIndexHelper.getSecondaryFileSplitProvider()); diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/FunctionRewriter.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/FunctionRewriter.java index 2bc5ab6..d1f1898 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/FunctionRewriter.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/FunctionRewriter.java @@ -18,6 +18,8 @@ */ package org.apache.asterix.app.function; +import static org.apache.asterix.common.exceptions.ErrorCode.EXPECTED_CONSTANT_VALUE; + import java.util.ArrayList; import java.util.List; @@ -26,6 +28,7 @@ import org.apache.asterix.metadata.declared.FunctionDataSource; import org.apache.asterix.om.base.AString; import org.apache.asterix.om.constants.AsterixConstantValue; +import org.apache.asterix.om.exceptions.UnsupportedTypeException; import org.apache.asterix.om.functions.IFunctionToDataSourceRewriter; import org.apache.asterix.om.types.ATypeTag; import org.apache.asterix.optimizer.rules.UnnestToDataScanRule; @@ -42,6 +45,7 @@ import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; import org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator; import org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator; +import org.apache.hyracks.api.exceptions.SourceLocation; public abstract class FunctionRewriter implements IFunctionToDataSourceRewriter { @@ -90,15 +94,17 @@ protected abstract FunctionDataSource toDatasource(IOptimizationContext context, AbstractFunctionCallExpression f) throws AlgebricksException; - protected String getString(List<Mutable<ILogicalExpression>> args, int i) throws AlgebricksException { + protected String getString(SourceLocation loc, List<Mutable<ILogicalExpression>> args, int i) + throws AlgebricksException { ConstantExpression ce = (ConstantExpression) args.get(i).getValue(); IAlgebricksConstantValue acv = ce.getValue(); if (!(acv instanceof AsterixConstantValue)) { - throw new AlgebricksException("Expected arg[" + i + "] to be of type String"); + throw new CompilationException(EXPECTED_CONSTANT_VALUE, loc); } AsterixConstantValue acv2 = (AsterixConstantValue) acv; - if (acv2.getObject().getType().getTypeTag() != ATypeTag.STRING) { - throw new AlgebricksException("Expected arg[" + i + "] to be of type String"); + final ATypeTag typeTag = acv2.getObject().getType().getTypeTag(); + if (typeTag != ATypeTag.STRING) { + throw new UnsupportedTypeException(loc, functionId, typeTag); } return ((AString) acv2.getObject()).getStringValue(); } diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/StorageComponentsRewriter.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/StorageComponentsRewriter.java index 259e6d7..3b89d50 100644 --- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/StorageComponentsRewriter.java +++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/function/StorageComponentsRewriter.java @@ -27,6 +27,7 @@ import org.apache.hyracks.algebricks.core.algebra.base.IOptimizationContext; import org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression; import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier; +import org.apache.hyracks.api.exceptions.SourceLocation; public class StorageComponentsRewriter extends FunctionRewriter { @@ -42,13 +43,13 @@ @Override public StorageComponentsDatasource toDatasource(IOptimizationContext context, AbstractFunctionCallExpression f) throws AlgebricksException { - String dataverseName = getString(f.getArguments(), 0); - String datasetName = getString(f.getArguments(), 1); + SourceLocation loc = f.getSourceLocation(); + String dataverseName = getString(loc, f.getArguments(), 0); + String datasetName = getString(loc, f.getArguments(), 1); MetadataProvider metadataProvider = (MetadataProvider) context.getMetadataProvider(); Dataset dataset = metadataProvider.findDataset(dataverseName, datasetName); if (dataset == null) { - throw new CompilationException(ErrorCode.UNKNOWN_DATASET_IN_DATAVERSE, f.getSourceLocation(), datasetName, - dataverseName); + throw new CompilationException(ErrorCode.UNKNOWN_DATASET_IN_DATAVERSE, loc, datasetName, dataverseName); } return new StorageComponentsDatasource(context.getComputationNodeDomain(), dataset.getDatasetId()); } diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.4.query.sqlpp new file mode 100644 index 0000000..0428cf6 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.4.query.sqlpp @@ -0,0 +1,20 @@ +/* + * 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. + */ +SET `import-private-functions` `true`; +SELECT VALUE DUMP_INDEX("test", "ds", "noindex"); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.5.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.5.query.sqlpp new file mode 100644 index 0000000..1046b73 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.5.query.sqlpp @@ -0,0 +1,20 @@ +/* + * 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. + */ +SET `import-private-functions` `true`; +SELECT VALUE DUMP_INDEX("test", "nodataset", "name_idx"); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.6.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.6.query.sqlpp new file mode 100644 index 0000000..b31601a --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.6.query.sqlpp @@ -0,0 +1,20 @@ +/* + * 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. + */ +SET `import-private-functions` `true`; +SELECT VALUE DUMP_INDEX("nodataverse", "ds", "name_idx"); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.7.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.7.query.sqlpp new file mode 100644 index 0000000..79dcf01 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.7.query.sqlpp @@ -0,0 +1,20 @@ +/* + * 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. + */ +SET `import-private-functions` `true`; +SELECT VALUE DUMP_INDEX("test", "ds", NULL); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.8.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.8.query.sqlpp new file mode 100644 index 0000000..ffe5c55 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.8.query.sqlpp @@ -0,0 +1,20 @@ +/* + * 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. + */ +SET `import-private-functions` `true`; +SELECT VALUE DUMP_INDEX("test", NULL, "name_idx"); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.9.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.9.query.sqlpp new file mode 100644 index 0000000..0e7e884 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/misc/dump_index/dump_index.9.query.sqlpp @@ -0,0 +1,20 @@ +/* + * 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. + */ +SET `import-private-functions` `true`; +SELECT VALUE DUMP_INDEX(NULL, "ds", "name_idx"); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml index 661e54e..a2e47d6 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -6046,6 +6046,12 @@ <test-case FilePath="misc"> <compilation-unit name="dump_index"> <output-dir compare="Text">dump_index</output-dir> + <expected-error>Cannot find index with name noindex</expected-error> + <expected-error>Cannot find dataset with name nodataset in dataverse test</expected-error> + <expected-error>Cannot find dataset with name ds in dataverse nodataverse</expected-error> + <expected-error>Unsupported type: dump-index cannot process input type null</expected-error> + <expected-error>Unsupported type: dump-index cannot process input type null</expected-error> + <expected-error>Unsupported type: dump-index cannot process input type null</expected-error> </compilation-unit> </test-case> <test-case FilePath="misc"> diff --git a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java index 9902afc..dc67f7e 100644 --- a/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java +++ b/asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java @@ -185,6 +185,8 @@ public static final int COMPILATION_EXPECTED_WINDOW_FUNCTION = 1102; public static final int COMPILATION_ILLEGAL_USE_OF_IDENTIFIER = 1103; public static final int INVALID_FUNCTION_MODIFIER = 1104; + public static final int OPERATION_NOT_SUPPORTED_ON_PRIMARY_INDEX = 1105; + public static final int EXPECTED_CONSTANT_VALUE = 1106; // Feed errors public static final int DATAFLOW_ILLEGAL_STATE = 3001; diff --git a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties index 49a9821..0478815 100644 --- a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties +++ b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties @@ -180,6 +180,8 @@ 1102 = Expected window or aggregate function, got: %1$s 1103 = Illegal use of identifier: %1$s 1104 = Invalid modifier %1$s for function %2$s +1105 = Operation not supported on primary index %1$s +1106 = Expected constant value # Feed Errors 3001 = Illegal state. -- To view, visit https://asterix-gerrit.ics.uci.edu/3431 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-MessageType: merged Gerrit-Change-Id: I87d75f7264c1eecf178300a1b0a67b351cce0216 Gerrit-Change-Number: 3431 Gerrit-PatchSet: 2 Gerrit-Owner: Till Westmann <ti...@apache.org> Gerrit-Reviewer: Anon. E. Moose (1000171) Gerrit-Reviewer: Dmitry Lychagin <dmitry.lycha...@couchbase.com> Gerrit-Reviewer: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Gerrit-Reviewer: Murtadha Hubail <mhub...@apache.org> Gerrit-Reviewer: Till Westmann <ti...@apache.org>