|
|
|
@ -19,7 +19,6 @@
|
|
|
|
|
package org.apache.iceberg.orc;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.Optional;
|
|
|
|
@ -264,11 +263,11 @@ public final class ORCSchemaUtil {
|
|
|
|
|
public static TypeDescription buildOrcProjection(
|
|
|
|
|
Schema schema, TypeDescription originalOrcSchema) {
|
|
|
|
|
final Map<Integer, OrcField> icebergToOrc = icebergToOrcMapping("root", originalOrcSchema);
|
|
|
|
|
return buildOrcProjection(Integer.MIN_VALUE, schema.asStruct(), true, icebergToOrc);
|
|
|
|
|
return buildOrcProjection(schema, Integer.MIN_VALUE, schema.asStruct(), true, icebergToOrc);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static TypeDescription buildOrcProjection(
|
|
|
|
|
Integer fieldId, Type type, boolean isRequired, Map<Integer, OrcField> mapping) {
|
|
|
|
|
Schema root, Integer fieldId, Type type, boolean isRequired, Map<Integer, OrcField> mapping) {
|
|
|
|
|
final TypeDescription orcType;
|
|
|
|
|
|
|
|
|
|
switch (type.typeId()) {
|
|
|
|
@ -284,6 +283,7 @@ public final class ORCSchemaUtil {
|
|
|
|
|
.orElseGet(() -> nestedField.name() + "_r" + nestedField.fieldId());
|
|
|
|
|
TypeDescription childType =
|
|
|
|
|
buildOrcProjection(
|
|
|
|
|
root,
|
|
|
|
|
nestedField.fieldId(),
|
|
|
|
|
nestedField.type(),
|
|
|
|
|
isRequired && nestedField.isRequired(),
|
|
|
|
@ -295,6 +295,7 @@ public final class ORCSchemaUtil {
|
|
|
|
|
Types.ListType list = (Types.ListType) type;
|
|
|
|
|
TypeDescription elementType =
|
|
|
|
|
buildOrcProjection(
|
|
|
|
|
root,
|
|
|
|
|
list.elementId(),
|
|
|
|
|
list.elementType(),
|
|
|
|
|
isRequired && list.isElementRequired(),
|
|
|
|
@ -304,10 +305,10 @@ public final class ORCSchemaUtil {
|
|
|
|
|
case MAP:
|
|
|
|
|
Types.MapType map = (Types.MapType) type;
|
|
|
|
|
TypeDescription keyType =
|
|
|
|
|
buildOrcProjection(map.keyId(), map.keyType(), isRequired, mapping);
|
|
|
|
|
buildOrcProjection(root, map.keyId(), map.keyType(), isRequired, mapping);
|
|
|
|
|
TypeDescription valueType =
|
|
|
|
|
buildOrcProjection(
|
|
|
|
|
map.valueId(), map.valueType(), isRequired && map.isValueRequired(), mapping);
|
|
|
|
|
root, map.valueId(), map.valueType(), isRequired && map.isValueRequired(), mapping);
|
|
|
|
|
orcType = TypeDescription.createMap(keyType, valueType);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
@ -326,13 +327,20 @@ public final class ORCSchemaUtil {
|
|
|
|
|
orcType = originalType.clone();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Types.NestedField field = root.findField(fieldId);
|
|
|
|
|
if (isRequired) {
|
|
|
|
|
throw new IllegalArgumentException(
|
|
|
|
|
Preconditions.checkArgument(
|
|
|
|
|
field.initialDefault() != null,
|
|
|
|
|
"Missing required field: %s (%s)",
|
|
|
|
|
root.findColumnName(fieldId),
|
|
|
|
|
type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (field.initialDefault() != null) {
|
|
|
|
|
throw new UnsupportedOperationException(
|
|
|
|
|
String.format(
|
|
|
|
|
Locale.ROOT,
|
|
|
|
|
"Field %d of type %s is required and was not found.",
|
|
|
|
|
fieldId,
|
|
|
|
|
type));
|
|
|
|
|
"ORC cannot read default value for field %s (%s): %s",
|
|
|
|
|
root.findColumnName(fieldId), type, field.initialDefault()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
orcType = convert(fieldId, type, false);
|
|
|
|
|