tanclary commented on code in PR #3655:
URL: https://github.com/apache/calcite/pull/3655#discussion_r1471624089


##########
core/src/main/java/org/apache/calcite/sql/type/MapKeyOperandTypeChecker.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+
+import com.google.common.collect.ImmutableList;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getKeyTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type-checking strategy where types must be Map and Map key type.
+ */
+public class MapKeyOperandTypeChecker implements SqlOperandTypeChecker {

Review Comment:
   Do we need an entire new class for this? We should just add a new entry to 
`OperandTypes` if possible. Or at least use a nested class (like 
`PeriodOperandTypeChecker`)



##########
site/_docs/reference.md:
##########
@@ -2794,6 +2794,7 @@ In the following:
 | s | MAP()                                          | Returns an empty map
 | s | MAP(key, value [, key, value]*)                | Returns a map with the 
given *key*/*value* pairs
 | s | MAP_CONCAT(map [, map]*)                       | Concatenates one or 
more maps. If any input argument is `NULL` the function returns `NULL`. Note 
that calcite is using the LAST_WIN strategy
+| s | MAP_CONTAINS_KEY(map, key)                     | Returns true if the 
*map* contains the *key*

Review Comment:
   What does it return if the map does not contain the key? False? Null? Error? 
Maybe `Returns whether map contains key* is better because it has less 
ambiguity.



##########
core/src/main/java/org/apache/calcite/sql/type/MapKeyOperandTypeChecker.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.sql.type;
+
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlCallBinding;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperandCountRange;
+import org.apache.calcite.sql.SqlOperator;
+
+import com.google.common.collect.ImmutableList;
+
+import static 
org.apache.calcite.sql.type.NonNullableAccessors.getKeyTypeOrThrow;
+import static org.apache.calcite.util.Static.RESOURCE;
+
+/**
+ * Parameter type-checking strategy where types must be Map and Map key type.
+ */
+public class MapKeyOperandTypeChecker implements SqlOperandTypeChecker {
+  @Override public boolean checkOperandTypes(
+      SqlCallBinding callBinding,
+      boolean throwOnFailure) {
+    final SqlNode op0 = callBinding.operand(0);
+    if (!OperandTypes.MAP.checkSingleOperandType(
+        callBinding,
+        op0,

Review Comment:
   I don't really think we should have to write all of this out. What is 
specific to MAP and KEY that it needs unique handling? From what I see you're 
just verifying the type of the 1st and 2nd arguments. Let me know if I'm 
missing something.



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -7189,6 +7189,43 @@ void checkRegexpExtract(SqlOperatorFixture f0, 
FunctionAlias functionAlias) {
         "INTEGER ARRAY NOT NULL");
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6223";>[CALCITE-6223]
+   * Add SAFE_NEGATE function (enabled in BigQuery library)</a>.
+   */
+  @Test void testMapContainsKeyFunc() {
+    final SqlOperatorFixture f0 = Fixtures.forOperators(true);

Review Comment:
   I don't think we normally instantiate the test fixture this way. Just use 
`f0 = fixture().setFor(...)` as normal.



##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -7189,6 +7189,43 @@ void checkRegexpExtract(SqlOperatorFixture f0, 
FunctionAlias functionAlias) {
         "INTEGER ARRAY NOT NULL");
   }
 
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-6223";>[CALCITE-6223]
+   * Add SAFE_NEGATE function (enabled in BigQuery library)</a>.
+   */

Review Comment:
   end the comment on the previous line



-- 
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]

Reply via email to