This is an automated email from the ASF dual-hosted git repository. dlych pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/asterixdb.git
The following commit(s) were added to refs/heads/master by this push: new 544cfdd [NO ISSUE][COMP] Disallow duplicate field names in CREATE TYPE 544cfdd is described below commit 544cfdd77f48e0e280b33c4d2a6973e1f2ffa493 Author: Dmitry Lychagin <dmitry.lycha...@couchbase.com> AuthorDate: Wed Nov 10 11:15:50 2021 -0800 [NO ISSUE][COMP] Disallow duplicate field names in CREATE TYPE - user model changes: no - storage format changes: no - interface changes: no Details: - Disallow duplicate field names in types created by CREATE TYPE and inline type definitions in CREATE DATASET/VIEW Change-Id: I437c94054eb5019b57d9f20a02a688ffaed937e2 Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/14024 Integration-Tests: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Tested-by: Jenkins <jenk...@fulliautomatix.ics.uci.edu> Reviewed-by: Dmitry Lychagin <dmitry.lycha...@couchbase.com> Reviewed-by: Ali Alsuliman <ali.al.solai...@gmail.com> --- .../apache/asterix/translator/TypeTranslator.java | 3 ++ .../ddl/bad-type-ddl/bad-type-ddl.2.ddl.sqlpp | 32 ++++++++++++++++++++++ .../create-dataset-inline-type-2.6.ddl.sqlpp | 29 ++++++++++++++++++++ .../create-view-6-typed-negative.27.ddl.sqlpp | 26 ++++++++++++++++++ .../test/resources/runtimets/testsuite_sqlpp.xml | 3 ++ 5 files changed, 93 insertions(+) diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TypeTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TypeTranslator.java index 6e02fc2..c482269 100644 --- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TypeTranslator.java +++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/TypeTranslator.java @@ -313,6 +313,9 @@ public class TypeTranslator { IAType[] fldTypes = new IAType[n]; int i = 0; for (String s : names) { + if (names.indexOf(s) < i) { + throw new CompilationException(ErrorCode.DUPLICATE_FIELD_NAME, rtd.getSourceLocation(), s); + } fldNames[i++] = s; } boolean isOpen = rtd.getRecordKind() == RecordKind.OPEN; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/bad-type-ddl/bad-type-ddl.2.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/bad-type-ddl/bad-type-ddl.2.ddl.sqlpp new file mode 100644 index 0000000..effd74b --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/bad-type-ddl/bad-type-ddl.2.ddl.sqlpp @@ -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 : Duplicate field name + * Expected Res : Error + */ + +drop dataverse experiments if exists; +create dataverse experiments; +use experiments; + +create type t1 as { + c : string, + c : string +}; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-inline-type-2/create-dataset-inline-type-2.6.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-inline-type-2/create-dataset-inline-type-2.6.ddl.sqlpp new file mode 100644 index 0000000..1c5f520 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/create-dataset-inline-type-2/create-dataset-inline-type-2.6.ddl.sqlpp @@ -0,0 +1,29 @@ +/* + * 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. + */ + +/* Create dataset that attempts to declare the same field twice + in inline type definition */ + +USE test; + +CREATE DATASET Cust4X( + c_custkey integer not unknown, + c_name string, + c_name string +) PRIMARY KEY c_custkey; diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.27.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.27.ddl.sqlpp new file mode 100644 index 0000000..dd69e56 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/view/create-view-6-typed-negative/create-view-6-typed-negative.27.ddl.sqlpp @@ -0,0 +1,26 @@ +/* + * 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. + */ + +--- Negative: view inline type has duplicate fields + +drop dataverse test if exists; +create dataverse test; + +create view test.v1(r bigint, r bigint) default null as + select r, [r] a from range(1,2) r; 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 87c4457..77f412c 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -4158,6 +4158,7 @@ <compilation-unit name="bad-type-ddl"> <output-dir compare="Text">none</output-dir> <expected-error>ASX1079: Compilation error: Reserved type name $x</expected-error> + <expected-error>ASX0013: Duplicate field name "c" (in line 29, at column 19)</expected-error> </compilation-unit> </test-case> <test-case FilePath="ddl"> @@ -4171,6 +4172,7 @@ <expected-error>ASX1082: Cannot find datatype with name test.$d$t$i$Cust1</expected-error> <expected-error>ASX1082: Cannot find datatype with name test.$d$t$i$Cust2</expected-error> <expected-error>ASX1082: Cannot find datatype with name my_unknown_type</expected-error> + <expected-error>ASX0013: Duplicate field name "c_name" (in line 25, at column 22)</expected-error> </compilation-unit> </test-case> <test-case FilePath="ddl"> @@ -13374,6 +13376,7 @@ <expected-error><![CDATA[ASX1164: Invalid foreign key definition (in line 39, at column 1)]]></expected-error> <expected-error><![CDATA[ASX1166: Invalid foreign key definition: foreign key does not match primary key of view test1.employee_v1 (in line 39, at column 1)]]></expected-error> <expected-error><![CDATA[ASX1167: Cannot change primary key of view test1.employee_v1 (in line 38, at column 1)]]></expected-error> + <expected-error><![CDATA[ASX0013: Duplicate field name "r" (in line 25, at column 20)]]></expected-error> <source-location>false</source-location> </compilation-unit> </test-case>