NobiGo commented on code in PR #3947:
URL: https://github.com/apache/calcite/pull/3947#discussion_r1868876707
##########
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java:
##########
@@ -866,6 +868,8 @@ void populate1() {
defineMethod(TRUNC_BIG_QUERY, BuiltInMethod.STRUNCATE.method,
NullPolicy.STRICT);
defineMethod(TRUNCATE, BuiltInMethod.STRUNCATE.method,
NullPolicy.STRICT);
defineMethod(LOG1P, BuiltInMethod.LOG1P.method, NullPolicy.STRICT);
+ defineMethod(TYPEOF, BuiltInMethod.TYPEOF.method, NullPolicy.STRICT);
Review Comment:
`TYPEOF` is a new function in CALCITE. Can we use a split Jira issue to
support it?
##########
site/_docs/reference.md:
##########
@@ -1239,14 +1240,66 @@ Note:
| MAP | Collection of keys mapped to values | Example: map < int,
varchar >
| MULTISET | Unordered collection that may contain duplicates | Example: int
multiset
| ARRAY | Ordered, contiguous collection that may contain duplicates |
Example: varchar(10) array
-| CURSOR | Cursor over the result of executing a query |
Review Comment:
Do we need to remove this `|`? ANY and UNKNOWN also end with `|`;
##########
core/src/main/java/org/apache/calcite/runtime/rtti/RuntimeTypeInformation.java:
##########
@@ -0,0 +1,243 @@
+/*
+ * 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.calcite.runtime.rtti;
+
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.Primitive;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeField;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.AbstractMap;
+
+import static java.util.Objects.requireNonNull;
+
+/**
+ * The type of a SQL expression at runtime.
+ * Normally SQL is a statically-typed language, and there is no need for
+ * runtime-type information. However, the VARIANT data type is actually
Review Comment:
There is an extra space before `However`.
##########
core/src/test/java/org/apache/calcite/test/SqlValidatorTest.java:
##########
@@ -1347,6 +1347,45 @@ void testLikeAndSimilarFails() {
.columnType("TIMESTAMP_TZ(3) NOT NULL");
}
+ @Test void testCastVariant() {
+ expr("cast(NULL as variant)")
+ .columnType("VARIANT");
+ expr("cast(1 as variant)")
+ .columnType("VARIANT NOT NULL");
+ expr("cast('abc' as variant)")
+ .columnType("VARIANT NOT NULL");
+ expr("cast(TIMESTAMP '2024-09-01 00:00:00' as variant)")
+ .columnType("VARIANT NOT NULL");
+ expr("cast(ARRAY[1,2,3] AS VARIANT)")
Review Comment:
If we convert `cast(ARRAY[1,2,3, null] AS VARIANT`, What's the columnType?
##########
core/src/main/java/org/apache/calcite/runtime/rtti/BasicSqlTypeRtti.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * 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.calcite.runtime.rtti;
+
+import org.checkerframework.checker.nullness.qual.Nullable;
+
+import java.util.Objects;
+
+/** Runtime type information about a base (primitive) SQL type. */
+public class BasicSqlTypeRtti extends RuntimeTypeInformation {
+ public BasicSqlTypeRtti(RuntimeSqlTypeName typeName) {
+ super(typeName);
+ assert typeName.isScalar() : "Base SQL type must be a scalar type " +
typeName;
+ }
+
+ @Override public boolean equals(@Nullable Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ BasicSqlTypeRtti that = (BasicSqlTypeRtti) o;
+ return typeName == that.typeName;
+ }
+
+ @Override public int hashCode() {
+ return Objects.hashCode(typeName);
+ }
+
+ @Override public String getTypeString() {
+ switch (this.typeName) {
Review Comment:
Can we merge some types? Most of the names of the types here have not
changed.
--
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]