From 1532dbec1dda685d50e7a95894a70b7796f182c3 Mon Sep 17 00:00:00 2001 From: Charles Givre Date: Mon, 28 Aug 2023 23:26:34 -0400 Subject: [PATCH] Fixed imports --- .../exec/store/xml/xsd/DrillXSDSchemaUtils.java | 4 ++-- .../exec/store/xml/xsd/DrillXSDSchemaVisitor.java | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/contrib/format-xml/src/main/java/org/apache/drill/exec/store/xml/xsd/DrillXSDSchemaUtils.java b/contrib/format-xml/src/main/java/org/apache/drill/exec/store/xml/xsd/DrillXSDSchemaUtils.java index 45379bf8e98..194f640a9a1 100644 --- a/contrib/format-xml/src/main/java/org/apache/drill/exec/store/xml/xsd/DrillXSDSchemaUtils.java +++ b/contrib/format-xml/src/main/java/org/apache/drill/exec/store/xml/xsd/DrillXSDSchemaUtils.java @@ -21,8 +21,8 @@ import org.apache.drill.common.types.TypeProtos.MinorType; import org.apache.drill.exec.record.metadata.SchemaBuilder; import org.apache.drill.exec.record.metadata.TupleMetadata; -import org.apache.drill.shaded.guava.com.google.common.annotations.VisibleForTesting; -import org.apache.drill.shaded.guava.com.google.common.collect.ImmutableMap; +import com.google.common.annotations.VisibleForTesting; +import com.google.common.collect.ImmutableMap; import org.apache.ws.commons.schema.XmlSchema; import org.apache.ws.commons.schema.XmlSchemaCollection; import org.apache.ws.commons.schema.XmlSchemaElement; diff --git a/contrib/format-xml/src/main/java/org/apache/drill/exec/store/xml/xsd/DrillXSDSchemaVisitor.java b/contrib/format-xml/src/main/java/org/apache/drill/exec/store/xml/xsd/DrillXSDSchemaVisitor.java index d1248b93177..83fcf270e5c 100644 --- a/contrib/format-xml/src/main/java/org/apache/drill/exec/store/xml/xsd/DrillXSDSchemaVisitor.java +++ b/contrib/format-xml/src/main/java/org/apache/drill/exec/store/xml/xsd/DrillXSDSchemaVisitor.java @@ -18,6 +18,8 @@ package org.apache.drill.exec.store.xml.xsd; +import org.apache.commons.lang3.StringUtils; +import org.apache.drill.common.exceptions.UserException; import org.apache.drill.common.types.TypeProtos.DataMode; import org.apache.drill.common.types.TypeProtos.MinorType; import org.apache.drill.exec.record.metadata.MapBuilder; @@ -57,7 +59,7 @@ public class DrillXSDSchemaVisitor implements XmlSchemaVisitor { * attributes map for all the attributes when the walker tells us we're * at the end of all the element decl's attributes. * - * Uses LinkedHashMap to ensure deterministic behavior which facilitates testability. + * Uses {@link LinkedHashMap} to ensure deterministic behavior which facilitates testability. * In this situation it probably does not matter, but it's a good practice. */ private HashMap> attributeInfoTable = @@ -100,11 +102,15 @@ public void onEnterElement(XmlSchemaElement xmlSchemaElement, XmlSchemaTypeInfo // // Note that the child name in constant ATTRIBUTE_MAP_NAME is reserved and cannot be used // by any child element. - // - // TODO: How to issue this error, and refuse to generate the Drill schema? // TODO: There are many other things we want to refuse. E.g., if there are mixed content elements. // - assert !fieldName.equals(ATTRIBUTE_MAP_NAME); + if (StringUtils.equals(ATTRIBUTE_MAP_NAME, fieldName)) { + throw UserException.dataReadError() + .message("XML schema contains a field named " + ATTRIBUTE_MAP_NAME + " which is a " + + "reserved word for XML schemata.") + .build(logger); + } + if (xmlSchemaTypeInfo.getType().name().equalsIgnoreCase("COMPLEX")) { // Start a map here. logger.debug("Starting map {}.", xmlSchemaElement.getName()); @@ -148,7 +154,6 @@ public void onEnterElement(XmlSchemaElement xmlSchemaElement, XmlSchemaTypeInfo if (isRepeated) { currentMapBuilder.add(fieldName, dataType, DataMode.REPEATED); logger.debug("Adding array {}.", xmlSchemaElement.getName()); - } else { currentMapBuilder.addNullable(fieldName, dataType); logger.debug("Adding field {}.", xmlSchemaElement.getName());