Skip to content

Commit ae5dbb1

Browse files
committed
Allow same SqlTypeName but with different nullability to be merged
Signed-off-by: Kai Huang <[email protected]>
1 parent 31931cf commit ae5dbb1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

core/src/main/java/org/opensearch/sql/calcite/SchemaUnifier.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private static List<SchemaField> buildUnifiedSchema(List<RelNode> nodes) {
7878
// New field - add to schema
7979
schema.add(new SchemaField(fieldName, fieldType));
8080
seenFields.put(fieldName, fieldType);
81-
} else if (!existingType.equals(fieldType)) {
81+
} else if (!areTypesCompatible(existingType, fieldType)) {
8282
// Same field name but different type - throw exception
8383
throw new IllegalArgumentException(
8484
String.format(
@@ -92,6 +92,10 @@ private static List<SchemaField> buildUnifiedSchema(List<RelNode> nodes) {
9292
return schema;
9393
}
9494

95+
private static boolean areTypesCompatible(RelDataType type1, RelDataType type2) {
96+
return type1.getSqlTypeName() != null && type1.getSqlTypeName().equals(type2.getSqlTypeName());
97+
}
98+
9599
/**
96100
* Builds a projection for a node to align with the unified schema. For each field in the unified
97101
* schema: - If the node has a matching field with the same type, use it - Otherwise, project NULL
@@ -113,8 +117,8 @@ private static List<RexNode> buildProjectionForNode(
113117
RelDataType expectedType = schemaField.getType();
114118
RelDataTypeField nodeField = nodeFieldMap.get(fieldName);
115119

116-
if (nodeField != null && nodeField.getType().equals(expectedType)) {
117-
// Field exists with matching type - use it
120+
if (nodeField != null && areTypesCompatible(nodeField.getType(), expectedType)) {
121+
// Field exists with compatible type - use it
118122
projection.add(context.rexBuilder.makeInputRef(node, nodeField.getIndex()));
119123
} else {
120124
// Field missing or type mismatch - project NULL

0 commit comments

Comments
 (0)