>From Peeyush Gupta <[email protected]>: Peeyush Gupta has submitted this change. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18244 )
Change subject: [ASTERIXDB-3385][COMP] Duplicate fields should not accepted in primary key ...................................................................... [ASTERIXDB-3385][COMP] Duplicate fields should not accepted in primary key - user model changes: no - storage format changes: no - interface changes: no Change-Id: I07f3bca08058dd17fd54dd0e9cc6b4ee8cb01d28 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18244 Integration-Tests: Jenkins <[email protected]> Reviewed-by: Murtadha Hubail <[email protected]> Tested-by: Peeyush Gupta <[email protected]> --- M asterixdb/asterix-common/src/main/java/org/apache/asterix/common/exceptions/ErrorCode.java M asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-negative/create-dataset-negative.04.ddl.sqlpp M asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java M asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-negative/create-dataset-negative.03.ddl.sqlpp 6 files changed, 97 insertions(+), 0 deletions(-) Approvals: Murtadha Hubail: Looks good to me, approved Peeyush Gupta: Verified Jenkins: Verified diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java index e253e07..34976b6 100644 --- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java +++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/ValidateUtil.java @@ -122,10 +122,36 @@ autogenerated, true, sourceLoc, partitioningExprTypes); } + private static void checkDuplicateFields(List<List<String>> partitioningExprs, SourceLocation sourceLoc) + throws CompilationException { + for (int i = 0; i < partitioningExprs.size(); i++) { + List<String> expr1 = partitioningExprs.get(i); + for (int j = i + 1; j < partitioningExprs.size(); j++) { + List<String> expr2 = partitioningExprs.get(j); + int k = 0; + while (k < expr1.size() && k < expr2.size()) { + if (!expr1.get(k).equals(expr2.get(k))) { + break; + } else { + k += 1; + } + } + if (k == expr1.size() && k == expr2.size()) { + throw new CompilationException(ErrorCode.DUPLICATE_FIELD_IN_PRIMARY_KEY, sourceLoc, + String.join(".", expr1)); + } else if (k == expr1.size() || k == expr2.size()) { + throw new CompilationException(ErrorCode.INCOMPATIBLE_FIELDS_IN_PRIMARY_KEY, sourceLoc, + String.join(".", expr1), String.join(".", expr2)); + } + } + } + } + private static List<IAType> validatePartitioningExpressionsImpl(ARecordType recType, ARecordType metaRecType, List<List<String>> partitioningExprs, List<Integer> keySourceIndicators, boolean autogenerated, boolean forPrimaryKey, SourceLocation sourceLoc, List<TypeExpression> partitioningExprTypes) throws AlgebricksException { + checkDuplicateFields(partitioningExprs, sourceLoc); String keyKindDisplayName = forPrimaryKey ? PRIMARY : ""; List<IAType> computedPartitioningExprTypes = new ArrayList<>(partitioningExprs.size()); if (autogenerated) { diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-negative/create-dataset-negative.03.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-negative/create-dataset-negative.03.ddl.sqlpp new file mode 100644 index 0000000..52c5119 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-negative/create-dataset-negative.03.ddl.sqlpp @@ -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. + */ + +drop dataverse test if exists; +create dataverse test; +use test; + +create dataset orders primary key (id:int, id:int); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-negative/create-dataset-negative.04.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-negative/create-dataset-negative.04.ddl.sqlpp new file mode 100644 index 0000000..6c4b039 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-negative/create-dataset-negative.04.ddl.sqlpp @@ -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. + */ + +drop dataverse test if exists; +create dataverse test; +use test; + +create dataset orders primary key (a:int, a.b:string, c:int); diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml index 783727a..6e19f2b 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/sqlpp_queries.xml @@ -4170,6 +4170,8 @@ <output-dir compare="Clean-JSON">create-dataset-negative</output-dir> <expected-error>ASX1001: Syntax error: Invalid primary key specification</expected-error> <expected-error>ASX1001: Syntax error: Invalid primary key specification</expected-error> + <expected-error>ASX1198: Duplicate field 'id' in primary key</expected-error> + <expected-error>ASX1199: Fields 'a' and 'a.b' are incompatible for primary key</expected-error> </compilation-unit> </test-case> <test-case FilePath="ddl"> 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 4d3b57b..2810399 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 @@ -300,6 +300,8 @@ COMPOSITE_KEY_NOT_SUPPORTED(1195), EXTERNAL_SINK_ERROR(1196), MINIMUM_VALUE_ALLOWED_FOR_PARAM(1197), + DUPLICATE_FIELD_IN_PRIMARY_KEY(1198), + INCOMPATIBLE_FIELDS_IN_PRIMARY_KEY(1199), // Feed errors 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 72bb788..dd557b9 100644 --- a/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties +++ b/asterixdb/asterix-common/src/main/resources/asx_errormsg/en.properties @@ -302,6 +302,8 @@ 1195 = Composite key is not allowed, only single key must be specified. 1196 = External sink error. %1$s 1197 = Minimum value allowed for '%1$s' is %2$s. Found %3$s +1198 = Duplicate field '%1$s' in primary key +1199 = Fields '%1$s' and '%2$s' are incompatible for primary key # Feed Errors 3001 = Illegal state. -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/18244 To unsubscribe, or for help writing mail filters, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Change-Id: I07f3bca08058dd17fd54dd0e9cc6b4ee8cb01d28 Gerrit-Change-Number: 18244 Gerrit-PatchSet: 3 Gerrit-Owner: Peeyush Gupta <[email protected]> Gerrit-Reviewer: Ali Alsuliman <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Murtadha Hubail <[email protected]> Gerrit-Reviewer: Peeyush Gupta <[email protected]> Gerrit-MessageType: merged
