asolimando commented on a change in pull request #2230:
URL: https://github.com/apache/calcite/pull/2230#discussion_r512190295
##########
File path: core/src/main/java/org/apache/calcite/sql/fun/SqlItemOperator.java
##########
@@ -129,18 +129,34 @@ private SqlSingleOperandTypeChecker
getChecker(SqlCallBinding callBinding) {
return typeFactory.createTypeWithNullability(operandType.getValueType(),
true);
case ROW:
- 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 {
- RelDataType fieldType = field.getType();
- if (operandType.isNullable()) {
- fieldType = typeFactory.createTypeWithNullability(fieldType, true);
+ 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)) {
+ 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(); //
1 indexed
}
- return fieldType;
+ } else {
+ throw new AssertionError("Unsupported field identifier type: '"
+ + indexType + "'");
+ }
+ if (fieldType != null && operandType.isNullable()) {
+ fieldType = typeFactory.createTypeWithNullability(fieldType, true);
Review comment:
I have double checked `createTypeWithNullability` in all the
implementations of `RelDataTypeFactory` and it does not seem so. For what's
worth, that bit is unchanged from the code my PR is based off.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]