LiShuMing commented on a change in pull request #1694: [CALCITE-2935] Add support BOOL_AND/BOOL_OR Aggregate Function URL: https://github.com/apache/calcite/pull/1694#discussion_r362142155
########## File path: core/src/main/java/org/apache/calcite/sql/fun/SqlBoolAggFunction.java ########## @@ -0,0 +1,50 @@ +/* + * 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.fun; + +import org.apache.calcite.sql.SqlAggFunction; +import org.apache.calcite.sql.SqlFunctionCategory; +import org.apache.calcite.sql.SqlKind; +import org.apache.calcite.sql.type.OperandTypes; +import org.apache.calcite.sql.type.ReturnTypes; +import org.apache.calcite.util.Optionality; + +import com.google.common.base.Preconditions; + +/** + * Definition of the <code>BOOL_AND</code> and <code>BOOL_OR</code> aggregate functions. + */ +public class SqlBoolAggFunction extends SqlAggFunction { + + //~ Constructors ----------------------------------------------------------- + + /** Creates a SqlBoolAggFunction. */ + public SqlBoolAggFunction(SqlKind kind) { + super(kind.name(), + null, + kind, + ReturnTypes.ARG0_NULLABLE_IF_EMPTY, + null, + OperandTypes.BOOLEAN, + SqlFunctionCategory.SYSTEM, + false, + false, + Optionality.FORBIDDEN); + Preconditions.checkArgument(kind == SqlKind.BOOL_AND + || kind == SqlKind.BOOL_OR); Review comment: I've checked again. I think it's still better to keep this class/func just like `SqlMinMaxAggFunction`/`SqlAnyValueAggFunction` for this patch. In `AggregateUnionTransposeRule` or `Match` class, it's easier to use the specific `SqlAggFunction`, otherwise need change some origin codes. In `AggregateUnionTransposeRule`, it use `Map<Class<? extends SqlAggFunction>, Boolean>` to define the specific SqlAggFunction type which may be replaced by a `SqlKind` sets later. However I think this maybe optimized by followed patches later? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
