>From Ian Maxon <[email protected]>: Ian Maxon has uploaded this change for review. ( https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17296 )
Change subject: [ASTERIXDB-3091][MTD] Make DROP TYPE derive correct names ...................................................................... [ASTERIXDB-3091][MTD] Make DROP TYPE derive correct names - user model changes: no - storage format changes: no - interface changes: no Details: DROP TYPE tries to derive the dependent nested anonymous types to drop by name. However, when we insert these, for missable fields and nested collections, the base type is used rather than the quantified or outer type to create the name. This happens to work most of the time hence this was not noticed for a very long time. This patch just fixes the two cases by using the unquantified type for missable fields of records, and the item type rather than the collection type for collections. Change-Id: I67f3ea5bbd9dd4f5f4b836e765f42ccc1d7b13ca --- A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.001.ddl.sqlpp A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.002.query.sqlpp M asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataNode.java A asterixdb/asterix-app/src/test/resources/runtimets/results/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.001.adm M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.000.ddl.sqlpp 6 files changed, 100 insertions(+), 3 deletions(-) git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/96/17296/1 diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.000.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.000.ddl.sqlpp new file mode 100644 index 0000000..7d98566 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.000.ddl.sqlpp @@ -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. + */ +CREATE TYPE UserType AS { +_oid: uuid, +user_id: string, +email: string, +name: +{ first: string?, last: string? } +, +address: +{ street: string?, city: string?, state: string?, zip: int? } +?, +categories: [ string ], +phone: [ +{ number: string?, kind: string? } +], +joined_date: string, +is_buyer: boolean, +is_seller: boolean +}; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.001.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.001.ddl.sqlpp new file mode 100644 index 0000000..c650b54 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.001.ddl.sqlpp @@ -0,0 +1,19 @@ +/* + * 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 TYPE UserType; \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.002.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.002.query.sqlpp new file mode 100644 index 0000000..05fd3a9 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.002.query.sqlpp @@ -0,0 +1,3 @@ +SELECT d.DatatypeName +FROM Metadata.Datatype d +WHERE starts_with(d.DatatypeName,"UserType"); \ No newline at end of file diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.001.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.001.adm new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/ddl/drop-anonymous-nested-types/drop-anonymous-nested-types.001.adm 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 5ef74bd..2b0771f 100644 --- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml +++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml @@ -4349,6 +4349,11 @@ <expected-error>Parameter invalid_date cannot be set</expected-error> </compilation-unit> </test-case> + <test-case FilePath="ddl"> + <compilation-unit name="drop-anonymous-nested-types"> + <output-dir compare="Text">drop-anonymous-nested-types</output-dir> + </compilation-unit> + </test-case> </test-group> <test-group name="dml"> <test-case FilePath="dml"> diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataNode.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataNode.java index 87f5129..0dfef57 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataNode.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/MetadataNode.java @@ -109,6 +109,7 @@ import org.apache.asterix.om.types.ARecordType; import org.apache.asterix.om.types.ATypeTag; import org.apache.asterix.om.types.AUnionType; +import org.apache.asterix.om.types.AbstractCollectionType; import org.apache.asterix.om.types.AbstractComplexType; import org.apache.asterix.om.types.BuiltinType; import org.apache.asterix.om.types.IAType; @@ -1483,15 +1484,23 @@ ARecordType recType = (ARecordType) parentType.getDatatype(); subTypes = Arrays.asList(recType.getFieldTypes()); } else if (parentType.getDatatype().getTypeTag() == ATypeTag.UNION) { - AUnionType recType = (AUnionType) parentType.getDatatype(); - subTypes = recType.getUnionList(); + AUnionType unionType = (AUnionType) parentType.getDatatype(); + subTypes = unionType.getUnionList(); + } else if (parentType.getDatatype().getTypeTag() == ATypeTag.ARRAY + || parentType.getDatatype().getTypeTag() == ATypeTag.MULTISET) { + AbstractCollectionType collType = (AbstractCollectionType) parentType.getDatatype(); + subTypes = List.of(collType.getItemType()); } List<String> nestedTypes = new ArrayList<>(); if (subTypes != null) { for (IAType subType : subTypes) { if (!(subType instanceof BuiltinType)) { - nestedTypes.add(subType.getTypeName()); + if (subType.getTypeTag() == ATypeTag.UNION) { + nestedTypes.add(((AUnionType) subType).getActualType().getTypeName()); + } else { + nestedTypes.add(subType.getTypeName()); + } } } } -- To view, visit https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/17296 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: I67f3ea5bbd9dd4f5f4b836e765f42ccc1d7b13ca Gerrit-Change-Number: 17296 Gerrit-PatchSet: 1 Gerrit-Owner: Ian Maxon <[email protected]> Gerrit-MessageType: newchange
