@@ -129,14 +129,18 @@ protected TableWithNullableRowInMap() {
129
129
// Schema contains a column whose type is MAP<VARCHAR, ROW(VARCHAR)>, but
130
130
// the ROW type can be nullable. This can conceivably be created by a
131
131
// declaration such as
132
- // CREATE TABLE T(p MAP<VARCHAR, ROW(k VARCHAR)>);
132
+ // CREATE TABLE T(P MAP<VARCHAR, ROW(K VARCHAR NON NULL, S VARCHAR NULL )>);
133
133
final RelDataType colType =
134
134
typeFactory .createMapType (typeFactory .createSqlType (SqlTypeName .VARCHAR ),
135
135
new RelRecordType (
136
136
StructKind .PEEK_FIELDS ,
137
137
ImmutableList .of (
138
138
new RelDataTypeFieldImpl ("K" , 0 ,
139
- typeFactory .createSqlType (SqlTypeName .VARCHAR ))), true ));
139
+ typeFactory .createSqlType (SqlTypeName .VARCHAR )),
140
+ new RelDataTypeFieldImpl ("S" , 1 ,
141
+ typeFactory .createTypeWithNullability (
142
+ typeFactory .createSqlType (SqlTypeName .VARCHAR ), true ))),
143
+ true ));
140
144
columnDesc .add ("P" , colType );
141
145
return typeFactory .createStructType (columnDesc );
142
146
}
@@ -151,22 +155,37 @@ protected TableWithNullableRowToplevel() {
151
155
@ Override public RelDataType getRowType (RelDataTypeFactory typeFactory ) {
152
156
final PairList <String , RelDataType > columnDesc = PairList .withCapacity (1 );
153
157
// This table can conceivably be created by a declaration such as
154
- // CREATE TABLE T(p ROW(k VARCHAR) NULL);
155
- final RelDataType colType =
158
+ // CREATE TABLE T(P ROW(K VARCHAR NOT NULL) NULL,
159
+ // Q ROW(S ROW(L VARCHAR NOT NULL, M VARCHAR NULL) NULL) NULL);
160
+ final RelDataType pColType =
156
161
new RelRecordType (
157
162
StructKind .PEEK_FIELDS , ImmutableList .of (
158
163
new RelDataTypeFieldImpl (
159
164
"K" , 0 , typeFactory .createSqlType (SqlTypeName .VARCHAR ))),
160
165
true );
161
- columnDesc .add ("P" , colType );
166
+ final RelDataType sType =
167
+ new RelRecordType (
168
+ StructKind .PEEK_FIELDS , ImmutableList .of (
169
+ new RelDataTypeFieldImpl (
170
+ "L" , 0 , typeFactory .createSqlType (SqlTypeName .VARCHAR )),
171
+ new RelDataTypeFieldImpl (
172
+ "M" , 1 , typeFactory .createSqlType (SqlTypeName .VARCHAR ))),
173
+ false );
174
+ final RelDataType qColType =
175
+ new RelRecordType (
176
+ StructKind .PEEK_FIELDS , ImmutableList .of (
177
+ new RelDataTypeFieldImpl ("S" , 0 , sType )),
178
+ true );
179
+ columnDesc .add ("P" , pColType );
180
+ columnDesc .add ("Q" , qColType );
162
181
return typeFactory .createStructType (columnDesc );
163
182
}
164
183
}
165
184
166
185
/** Test case for
167
186
* <a href="https://issues.apache.org/jira/browse/CALCITE-6764">[CALCITE-6764]
168
187
* Field access from a nullable ROW should be nullable</a>. */
169
- @ Test void testNullableValue () throws Exception {
188
+ @ Test void testNullableRowInMap () throws Exception {
170
189
Connection connection = DriverManager .getConnection ("jdbc:calcite:" );
171
190
CalciteConnection calciteConnection = connection .unwrap (CalciteConnection .class );
172
191
calciteConnection .getRootSchema ().add ("T" , new TableWithNullableRowInMap ());
@@ -175,7 +194,7 @@ protected TableWithNullableRowToplevel() {
175
194
// java.lang.RuntimeException: java.lang.AssertionError:
176
195
// Conversion to relational algebra failed to preserve datatypes:
177
196
// validated type:
178
- ResultSet resultSet = statement .executeQuery ("SELECT P['a'].K FROM T" );
197
+ ResultSet resultSet = statement .executeQuery ("SELECT P['a'].K, P['a'].S FROM T" );
179
198
resultSet .close ();
180
199
statement .close ();
181
200
connection .close ();
@@ -184,7 +203,7 @@ protected TableWithNullableRowToplevel() {
184
203
/** Test case for
185
204
* <a href="https://issues.apache.org/jira/browse/CALCITE-6764">[CALCITE-6764]
186
205
* Field access from a nullable ROW should be nullable</a>. */
187
- @ Test void testNullableValue2 () throws Exception {
206
+ @ Test void testNullableRowTopLevel () throws Exception {
188
207
Connection connection = DriverManager .getConnection ("jdbc:calcite:" );
189
208
CalciteConnection calciteConnection = connection .unwrap (CalciteConnection .class );
190
209
calciteConnection .getRootSchema ().add ("T" , new TableWithNullableRowToplevel ());
@@ -193,7 +212,7 @@ protected TableWithNullableRowToplevel() {
193
212
// java.lang.RuntimeException: java.lang.AssertionError:
194
213
// Conversion to relational algebra failed to preserve datatypes:
195
214
// validated type:
196
- ResultSet resultSet = statement .executeQuery ("SELECT t.p.k FROM T" );
215
+ ResultSet resultSet = statement .executeQuery ("SELECT T.P.K, T.Q.S, T.Q.S.L, T.Q.S.M FROM T" );
197
216
resultSet .close ();
198
217
statement .close ();
199
218
connection .close ();
0 commit comments