in awsglue/gluetypes.py [0:0]
def mergeDataTypes(s1, s2):
if isinstance(s1, UnknownType) or isinstance(s1, NullType):
return s2
elif isinstance(s2, UnknownType) or isinstance(s2, NullType):
return s1
elif isinstance(s1, ChoiceType) or isinstance(s2, ChoiceType):
return _make_choice(s1, s2)
elif type(s1) != type(s2):
return _make_choice(s1, s2)
else:
if isinstance(s1, StructType):
new_fields = []
# Fields that are present in both s1 and s2.
for field in s1:
if s2.hasField(field):
new_fields.append(
Field(field.name,
mergeDataTypes(field.dataType,
s2.getField(field).dataType),
field.properties))
else:
# Fields in s1 that are not in s2.
new_fields.append(Field(field.name, field.dataType,
field.properties))
# Fields in s2 that are not in s1.
new_fields.extend([Field(field.name, field.dataType,
field.properties)
for field in s2 if not s1.hasField(field)])
return StructType(new_fields, s1.properties)
elif isinstance(s1, ArrayType):
return ArrayType(mergeDataTypes(s1.elementType, s2.elementType))
elif isinstance(s1, MapType):
return MapType(mergeDataTypes(s1.valueType, s2.valueType))
elif isinstance(s1, EnumType):
return EnumType(s1.options + s2.options)
else:
return s1