rubenada commented on a change in pull request #2295:
URL: https://github.com/apache/calcite/pull/2295#discussion_r540793659
##########
File path: core/src/test/java/org/apache/calcite/rex/RexBuilderTest.java
##########
@@ -735,4 +740,46 @@ private void checkBigDecimalLiteral(RexBuilder builder,
String val) {
literal.getValueAs(BigDecimal.class).toString(), is(val));
}
+ @Test void testValidateRexFieldAccess() {
+ final RelDataTypeFactory typeFactory =
+ new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
+ final RexBuilder builder = new RexBuilder(typeFactory);
+
+ RelDataType intType = typeFactory.createSqlType(SqlTypeName.INTEGER);
+ RelDataType longType = typeFactory.createSqlType(SqlTypeName.BIGINT);
+
+ RelDataType structType = typeFactory.createStructType(
+ Arrays.asList(intType, longType), Arrays.asList("x", "y"));
+ RexInputRef inputRef = builder.makeInputRef(structType, 0);
+
+ // construct RexFieldAccess fails because of negative index
+ IllegalArgumentException e1 = assertThrows(IllegalArgumentException.class,
() -> {
+ RelDataTypeField field = new RelDataTypeFieldImpl("z", -1, intType);
+ new RexFieldAccess(inputRef, field);
+ });
+ assertThat(e1.getMessage(),
+ is("Field #-1: z INTEGER does not exist for expression $0"));
+
Review comment:
Just to complete: could we have a test that fails because we use index
== fieldList.size() (I guess 2 in this specific case) ?
----------------------------------------------------------------
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]