Source:
<code>@Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) { final RelDataTypeFactory typeFactory = opBinding.getTypeFactory(); final RelDataType operandType = opBinding.getOperandType(0); switch (operandType.getSqlTypeName()) { case ARRAY: return typeFactory.createTypeWithNullability( operandType.getComponentType(), true); case MAP: return typeFactory.createTypeWithNullability(operandType.getValueType(), true); case ROW: RelDataType fieldType = null; RelDataType indexType = opBinding.getOperandType(1); if (SqlTypeFamily.STRING.contains(indexType)) { String fieldName = opBinding.getOperandLiteralValue(1, String.class); RelDataTypeField field = operandType.getField(fieldName, false, false); if (field == null) { throw new AssertionError("Cannot infer type of field '" + fieldName + "' within ROW type: " + operandType); } else { fieldType = field.getType(); } } else if (SqlTypeFamily.INTEGER.contains(indexType)) { <START> Integer index = opBinding.getOperandLiteralValue(1, Integer.class); <END> if (index == null || index < 1 || index > operandType.getFieldCount()) { throw new AssertionError("Cannot infer type of field at position " + index + " within ROW type: " + operandType); } else { fieldType = operandType.getFieldList().get(index - 1).getType(); } } else { throw new AssertionError("Unsupported field identifier type: '" + indexType + "'"); } if (fieldType != null && operandType.isNullable()) { fieldType = typeFactory.createTypeWithNullability(fieldType, true); } return fieldType; case ANY: case DYNAMIC_STAR: return typeFactory.createTypeWithNullability( typeFactory.createSqlType(SqlTypeName.ANY), true); default: throw new AssertionError(); } }</code><technical_language>SqlTypeUtil decide type category</technical_language>

Target:
@Override public RelDataType inferReturnType(SqlOperatorBinding opBinding) { final RelDataTypeFactory typeFactory = opBinding.getTypeFactory(); final RelDataType operandType = opBinding.getOperandType(0); switch (operandType.getSqlTypeName()) { case ARRAY: return typeFactory.createTypeWithNullability( operandType.getComponentType(), true); case MAP: return typeFactory.createTypeWithNullability(operandType.getValueType(), true); case ROW: RelDataType fieldType; RelDataType indexType = opBinding.getOperandType(1); if (SqlTypeUtil.isString(indexType)) { String fieldName = opBinding.getOperandLiteralValue(1, String.class); RelDataTypeField field = operandType.getField(fieldName, false, false); if (field == null) { throw new AssertionError("Cannot infer type of field '" + fieldName + "' within ROW type: " + operandType); } else { fieldType = field.getType(); } } else if (SqlTypeUtil.isIntType(indexType)) { Integer index = opBinding.getOperandLiteralValue(1, Integer.class); if (index == null || index < 1 || index > operandType.getFieldCount()) { throw new AssertionError("Cannot infer type of field at position " + index + " within ROW type: " + operandType); } else { fieldType = operandType.getFieldList().get(index - 1).getType(); } } else { throw new AssertionError("Unsupported field identifier type: '" + indexType + "'"); } if (fieldType != null && operandType.isNullable()) { fieldType = typeFactory.createTypeWithNullability(fieldType, true); } return fieldType; case ANY: case DYNAMIC_STAR: return typeFactory.createTypeWithNullability( typeFactory.createSqlType(SqlTypeName.ANY), true); default: throw new AssertionError(); } }