mihaibudiu commented on code in PR #4127:
URL: https://github.com/apache/calcite/pull/4127#discussion_r1908077623
##########
core/src/test/java/org/apache/calcite/test/TableInRootSchemaTest.java:
##########
@@ -73,4 +87,63 @@ class TableInRootSchemaTest {
connection.close();
}
+ /**
+ * Helper class for the test for [CALCITE-6764] below.
+ */
+ private static class RowTable extends AbstractQueryableTable {
+ protected RowTable() {
+ super(Object[].class);
+ }
+
+ @Override public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+ final PairList<String, RelDataType> columnDesc =
PairList.withCapacity(1);
+ // Schema contains a column whose type is MAP<VARCHAR, ROW(VARCHAR)>, but
+ // the ROW type can be nullable.
+ final RelDataType colType =
+
typeFactory.createMapType(typeFactory.createSqlType(SqlTypeName.VARCHAR),
+ new RelRecordType(
+ StructKind.PEEK_FIELDS,
+ ImmutableList.of(
+ new RelDataTypeFieldImpl("K", 0,
+ typeFactory.createSqlType(SqlTypeName.VARCHAR))),
true));
+ columnDesc.add("P", colType);
+ return typeFactory.createStructType(columnDesc);
+ }
+
+ @Override public <T> Queryable<T> asQueryable(
+ QueryProvider queryProvider, SchemaPlus schema, String tableName) {
+ return new AbstractTableQueryable<T>(queryProvider, schema, this,
+ tableName) {
+ @Override public Enumerator<T> enumerator() {
+ return new Enumerator<T>() {
+ @Override public T current() {
+ return null;
+ }
+
+ @Override public boolean moveNext() {
+ // Table is empty
+ return false;
+ }
+
+ @Override public void reset() {}
+
+ @Override public void close() {}
+ };
+ }
+ };
+ }
+ }
+
+ /** Test case for <a
href="https://issues.apache.org/jira/browse/CALCITE-6764">[CALCITE-6764]
+ * Field access from a nullable ROW should be nullable</a>. */
+ @Test void testNullableValue() throws Exception {
+ Connection connection = DriverManager.getConnection("jdbc:calcite:");
+ CalciteConnection calciteConnection =
connection.unwrap(CalciteConnection.class);
+ calciteConnection.getRootSchema().add("T", new RowTable());
+ Statement statement = calciteConnection.createStatement();
+ ResultSet resultSet = statement.executeQuery("SELECT P['a'].K FROM T");
Review Comment:
There is no nullability information as far as I know.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]