snuyanzin commented on code in PR #21934: URL: https://github.com/apache/flink/pull/21934#discussion_r1149294805
########## flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/functions/sql/SqlRowConstructor.java: ########## @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.table.planner.functions.sql; + +import org.apache.calcite.rel.type.RelDataType; +import org.apache.calcite.sql.SqlOperator; +import org.apache.calcite.sql.SqlOperatorBinding; +import org.apache.calcite.sql.SqlUtil; +import org.apache.calcite.sql.fun.SqlRowOperator; +import org.apache.calcite.util.Pair; + +import java.util.AbstractList; +import java.util.Map; + +/** {@link SqlOperator} for <code>ROW</code>, which behaves same way as in Calcite 1.29.0. */ +public class SqlRowConstructor extends SqlRowOperator { + public SqlRowConstructor() { + super("ROW"); + } + + @Override + public RelDataType inferReturnType(SqlOperatorBinding opBinding) { + // The type of a ROW(e1,e2) expression is a record with the types + // {e1type,e2type}. According to the standard, field names are + // implementation-defined. + return opBinding + .getTypeFactory() + .createStructType( + new AbstractList<Map.Entry<String, RelDataType>>() { + @Override + public Map.Entry<String, RelDataType> get(int index) { + return Pair.of( + SqlUtil.deriveAliasFromOrdinal(index), + opBinding.getOperandType(index)); + } + + @Override + public int size() { + return opBinding.getOperandCount(); + } + }); + } +} Review Comment: short answer yes. A bit more words explaining this it looks like in SQL standard there are statements about about `ROW` like ``` The value of R IS NULL is Case: 1) If the value of every field of V is the null value, then True. 2) Otherwise, False. ii) The value of R IS NOT NULL is Case: 1) If the value of no field of V is the null value, then True. 2) Otherwise, False. ``` There is nothing about how to treat `ROW(NULL, NULL)` however to satisfy this Calcite treats it as `NULL`. Thus with Calcite 1.30.0+ ```sql SELECT ROW(CAST(NULL AS INT), CAST(NULL AS INT)) IS NOT NULL; --returns FALSE SELECT ROW(CAST(NULL AS INT), CAST(NULL AS INT)) IS NULL; -- returns true ``` With Flink and Calcite before 1.30.0 ```sql SELECT ROW(CAST(NULL AS INT), CAST(NULL AS INT)) IS NOT NULL; --returns TRUE SELECT ROW(CAST(NULL AS INT), CAST(NULL AS INT)) IS NULL; -- returns FALSE ``` -- 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]
